home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 2.ddi / TVINC.ZIP / RESOURCE.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  6.7 KB  |  271 lines

  1. /* ------------------------------------------------------------------------*/
  2. /*                                                                         */
  3. /*   RESOURCE.H                                                            */
  4. /*                                                                         */
  5. /*   Copyright (c) Borland International 1991                              */
  6. /*   All Rights Reserved.                                                  */
  7. /*                                                                         */
  8. /*   defines the classes TStringCollection, TResourceCollection,           */
  9. /*   TResourceFile, TStrListMaker, and TStringList                         */
  10. /*                                                                         */
  11. /* ------------------------------------------------------------------------*/
  12.  
  13. #pragma option -Vo-
  14. #if defined( __BCOPT__ )
  15. #pragma option -po-
  16. #endif
  17.  
  18. #if defined( Uses_TStringCollection ) && !defined( __TStringCollection )
  19. #define __TStringCollection
  20.  
  21. class TStringCollection : public TSortedCollection
  22. {
  23.  
  24. public:
  25.  
  26.     TStringCollection( short aLimit, short aDelta );
  27.  
  28. private:
  29.  
  30.     virtual int compare( void *key1, void *key2 );
  31.     virtual void freeItem( void *item );
  32.  
  33.     virtual const char *streamableName() const
  34.         { return name; }
  35.     virtual void *readItem( ipstream& );
  36.     virtual void writeItem( void *, opstream& );
  37.  
  38. protected:
  39.  
  40.     TStringCollection( StreamableInit ) : TSortedCollection ( streamableInit ) {};
  41.  
  42. public:
  43.  
  44.     static const char * const near name;
  45.     static TStreamable *build();
  46.  
  47. };
  48.  
  49. inline ipstream& operator >> ( ipstream& is, TStringCollection& cl )
  50.     { return is >> (TStreamable&)cl; }
  51. inline ipstream& operator >> ( ipstream& is, TStringCollection*& cl )
  52.     { return is >> (void *&)cl; }
  53.  
  54. inline opstream& operator << ( opstream& os, TStringCollection& cl )
  55.     { return os << (TStreamable&)cl; }
  56. inline opstream& operator << ( opstream& os, TStringCollection* cl )
  57.     { return os << (TStreamable *)cl; }
  58.  
  59. #endif  // Uses_TStringCollection
  60.  
  61. #if defined( Uses_TResourceItem ) && !defined( __TResourceItem )
  62. #define __TResourceItem
  63.  
  64. struct TResourceItem
  65. {
  66.     
  67.     long pos;
  68.     long size;
  69.     char *key;
  70. };
  71.  
  72. #endif  // Uses_TResourceItem
  73.  
  74. #if defined( Uses_TResourceCollection ) && !defined( __TResourceCollection )
  75. #define __TResourceCollection
  76.  
  77. class TResourceCollection: public TStringCollection
  78. {
  79.  
  80. public:
  81.  
  82.     TResourceCollection( StreamableInit) : TStringCollection( streamableInit ) {};
  83.     TResourceCollection( short aLimit, short aDelta );
  84.  
  85.     virtual void *keyOf( void *item );
  86.  
  87. private:
  88.  
  89.     virtual void freeItem( void *item );
  90.  
  91.     virtual const char *streamableName() const
  92.         { return name; }
  93.     virtual void *readItem( ipstream& );
  94.     virtual void writeItem( void *, opstream& );
  95.  
  96. public:
  97.  
  98.     static const char * const near name;
  99.     static TStreamable *build();
  100.  
  101. };
  102.  
  103. inline ipstream& operator >> ( ipstream& is, TResourceCollection& cl )
  104.     { return is >> (TStreamable&)cl; }
  105. inline ipstream& operator >> ( ipstream& is, TResourceCollection*& cl )
  106.     { return is >> (void *&)cl; }
  107.  
  108. inline opstream& operator << ( opstream& os, TResourceCollection& cl )
  109.     { return os << (TStreamable&)cl; }
  110. inline opstream& operator << ( opstream& os, TResourceCollection* cl )
  111.     { return os << (TStreamable *)cl; }
  112.  
  113. #endif  // Uses_TResourceCollection
  114.  
  115. #if defined( Uses_TResourceFile ) && !defined( __TResourceFile )
  116. #define __TResourceFile
  117.  
  118. class far TResourceCollection;
  119. class far fpstream;
  120.  
  121. class TResourceFile: public TObject
  122. {
  123.  
  124. public:
  125.  
  126.     TResourceFile( fpstream *aStream );
  127.     ~TResourceFile();
  128.     short count();
  129.     void remove( const char *key );
  130.     void flush();
  131.     void *get( const char *key );
  132.     const char *keyAt( short i );
  133.     void put( TStreamable *item, const char *key );
  134.     fpstream *switchTo( fpstream *aStream, Boolean pack );
  135.  
  136. protected:
  137.  
  138.     fpstream *stream;
  139.     Boolean modified;
  140.     long basePos;
  141.     long indexPos;
  142.     TResourceCollection *index;
  143. };
  144.  
  145. #endif  // Uses_TResourceFile
  146.  
  147. #if defined( Uses_TStrIndexRec ) && !defined( __TStrIndexRec )
  148. #define __TStrIndexRec
  149.  
  150. class TStrIndexRec
  151. {
  152.  
  153. public:
  154.  
  155.     TStrIndexRec();
  156.  
  157.     ushort key;
  158.     ushort count;
  159.     ushort offset;
  160.  
  161. };
  162.  
  163. #endif  // Uses_TStrIndexRec
  164.  
  165. #if defined( Uses_TStringList ) && !defined( __TStringList )
  166. #define __TStringList
  167.  
  168. class far TStrIndexRec;
  169.  
  170. class TStringList : public TObject, public TStreamable
  171. {
  172.  
  173. public:
  174.  
  175.     ~TStringList();
  176.  
  177.     void get( char *dest, ushort key );
  178.  
  179. private:
  180.  
  181.     ipstream *ip;
  182.     long basePos;
  183.     short indexSize;
  184.     TStrIndexRec *index;
  185.  
  186.     virtual const char *streamableName() const
  187.         { return name; }
  188.  
  189. protected:
  190.  
  191.     TStringList( StreamableInit );
  192.     virtual void write( opstream& ) {}
  193.     virtual void *read( ipstream& );
  194.  
  195. public:
  196.  
  197.     static const char * const near name;
  198.     static TStreamable *build();
  199.  
  200. };
  201.  
  202. inline ipstream& operator >> ( ipstream& is, TStringList& cl )
  203.     { return is >> (TStreamable&)cl; }
  204. inline ipstream& operator >> ( ipstream& is, TStringList*& cl )
  205.     { return is >> (void *&)cl; }
  206.  
  207. inline opstream& operator << ( opstream& os, TStringList& cl )
  208.     { return os << (TStreamable&)cl; }
  209. inline opstream& operator << ( opstream& os, TStringList* cl )
  210.     { return os << (TStreamable *)cl; }
  211.  
  212. #endif  // Uses_TStringList
  213.  
  214.  
  215. #if defined( Uses_TStrListMaker ) && !defined( __TStrListMaker )
  216. #define __TStrListMaker
  217.  
  218. class TStrListMaker : public TObject, public TStreamable
  219. {
  220.  
  221. public:
  222.  
  223.     TStrListMaker( ushort aStrSize, ushort aIndexSize );
  224.     ~TStrListMaker();
  225.  
  226.     void put( ushort key, char *str );
  227.  
  228. private:
  229.  
  230.     ushort strPos;
  231.     ushort strSize;
  232.     char *strings;
  233.     ushort indexPos;
  234.     ushort indexSize;
  235.     TStrIndexRec *index;
  236.     TStrIndexRec cur;
  237.     void closeCurrent();
  238.  
  239.     virtual const char *streamableName() const
  240.         { return TStringList::name; }
  241.  
  242. protected:
  243.  
  244.     TStrListMaker( StreamableInit );
  245.     virtual void write( opstream& );
  246.     virtual void *read( ipstream& ) { return 0; }
  247.  
  248. public:
  249.  
  250.     static TStreamable *build();
  251.  
  252. };                    
  253.  
  254. inline ipstream& operator >> ( ipstream& is, TStrListMaker& cl )
  255.     { return is >> (TStreamable&)cl; }
  256. inline ipstream& operator >> ( ipstream& is, TStrListMaker*& cl )
  257.     { return is >> (void *&)cl; }
  258.  
  259. inline opstream& operator << ( opstream& os, TStrListMaker& cl )
  260.     { return os << (TStreamable&)cl; }
  261. inline opstream& operator << ( opstream& os, TStrListMaker* cl )
  262.     { return os << (TStreamable *)cl; }
  263.  
  264.  
  265. #endif  // Uses_TStrListMaker
  266.  
  267. #pragma option -Vo.
  268. #if defined( __BCOPT__ )
  269. #pragma option -po.
  270. #endif
  271.