Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/DataType/DBase.cpp

Go to the documentation of this file.
00001 // DBase.cpp - DBase Class Implementation
00002 
00003 #include <j2k/DataType/DBase.hpp>
00004 
00005 DBase::DBase() {                      // Default constructor
00006  _id   = new String();
00007  _name = new String();
00008  _tel  = new String();
00009 }
00010 
00011 DBase::DBase( DBase& db )             // Copy Constructor
00012 {
00013  _id   = new String( *db._id   );
00014  _name = new String( *db._name );
00015  _tel  = new String( *db._tel  );
00016 }
00017 
00018 DBase::DBase(const char* cmd)         // Command decoder Constructor
00019 {
00020  _id   = new String( cmd,  3,  6 );
00021  _name = new String( cmd, 13, 17 );
00022 
00023  if ( _name->parseInt()  > 0 ) {      // If it's a 2 parameters command
00024    _tel  = _name;                     // with a phone number only.
00025    _name = new String( 17, ' ' );
00026 
00027  } else {
00028    _tel  = new String( cmd, 32,  7 );
00029  }
00030 
00031    int l = _name->length();
00032    l -= 17;
00033 
00034 
00035    if ( l < 0 ) {       // Fill the rest of name with space
00036       int m = (-1 * l) + 2;
00037       _name->addChar( m, ' ');
00038    }
00039 }
00040 
00041 DBase::DBase(const char* id, const char* name, const char* tel )
00042 {
00043   _id   = new String( id   );
00044   _name = new String( name );
00045   _tel  = new String( tel  );
00046 }
00047 
00048 // String Object Constructor
00049 DBase::DBase(String& id, String& name, String& tel) {
00050  _id   = new String( id   );
00051  _name = new String( name );
00052  _tel  = new String( tel  );
00053 }
00054 
00055 
00056 // N.B. Safety Net Feature:
00057 // ========================
00058 // If we simply copy the DataStructure without testing,
00059 // we won't be able to write code such as:  db = db;
00060 // because we would loose the data before we copy it in the new one !
00061 // For sure, we don't explicitly write this kind of code
00062 // but some compiler are really enough stupid to do so ! =(
00063 
00064 DBase&  DBase::operator= (DBase& db) {
00065   if ( &db != this )  {
00066     _id   = db._id;
00067     _name = db._name;
00068     _tel  = db._tel;
00069   }
00070   return *this;
00071 }
00072 
00073 const char* DBase::string() const {    // return a char* result
00074 
00075   String* result = new String();      // Give a formatted output
00076 
00077   result->add("  ");
00078   result->add( _id->string() );
00079   result->add("   ");
00080   result->add( _name->string() );
00081   result->add("  ");
00082   result->add( _tel->string()  );
00083   result->add("  ");
00084   return result->string();
00085 }
00086 
00087 const bool  DBase::operator== ( DBase& db )
00088 {
00089   return ( *_id == *db._id ) && ( *_name == *db._name ) && ( *_tel == *db._tel );
00090 }
00091 
00092 // strcmp return True if Different !
00093 const bool  DBase::operator!= ( DBase& db )
00094 {
00095   return ( *_id != *db._id ) || ( *_name != *db._name ) || ( *_tel != *db._tel );
00096 }
00097 
00098 const bool  DBase::operator< (DBase& db) {
00099   return ( *_id < *db._id );
00100 }
00101 
00102 const bool  DBase::operator> (DBase& db) {
00103   return ( *_id > *db._id );
00104 }
00105 
00106 const bool  DBase::CompareID (DBase& db) {
00107   return _id->compare( *db._id ) > 0;
00108 }
00109 
00110 const bool  DBase::valid() const {
00111   if ( this == NULL ) {
00112      return FALSE;
00113   } else {
00114      return ( _id != NULL ) && ( _name != NULL ) && ( _tel != NULL );
00115   }
00116 }

Generated on Sun Oct 14 18:46:17 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001