home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Demos / OOFILE / Buildable, limited OOFILE / OOFILE headers / oof3.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-27  |  9.3 KB  |  352 lines  |  [TEXT/CWIE]

  1. #ifndef H_OOF3
  2. #define H_OOF3
  3.  
  4. // COPYRIGHT 1994 A.D. Software, All rights reserved
  5.  
  6. // OOFILE database non-numeric field-related classes
  7. // see also oof4.hpp
  8.  
  9. #include "oof1.hpp"
  10. #ifdef _Macintosh
  11. #include <Types.h>
  12. #endif
  13.  
  14. enum OOF_fieldTypes {charField, textField, dateField, shortField, uShortField, longField, uLongField, realField, blobField, compoundField, boolField, fixedBinaryField};
  15. ostream& operator<<(ostream&, OOF_fieldTypes);
  16.  
  17. class dbField : public dbClass, public OOF_mixRelChainEndPoint{
  18. public:
  19.      dbField() ; 
  20.     dbField(const OOF_IndexOptions) ; 
  21.     dbField(const char *) ;
  22.     dbField(const char *, const OOF_IndexOptions);
  23.      dbField(const dbField&); 
  24.     virtual ~dbField() {};
  25.     
  26. //    operator dbField*(); 
  27.  
  28. // additional setting operators
  29.     void index(const OOF_IndexOptions=kIndexed);
  30.     void setName(const char* name);
  31.  
  32. // reflective operators
  33.     virtual void describe(ostream&);
  34.     virtual unsigned int countSegments() const;
  35.     virtual OOF_fieldTypes fieldType() const=0;
  36.     virtual unsigned long fieldLen() const=0;
  37.     virtual unsigned int fieldEditLen() const;
  38.     dbTable* fieldTable() const;
  39.     unsigned long fieldDataLen() const;
  40.     fieldNumT fieldNumber() const;
  41.     OOF_String fieldName() const;
  42.     OOF_IndexOptions fieldIndexOptions() const;
  43.     bool fieldIndexAllowsDups() const;
  44.     bool fieldIndexIsCompressLeading() const;
  45.     bool fieldIndexIsCompressPadding() const;
  46.     virtual bool fieldIsIndexed() const;
  47.     virtual bool fieldIsUniqueIndexed() const;
  48.     unsigned int fieldNumIndexes() const;
  49.     bool allowsDuplicates() const;
  50.     bool caseSensitive() const;
  51.     virtual bool fieldIsBlob() const;
  52.     virtual bool fieldIsBinary() const;
  53.     virtual bool fieldIsVirtual() const;
  54.  
  55. // data access
  56.     virtual void setString(const char*) { assert(0); };  
  57.     void operator=(const char*); 
  58.     virtual char *copyAsChars();
  59.     const void* binaryContents();
  60.     const void* currentbinaryContents() const;
  61.     virtual void extract(ostream&);
  62.     virtual bool insert(istream&, char fieldSep, char recSep);
  63.     virtual void copyValueFrom(dbField*) {};
  64.     virtual bool validateContents() { return true; };
  65.  
  66.     virtual void generateTestData(const char *testBuf, unsigned long testBufLen) {};    
  67.     
  68.     
  69. protected:
  70.     void validateContextInCaseRelated(); 
  71.     dbField* GetRelatedFieldOrUs();
  72.  
  73. // data storage
  74.     OOF_tableBackend *mBackend;
  75.     dbTable*    mTable;
  76.     unsigned int mFieldNumber;
  77.     
  78. private:
  79.     OOF_IndexOptions mIndexOptions;
  80.     OOF_String mFieldName;
  81.  
  82.     friend    class dbTable;
  83.     friend void validateDatabaseState();
  84. };
  85. typedef dbField *dbFieldPtr;
  86.  
  87.  
  88.  
  89. class dbQueryBinary;
  90. class dbQueryTrinary;
  91. class dbQueryBinaryCombo;
  92.  
  93. class dbChar : public dbField  {
  94. public:
  95. // constructors
  96.   dbChar(long fieldWidth = 80) :
  97.                 mMaxLength(fieldWidth) {};
  98.   dbChar(long fieldWidth, const char *fieldName):
  99.                 dbField(fieldName),
  100.                 mMaxLength(fieldWidth){};
  101.     dbChar(long fieldWidth, const OOF_IndexOptions indexOptions) :
  102.                 dbField(indexOptions),
  103.                 mMaxLength(fieldWidth) {}; 
  104.   dbChar(long fieldWidth, const char *fieldName, const OOF_IndexOptions indexOptions)  :
  105.                 dbField(fieldName, indexOptions),
  106.                 mMaxLength(fieldWidth) {};  
  107.     virtual ~dbChar() {};
  108.  
  109. // reflective operators
  110.     virtual void describe(ostream&);
  111.     virtual OOF_fieldTypes fieldType() const;
  112.     virtual bool fieldIsBinary() const;
  113.     virtual unsigned long fieldLen() const;
  114.  
  115. // search factories
  116.     dbQueryBinary    operator==(const char*) const;
  117.     dbQueryBinary    operator<(const char*) const;
  118.     dbQueryBinary    operator<=(const char*) const;
  119.     dbQueryBinary    operator>=(const char*) const;
  120.     dbQueryBinary    operator>(const char*) const;
  121.     dbQueryBinary    operator!=(const char*) const;
  122.     dbQueryBinary    startsWith(const char*) const;
  123.     dbQueryTrinary    between(const char*, const char*) const;
  124.     dbQueryTrinary    outside(const char*, const char*) const;
  125.  
  126. // data access
  127.     dbChar& operator()();
  128.     virtual  char * copyAsChars();
  129.     operator const char*();
  130. #ifdef _Macintosh
  131.     void asStr255(Str255 s);
  132.     void setStr255(const Str255 s);
  133. #endif
  134.     virtual void setString(const char*);  
  135.     dbChar& operator=(const char*);  
  136.     void setChars(const char* str , unsigned long charLen);
  137.     dbChar& operator=(dbChar&);
  138.     virtual void extract(ostream& os);
  139.     virtual bool insert(istream&, char fieldSep, char recSep);
  140.  
  141.     virtual void generateTestData(const char *testBuf, unsigned long testBufLen);
  142.  
  143. // data storage
  144. private:
  145.   long mMaxLength;
  146. };
  147.  
  148.  
  149.  
  150. class dbBLOB : public dbField {
  151. public:
  152. // constructors
  153.   dbBLOB() :
  154.                 mBody(0),
  155.                 mBodyLength(0),
  156.                 mDirty(false),
  157.                 mLoaded(false)
  158.           {};
  159.     dbBLOB(const OOF_IndexOptions indexOptions) :
  160.                 dbField(indexOptions),
  161.                 mBody(0),
  162.                 mBodyLength(0),
  163.                 mDirty(false),
  164.                 mLoaded(false)
  165.     {};
  166.   dbBLOB(const char *fieldName)  :
  167.                 dbField(fieldName),
  168.                 mBody(0),
  169.                 mBodyLength(0),
  170.                 mDirty(false),
  171.                 mLoaded(false)
  172.   {};
  173.     dbBLOB(const char *fieldName, const OOF_IndexOptions indexOptions)  :
  174.                 dbField(fieldName, indexOptions),
  175.                 mBody(0),
  176.                 mBodyLength(0),
  177.                 mDirty(false),
  178.                 mLoaded(false)
  179.     {};  
  180.   dbBLOB(const dbBLOB& rhs) :
  181.                 mBody(0),
  182.                 mBodyLength(0),
  183.                 mDirty(false),
  184.                 mLoaded(false)
  185.           {};
  186.     virtual ~dbBLOB();
  187.  
  188. // reflective operators
  189.     virtual OOF_fieldTypes fieldType() const;
  190.     virtual unsigned long fieldLen() const;
  191.     virtual bool fieldIsBlob() const;
  192.     bool isDirty() const;
  193.  
  194. // data access
  195.     dbBLOB& operator()();
  196.     void *bodyAddress() const;
  197.     void reset();
  198.     void* allocRoomFor(unsigned long);
  199.     void *orphanBody();
  200.     void adoptBody(void* body, unsigned long bodyLen);
  201.  
  202. protected:
  203.      void SetLength(unsigned long len);
  204.     void LoadField();
  205.     
  206. // data storage
  207.     void*    mBody;    // owned
  208.     unsigned long mBodyLength;  // allow for part-using the block
  209.     bool mDirty,mLoaded;
  210.     
  211.  
  212. };
  213.  
  214.  
  215. class dbText : public dbBLOB {
  216. public:
  217. // constructors
  218.   dbText(){};
  219.     dbText(const OOF_IndexOptions opt) :
  220.                 dbBLOB(opt) 
  221.                 {
  222. //                assert( opt == kNotIndexed);  // more later
  223.                 }; 
  224.   dbText(const char *fieldName)  :
  225.                 dbBLOB(fieldName) {}; 
  226.   dbText(const char *fieldName, const OOF_IndexOptions opt)  :
  227.                 dbBLOB(fieldName, opt) {//assert(opt == kNotIndexed);
  228.                 };  
  229.     virtual ~dbText() {};
  230.  
  231. // reflective operators
  232.     virtual OOF_fieldTypes fieldType() const;
  233.     virtual bool fieldIsBinary() const;
  234.  
  235. // search factories
  236.     dbQueryBinary    operator==(const char*) const;
  237.     dbQueryBinary    operator<(const char*) const;
  238.     dbQueryBinary    operator<=(const char*) const;
  239.     dbQueryBinary    operator>=(const char*) const;
  240.     dbQueryBinary    operator>(const char*) const;
  241.     dbQueryBinary    operator!=(const char*) const;
  242.  
  243. // data access
  244.     dbText& operator()();
  245.     virtual char * copyAsChars();
  246.     operator const char*();
  247.     virtual void setString(const char*);  
  248.     dbText& operator=(const char*); 
  249.     dbText& operator=(dbText&);
  250.     void operator+=(const char*);  // the only field with an append operator
  251.     void setChars(const char* str , unsigned long charLen);
  252.     virtual void extract(ostream& os);
  253.  
  254.     virtual void generateTestData(const char *testBuf, unsigned long testBufLen);    
  255. };
  256.  
  257.  
  258. class dbFixedBinary : public dbField {
  259. public:
  260. // constructors
  261.     dbFixedBinary(long fieldWidth = 4) :
  262.                 mBodyLength(fieldWidth) {};
  263.     dbFixedBinary(long fieldWidth, const OOF_IndexOptions indexOptions) :
  264.                 dbField(indexOptions),
  265.                 mBodyLength(fieldWidth) {}; 
  266.     dbFixedBinary(long fieldWidth, const char *fieldName)  :
  267.                 dbField(fieldName),
  268.                 mBodyLength(fieldWidth)  {};  
  269.     dbFixedBinary(long fieldWidth, const char *fieldName, const OOF_IndexOptions indexOptions)  :
  270.                 dbField(fieldName, indexOptions),
  271.                 mBodyLength(fieldWidth) {};  
  272.     dbFixedBinary& operator=(dbFixedBinary& rhs);
  273.                 
  274.     virtual ~dbFixedBinary() {};
  275.  
  276. // reflective operators
  277.     virtual OOF_fieldTypes fieldType() const;
  278.     virtual unsigned long fieldLen() const;
  279.     
  280. // data access
  281.     dbFixedBinary& operator()();
  282.     dbFixedBinary&  operator=(const char* str);
  283.     virtual void setString(const char*);  
  284.     void setValue(const void* str);
  285.     void setByte(char c, unsigned int offset);
  286.     virtual void extract(ostream& os);
  287.     virtual void generateTestData(const char *testBuf, unsigned long testBufLen);
  288.     virtual void describe(ostream& os);
  289.  
  290. protected:
  291.     
  292. // data storage
  293.     unsigned long mBodyLength; 
  294.     
  295.  
  296. };
  297.  
  298.  
  299. class dbCompoundField : public dbField {
  300. public:
  301. // constructors
  302.   dbCompoundField() : 
  303.                                 mNumSegments(0),
  304.                                 mTotalLength(0)  {};
  305.     dbCompoundField(const OOF_IndexOptions indexOptions) :
  306.                                 dbField(indexOptions),
  307.                                 mNumSegments(0),
  308.                                 mTotalLength(0)  {}; 
  309.   dbCompoundField(const char *fieldName) :
  310.                                 dbField(fieldName),
  311.                                 mNumSegments(0),
  312.                                 mTotalLength(0) {};
  313.   dbCompoundField(const char *fieldName, const OOF_IndexOptions indexOptions) :
  314.                                 dbField(fieldName, indexOptions),
  315.                                 mNumSegments(0),
  316.                                 mTotalLength(0) {};
  317.     virtual ~dbCompoundField() {};
  318.     
  319.     virtual unsigned int countSegments() const;
  320.     void addSegment(dbField&);
  321.     dbCompoundField& operator<<(dbField&);
  322.     
  323. // data output
  324.     virtual void extract(ostream& os);
  325.  
  326. // reflective operators
  327.     virtual OOF_fieldTypes fieldType() const;
  328.     virtual unsigned long fieldLen() const;
  329.     virtual bool fieldIsVirtual() const;
  330.     const dbField* segment(unsigned int) const;
  331.  
  332. // search factories
  333.     dbQueryBinary    operator==(const char*) const;
  334.     dbQueryBinary    operator<(const char*) const;
  335.     dbQueryBinary    operator<=(const char*) const;
  336.     dbQueryBinary    operator>=(const char*) const;
  337.     dbQueryBinary    operator>(const char*) const;
  338.     dbQueryBinary    operator!=(const char*) const;
  339.     dbQueryBinary    startsWith(const char* str) const;
  340.  
  341. // data storage
  342. private:
  343.     unsigned int mNumSegments, mTotalLength;
  344.     OOF_Dictionary    mSegments;
  345. };
  346.  
  347.  
  348.  
  349. // include inline definitions
  350. #include "oof3.inl"
  351. #endif
  352.