attribute.h

Go to the documentation of this file.
00001 
00002 
00003 #ifndef ATTRIBUTE_DEFINED
00004 #define ATTRIBUTE_DEFINED
00005 
00006 namespace class_def {
00007 
00010   class attribute {
00011   protected:
00012     std::string _type;
00013     int         _reference;
00014     std::string _name;
00015     std::string _null_value; // functional or derived, if not defined on init
00016     int         _max_length; // 0 if not defined
00017     std::vector<std::string> _comments;
00018     
00019     static int _erno;
00020     static const char *_error_msg;
00021     static int _allow_custom_classes;
00022     static int _copy_constructor;
00023     static int _check_attributes;
00024     static const std::vector<std::string> _empty_string_vector;
00025   
00026   public:
00027     enum { 
00028       value=0, 
00029       containment=1, 
00030       reference=2, 
00031       shallow_pointer=3, 
00032       deep_pointer=4};
00033     
00034     static void put_allow_custom_classes( int newval);
00035     static void put_copy_constructor( int newval);
00036     static void put_check_attributes( int newval);
00037     static int  get_allow_custom_classes();
00038     static int  get_copy_constructor();
00039     static int  get_check_attributes();
00040 
00041     int is_custom_class() const;
00042     
00043     static  const char *_get_class_name() { return "class_def::attribute";}
00044     virtual const char *get_class_name() const = 0;
00045     
00046     void set_null() {
00047       _name = _type = _null_value = "";
00048       _reference = 0;
00049       _max_length = 0;
00050       if (_comments.size()>0) {
00051         _comments.erase( _comments.begin(), _comments.end());
00052       }
00053     }
00054     
00055     static int check_attributes(
00056                                 const std::string& Type,
00057                                 int                Reference,
00058                                 const std::string& Name,
00059                                 const std::string& Null_value,
00060                                 int                Max_length,
00061                                 const std::vector<std::string>& Comments);
00062     
00063     void init_calc_derived_attributes();
00064     
00065     void init(
00066               const std::string& Type,
00067               int                Reference,
00068               const std::string& Name,
00069               const std::string& Null_value,
00070               int                Max_length,
00071               const std::vector<std::string>& Comments)
00072     {
00073       const char *funcname = "attribute::init";
00074       
00075       check_attributes(
00076                        Type,
00077                        Reference,
00078                        Name,
00079                        Null_value,
00080                        Max_length,
00081                        Comments);
00082       
00083       if (_erno) {
00084         throw ( std::invalid_argument( error_message( 
00085                                                          get_class_name(), 
00086                                                          funcname, 
00087                                                          __FILE__,
00088                                                          _error_msg,
00089                                                          __LINE__, 
00090                                                          _erno   ,
00091                                                          lineno  ).what()));
00092       }
00093       
00094       _type = Type; 
00095       _reference = Reference;
00096       _name = Name;
00097       _null_value = Null_value;
00098       _max_length = Max_length;
00099       _comments = Comments;
00100       
00101       init_calc_derived_attributes();
00102     }
00103     
00104     attribute(
00105               const std::string& Type       = "",
00106               int                Reference  = 0 ,
00107               const std::string& Name       = "",
00108               const std::string& Null_value = "",
00109               int                Max_length = 0 ,
00110               std::vector<std::string> Comments = _empty_string_vector)
00111       {
00112         set_null();
00113         init(
00114              Type,
00115              Reference,
00116              Name,
00117              Null_value,
00118              Max_length,
00119              Comments);
00120         init_calc_derived_attributes();
00121       }
00122     
00123     virtual ~attribute() { set_null();}
00124     
00125     // get data functions
00126     attribute *get_this() { return this;}
00127     const std::string& get_type() const { return _type;}
00128     int   get_reference() const { return _reference;}
00129     const std::string& get_name() const { return _name;}
00130     const std::string& get_null_value() const { return _null_value;}
00131     int   get_max_length() const { return _max_length;}
00132     const std::vector<std::string>& get_comments() const { return _comments;}
00133     
00134     std::string input_format_of_name() const;
00135     std::string storage_format_of_name() const;
00136     std::string get_Name() const;
00137     
00138     // put data functions
00139     void put_type( const std::string& Type) {
00140       const char *funcname = "attribute::put_type";
00141       check_attributes(
00142                        Type,
00143                        _reference,
00144                        _name,
00145                        _null_value,
00146                        _max_length,
00147                        _comments);
00148       if (_erno) {
00149         throw ( std::invalid_argument( error_message( 
00150                                  get_class_name(), 
00151                                  funcname, 
00152                                  __FILE__,
00153                                  _error_msg,
00154                                  __LINE__, 
00155                                  _erno   ,
00156                                  lineno  ).what()));
00157       }
00158       _type = Type;
00159     }
00160     
00161     void put_reference( int  Reference) {
00162       const char *funcname = "attribute::put_reference";
00163       check_attributes(
00164                        _type    ,
00165                        Reference,
00166                        _name    ,
00167                        _null_value,
00168                        _max_length,
00169                        _comments);
00170       if (_erno) {
00171         throw ( std::invalid_argument( error_message( 
00172                                  get_class_name()   , 
00173                                  funcname, 
00174                                  __FILE__,
00175                                  _error_msg,
00176                                  __LINE__, 
00177                                  _erno   ,
00178                                  lineno  ).what()));
00179       }
00180       _reference = Reference;
00181     }
00182     
00183     void put_name( const std::string& Name) {
00184       const char *funcname = "attribute::put_name";
00185       check_attributes(
00186                        _type,
00187                        _reference,
00188                        Name,
00189                        _null_value,
00190                        _max_length,
00191                        _comments);
00192       if (_erno) {
00193         throw ( std::invalid_argument( error_message ( 
00194                                    get_class_name()   , 
00195                                    funcname, 
00196                                    __FILE__,
00197                                    _error_msg,
00198                                    __LINE__, 
00199                                    _erno   ,
00200                                    lineno  ).what()));
00201       }
00202       _name = Name;
00203     }
00204     
00205     void put_null_value( const std::string& Null_Value) {
00206       const char *funcname = "attribute::put_null_value";
00207       check_attributes(
00208                        _type     ,
00209                        _reference,
00210                        _name     ,
00211                        Null_Value,
00212                        _max_length,
00213                        _comments);
00214       if (_erno) {
00215         throw ( std::invalid_argument( error_message( 
00216                                   get_class_name()   , 
00217                                   funcname, 
00218                                   __FILE__,
00219                                   _error_msg,
00220                                   __LINE__, 
00221                                   _erno   ,
00222                                   lineno  ).what()));
00223       }
00224       _null_value = Null_Value;
00225     }
00226     
00227     void put_comments( const std::vector<std::string>& Comments) {
00228       const char *funcname = "attribute::put_comments";
00229       check_attributes(
00230                        _type     ,
00231                        _reference,
00232                        _name     ,
00233                        _null_value,
00234                        _max_length,
00235                        Comments   );
00236       if (_erno) {
00237         throw ( std::invalid_argument( error_message( 
00238                                   get_class_name(), 
00239                                   funcname, 
00240                                   __FILE__,
00241                                   _error_msg,
00242                                   __LINE__, 
00243                                   _erno   ,
00244                                   lineno  ).what()));
00245       }
00246       _comments = Comments;
00247     }
00248     
00249     friend std::istream& operator>>( std::istream& s, attribute& atr);
00250     friend std::ostream& operator<<( std::ostream& s, const attribute& atr);
00251     
00252     void print_comments( std::ostream& s) const {
00253       size_t j;
00254       for (j=0;j<_comments.size();j++) {
00255         s << _comments[j] << std::endl;
00256       }
00257     }
00258   };
00259 }
00260 
00261 #endif

Generated on Tue Jul 14 12:22:31 2009 for cstpp by  doxygen 1.5.1