home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWStream / Include / FWArDyna.h next >
Encoding:
C/C++ Source or Header  |  1995-11-08  |  11.2 KB  |  327 lines  |  [TEXT/MPS ]

  1. #ifndef FWARDYNA_H
  2. #define FWARDYNA_H
  3. //========================================================================================
  4. //
  5. //    File:                FWArDyna.h
  6. //    Release Version:    $ 1.0d11 $
  7. //
  8. //    Copyright:    (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWDICTLI_H
  13. #include "FWDictLi.h"
  14. #endif
  15.  
  16. #ifndef FWCLAINF_H
  17. #include "FWClaInf.h"
  18. #endif
  19.  
  20. #ifndef FWSTRMRW_H
  21. #include "FWStrmRW.h"
  22. #endif
  23.  
  24. #ifndef FWSTDDEF_H
  25. #include "FWStdDef.h"
  26. #endif
  27.  
  28. #if FW_LIB_EXPORT_PRAGMAS
  29. #pragma lib_export on
  30. #endif
  31.  
  32. //========================================================================================
  33. // MACROS
  34. //========================================================================================
  35.  
  36. //----------------------------------------------------------------------------------------
  37. // FW_REGISTER_ARCHIVABLE_CLASS
  38. //----------------------------------------------------------------------------------------
  39.  
  40. #define FW_REGISTER_ARCHIVABLE_CLASS(classLabel, classType, inputFunction, outputFunction) \
  41.     FW_CDynamicArchiver FWArchive##classLabel(#classLabel, \
  42.                                               FW_CLASSNAME_FROM_TYPE(classType), \
  43.                                               FW_PrivGetLocalNameToLabelMap(), \
  44.                                               FW_PrivGetLocalLabelToIOFunctionMap(), \
  45.                                               inputFunction, \
  46.                                               outputFunction);
  47.  
  48. //----------------------------------------------------------------------------------------
  49. // FW_REGISTER_PREV_VERSION_ARCHIVABLE_CLASS
  50. //----------------------------------------------------------------------------------------
  51.  
  52. #define FW_REGISTER_PREV_VERSION_ARCHIVABLE_CLASS(oldVersionClassLabel, inputFunction) \
  53.     FW_CDynamicArchiver FWArchive##oldVersionClassLabel(#oldVersionClassLabel, \
  54.                                               FW_PrivGetLocalLabelToIOFunctionMap(), \
  55.                                               inputFunction);
  56.  
  57. //----------------------------------------------------------------------------------------
  58. // FW_REGISTER_ARCHIVABLE_SOM_CLASS
  59. //----------------------------------------------------------------------------------------
  60.  
  61. #define FW_REGISTER_ARCHIVABLE_SOM_CLASS(classLabel, classType, inputFunction, outputFunction) \
  62.     FW_CDynamicArchiver FWArchive##classLabel(#classLabel, \
  63.                                               classType##NewClass(0,0)->somGetName(), \
  64.                                               FW_PrivGetLocalNameToLabelMap(), \
  65.                                               FW_PrivGetLocalLabelToIOFunctionMap(), \
  66.                                               inputFunction, \
  67.                                               outputFunction);
  68.  
  69. //----------------------------------------------------------------------------------------
  70. // FW_ARCHIVE_FUNC_ATTR
  71. //----------------------------------------------------------------------------------------
  72.  
  73. // Note: for build configurations that don't have instance data (FW_HAS_INSTANCE_DATA not
  74. // defined), map merging functions should *NOT* be exported.  They must be statically linked
  75. // in every DLL that defines dynamic classes.  The functions are defined in FWLocMap.cpp.
  76. // Every DLL which registers archivers must statically link to FWLocMap.obj.
  77.  
  78. #ifdef FW_HAS_INSTANCE_DATA
  79. #define FW_ARCHIVE_FUNC_ATTR FW_FUNC_ATTR
  80. #else
  81. #define FW_ARCHIVE_FUNC_ATTR
  82. #endif
  83.  
  84. //========================================================================================
  85. // Forward Declarations
  86. //========================================================================================
  87.  
  88. struct FW_CLASS_ATTR FW_SPrivDynamicArchiverGlobals;
  89.  
  90. //========================================================================================
  91. //    Struct FW_SPrivArcStr
  92. //    An internal implementation class used in maps for string-type keys and values
  93. //========================================================================================
  94.  
  95. struct FW_CLASS_ATTR FW_SPrivArcStr
  96. {
  97. public:
  98.     FW_SPrivArcStr(const FW_SPrivArcStr& string);
  99.     FW_SPrivArcStr(const char* string);
  100.     FW_SPrivArcStr& operator=(const FW_SPrivArcStr& string);
  101.     FW_Boolean operator==(const FW_SPrivArcStr& string) const;
  102.     FW_Boolean operator!=(const FW_SPrivArcStr& string) const;
  103.  
  104.     const char* fString;
  105.  
  106. public:
  107.     // This constructor is necessary as an artifact of the way we use the Booch components.
  108.     // It would be worthwhile to eliminate the need for it when we switch to STL.
  109. //    FW_SPrivArcStr();
  110. };
  111.  
  112. //========================================================================================
  113. //    Struct FW_SPrivArcFun
  114. //    An internal implementation class used in maps for I/O function pointer values
  115. //========================================================================================
  116.  
  117. struct FW_CLASS_ATTR FW_SPrivArcFun
  118. {
  119.     FW_SPrivArcFun(const FW_SPrivArcFun& ioFunctions);
  120.     FW_SPrivArcFun(FW_CReadableStream::InputFunction inputFunction,
  121.                    FW_CWritableStream::OutputFunction outputFunction);
  122.     FW_SPrivArcFun& operator=(const FW_SPrivArcFun& ioFunctions);
  123.     FW_Boolean operator==(const FW_SPrivArcFun& ioFunctions) const;
  124.     FW_Boolean operator!=(const FW_SPrivArcFun& ioFunctions) const;
  125.  
  126.     FW_CReadableStream::InputFunction fInputFunction;
  127.     FW_CWritableStream::OutputFunction fOutputFunction;
  128.  
  129. public:
  130.     // This constructor is necessary as an artifact of the way we use the Booch components.
  131.     // It would be worthwhile to eliminate the need for it when we switch to STL.
  132. //    FW_SPrivArcFun();
  133. };
  134.  
  135. //========================================================================================
  136. //    Class FW_CPrivNameToLabelMap
  137. //========================================================================================
  138.  
  139. class FW_CLASS_ATTR FW_CPrivNameToLabelMap : public FW_CPrivDictionaryList
  140. {
  141. public:
  142.     FW_CPrivNameToLabelMap();
  143.     virtual ~FW_CPrivNameToLabelMap();
  144. protected:
  145.     virtual FW_Boolean    KeysMatch(FW_PrivKeyType key1,FW_PrivKeyType key2) const;
  146. };
  147.  
  148. //========================================================================================
  149. //    Class FW_CPrivLabelToIOFunctionMap
  150. //========================================================================================
  151.  
  152. class FW_CLASS_ATTR FW_CPrivLabelToIOFunctionMap : public FW_CPrivDictionaryList
  153. {
  154. public:
  155.     FW_CPrivLabelToIOFunctionMap();
  156.     virtual ~FW_CPrivLabelToIOFunctionMap();
  157. protected:
  158.     virtual FW_Boolean    KeysMatch(FW_PrivKeyType key1,FW_PrivKeyType key2) const;
  159. };
  160.  
  161. //========================================================================================
  162. // STRUCT FW_SPrivDynamicArchiverGlobals
  163. //========================================================================================
  164.  
  165. #ifdef FW_BUILD_MAC
  166. #pragma options align=mac68k
  167. #endif
  168.  
  169. #ifdef FW_BUILD_WIN
  170. #pragma pack(push, 1)
  171. #endif
  172.  
  173. struct FW_CLASS_ATTR FW_SPrivDynamicArchiverGlobals
  174. {
  175.     FW_CPrivNameToLabelMap * gMapClassNameToClassLabel;
  176.     FW_CPrivLabelToIOFunctionMap * gMapClassLabelToObjectIOFunction;
  177. };
  178.  
  179. #ifdef FW_BUILD_MAC
  180. #pragma options align=reset
  181. #endif
  182.  
  183. #ifdef FW_BUILD_WIN
  184. #pragma pack(pop)
  185. #endif
  186.  
  187. //========================================================================================
  188. //    Class FW_CDynamicArchiver
  189. //========================================================================================
  190.  
  191. class FW_CLASS_ATTR FW_CDynamicArchiver
  192. {
  193.     
  194. public:
  195.  
  196.     static void InputObject(FW_CReadableStream& readableStream,
  197.                             void*& object);
  198.         // Input an object of a dynamic class from the readableStream.
  199.  
  200.     static void OutputObject(FW_CWritableStream& writableStream,
  201.                              const void* object,
  202.                              const char* className);
  203.         // Output an object of a dynamic class to the writableStream.
  204.     
  205. protected:
  206.  
  207.     enum
  208.     {
  209.         kMaxClassLabelLength = 255    // Maximum allowed length of a class label
  210.     };
  211.     
  212.     static void* ReadClassLabel(FW_CReadableStream& readableStream);
  213.  
  214.     static void WriteClassLabel(FW_CWritableStream& writableStream,
  215.                                 const void* classLabel);
  216.  
  217.  
  218.     // ----- Task global implementation items
  219.  
  220. public:
  221.  
  222.     static void Initialize(FW_SPrivDynamicArchiverGlobals& globals);
  223.     static void Terminate();
  224.     static FW_SPrivDynamicArchiverGlobals& GetDynamicArchiverGlobals();
  225.  
  226. protected:
  227.  
  228.     enum
  229.     {
  230.         kDynamicArchiverGlobalsOffset = 158
  231.     };
  232.  
  233.     // ----- Dynamic map implementation items
  234.  
  235. public:
  236.  
  237.     friend FW_ARCHIVE_FUNC_ATTR void FW_MergeArchiverMaps();
  238.     friend FW_ARCHIVE_FUNC_ATTR FW_CPrivNameToLabelMap& FW_PrivGetLocalNameToLabelMap();
  239.     friend FW_ARCHIVE_FUNC_ATTR FW_CPrivLabelToIOFunctionMap& FW_PrivGetLocalLabelToIOFunctionMap();
  240.  
  241.     FW_CDynamicArchiver(const char* classLabel,
  242.                         const char* className,
  243.                         FW_CPrivNameToLabelMap& localNameToLabelMap,
  244.                         FW_CPrivLabelToIOFunctionMap& localLabelToIOFunctionMap,
  245.                         FW_CReadableStream::InputFunction inputFunction,
  246.                         FW_CWritableStream::OutputFunction outputFunction);
  247.         // Register the <classLabel, className, inputFunction, outputFunction>
  248.         // 4-tuple of a dynamic class with the archiver.
  249.  
  250.     FW_CDynamicArchiver(const char* oldVersionClassLabel,
  251.                         FW_CPrivLabelToIOFunctionMap& localLabelToIOFunctionMap,
  252.                         FW_CReadableStream::InputFunction inputFunction);
  253.         // Registers the <classLabel, inputFunction> for an old label.
  254.  
  255.     static FW_CReadableStream::InputFunction LookupInputFunction(const char* classLabel);
  256.     
  257.     static FW_CWritableStream::OutputFunction LookupOutputFunction(const char* classLabel);
  258.  
  259. private:
  260.  
  261. //    static BC_Index HashFunction(const FW_SPrivArcStr& string);
  262.     
  263.     static FW_CPrivNameToLabelMap& GetNameToLabelMap();
  264.     
  265.     static FW_CPrivLabelToIOFunctionMap& GetLabelToIOFunctionMap();
  266.  
  267.     static FW_CPrivNameToLabelMap * gLocalClassNameToClassLabelMap;
  268.     
  269.     static FW_CPrivLabelToIOFunctionMap * gLocalClassLabelToObjectIOFunctionMap;
  270.  
  271.     static void MergeNameToLabelMaps(FW_CPrivNameToLabelMap& local,
  272.                                     FW_CPrivNameToLabelMap& global);
  273.     
  274.     static void MergeLabelToIOFunctionMaps(FW_CPrivLabelToIOFunctionMap& local,
  275.                                     FW_CPrivLabelToIOFunctionMap& global);
  276.  
  277. private:
  278.     static FW_SPrivDynamicArchiverGlobals gGlobals;
  279.  
  280. private:
  281.     FW_CDynamicArchiver(const FW_CDynamicArchiver& archiver);
  282.     FW_CDynamicArchiver& operator=(const FW_CDynamicArchiver& archiver);
  283.         // Shouldn't need to copy this class.
  284. };
  285.  
  286. //----------------------------------------------------------------------------------------
  287. // FW_CPrivNameToLabelMap& FW_CDynamicArchiver::GetNameToLabelMap
  288. //----------------------------------------------------------------------------------------
  289.  
  290. inline FW_CPrivNameToLabelMap& FW_CDynamicArchiver::GetNameToLabelMap()
  291. {
  292.     return *GetDynamicArchiverGlobals().gMapClassNameToClassLabel;
  293. }
  294.  
  295. //----------------------------------------------------------------------------------------
  296. // FW_CPrivLabelToIOFunctionMap& FW_CDynamicArchiver::GetLabelToIOFunctionMap
  297. //----------------------------------------------------------------------------------------
  298.  
  299. inline FW_CPrivLabelToIOFunctionMap& FW_CDynamicArchiver::GetLabelToIOFunctionMap()
  300. {
  301.     return *GetDynamicArchiverGlobals().gMapClassLabelToObjectIOFunction;
  302. }
  303.  
  304.  
  305. //========================================================================================
  306. // Archiver maps implementation functions
  307. //========================================================================================
  308.  
  309. FW_ARCHIVE_FUNC_ATTR FW_CPrivNameToLabelMap& FW_PrivGetLocalNameToLabelMap();
  310.  
  311. FW_ARCHIVE_FUNC_ATTR FW_CPrivLabelToIOFunctionMap& FW_PrivGetLocalLabelToIOFunctionMap();
  312.  
  313. void FW_ARCHIVE_FUNC_ATTR FW_MergeArchiverMaps();
  314.     // Merge application's or component's archiver map into global archiver map.
  315.  
  316. void FW_ARCHIVE_FUNC_ATTR FW_InitializeArchiving(FW_Instance rootInstance);
  317.  
  318. #ifdef FW_BUILD_WIN16
  319. extern "C" void FW_FUNC_ATTR FW_MERGEARCHIVERMAPSHOOK();
  320. #endif
  321.  
  322. #if FW_LIB_EXPORT_PRAGMAS
  323. #pragma lib_export off
  324. #endif
  325.  
  326. #endif
  327.