Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Examples  

Person.hpp

00001 #if   !defined(__PERSON_HPP)
00002 #define __PERSON_HPP
00003 
00004 /*
00005   CoreLinux++ 
00006   Copyright (C) 1999 CoreLinux Consortium
00007   
00008    The CoreLinux++ Library is free software; you can redistribute it and/or
00009    modify it under the terms of the GNU Library General Public License as
00010    published by the Free Software Foundation; either version 2 of the
00011    License, or (at your option) any later version.
00012 
00013    The CoreLinux++ Library Library is distributed in the hope that it will 
00014    be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016    Library General Public License for more details.
00017 
00018    You should have received a copy of the GNU Library General Public
00019    License along with the GNU C Library; see the file COPYING.LIB.  If not,
00020    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00021    Boston, MA 02111-1307, USA.  
00022 */   
00023 
00024 #if   !defined(__COMMON_HPP)                     
00025 #include <Common.hpp>          
00026 #endif
00027 
00028 
00029 //
00030 // This gives our Person the types
00031 // that is more reasonable for the
00032 // domain.
00033 //
00034 
00035 DECLARE_TYPE( CORELINUX(StringUtf8), Name );
00036 DECLARE_TYPE( CORELINUX(Long), Age );
00037 
00038 //
00039 // Person is a concrete non-polymorphice class that 
00040 // examples some CoreLinux++ style and constraints. In this domain
00041 // it is enforced that no Person can be the same as another Person.
00042 // This is a soft approach as in a real world application uniqueness 
00043 // in a domain would have to consider ALL persons in a domain.
00044 //
00045 
00046 DECLARE_CLASS( Person );
00047 
00048 class Person
00049 {
00050 public:
00051 
00052    //
00053    // Public Constructors and destructors
00054    //
00055 
00056                         //
00057                         // Default constructor forces taking
00058                         // a name because what is a person 
00059                         // without one. The other constructors
00060                         // not allowed are in the protected area
00061                         // with assertions!
00062                         //
00063 
00064                         Person( NameCref, Age );
00065 
00066    virtual              ~Person( void );
00067 
00068    //
00069    // Operator overloads.
00070    //
00071 
00072             // Operator equality down to the name 
00073 
00074             bool  operator==( PersonCref ) const;
00075 
00076 
00077    //
00078    // Accessors
00079    //
00080 
00081             // Explicit name fetch
00082 
00083             NameCref    getName( void ) const;
00084 
00085             // Coercion name fetch
00086 
00087                         operator NameCref( void ) const;
00088 
00089             // Explicit age fetch
00090 
00091             AgeCref     getAge( void ) const;
00092 
00093             // Coercion age fetch
00094 
00095                         operator AgeCref( void ) const;
00096 
00097    //
00098    // Mutators
00099    //
00100             // Prefered method
00101 
00102             void  setAge( Age );
00103 
00104 
00105 protected:
00106 
00107                         //
00108                         // As stated, this can't be
00109                         // because a Person has a Name
00110                         //
00111 
00112                         Person( void );
00113 
00114                         //
00115                         // This would violate the same
00116                         // person existing twice in the
00117                         // domain.
00118                         //
00119 
00120                         Person( PersonCref );
00121 
00122             // ditto
00123 
00124             PersonRef   operator=( PersonCref );
00125 
00126 private:
00127 
00128          //
00129          // Use the language to enforce that the name
00130          // is only set once.
00131          //
00132 
00133          NameCref    theName;
00134 
00135          //
00136          // Whereas the age can change but is constrained
00137          // to >= 0 and and <= corelinux::Limits::LONGMAX
00138          //
00139 
00140          Age         theAge;
00141 
00142 
00143 };
00144 
00145 #endif // if !defined(__PERSON_HPP)
00146 
00147 /*
00148    Common rcs information do not modify
00149    $Author: frankc $
00150    $Revision: 1.6 $
00151    $Date: 2000/02/10 14:32:20 $
00152    $Locker:  $
00153 */
00154 

This is the CoreLinux++ reference manual
Provided by The CoreLinux Consortium