HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GA_SharedDataHandle.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GU_SharedDataHandle.h
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef GU_SHAREDDATAHANDLE_H_
12 #define GU_SHAREDDATAHANDLE_H_
13 
14 #include <UT/UT_String.h>
15 #include <UT/UT_StringHolder.h>
16 #include <UT/UT_StringMap.h>
17 #include <UT/UT_JSONParser.h>
18 #include <UT/UT_IStream.h>
19 #include <UT/UT_SharedPtr.h>
20 #include <UT/UT_Lock.h>
21 #include <UT/UT_DoubleLock.h>
22 
23 #include "GA_API.h"
24 #include "GA_PrimitiveDefinition.h"
25 
26 class GA_SharedLoadData;
28 class GA_Primitive;
29 
30 class UT_SCFReader;
31 class UT_IStream;
32 
33 ///
34 /// The context stores information we can share between multiple
35 /// resolves, to allow us to keep file handles open.
36 ///
38 {
39 public:
41  virtual ~GA_SharedDataContext();
42 
43  UT_IStream *openStream(const UT_StringRef &filename);
44 protected:
45 
48 };
49 
50 ///
51 ///
52 ///
54 {
55 public:
56  /// @param filename Filename to retrieve shared data from
57  /// @param offset Offset into file given (usually given from index, -1 if no index)
58  /// @param loader The loader to use to retrieve the shared data
59  /// Setting the offset to -1 means that there was no index in the file.
60  GA_SharedDataHandle(const UT_StringHolder &filename,
61  exint offset,
62  exint length,
65 
66  /// Forces the loading of the shared data immediately from the
67  /// parser given. Used for backwards compatibility with files that
68  /// do not have an index.
69  void forceLoadSharedData(GA_SharedLoadData* loadedData);
70 
71  /// Called by shared data users when they want to retrieve the
72  /// loaded data. After calling this function they should clear
73  /// Their shared pointer to this object so the loaded data
74  /// can be freed.
75  const GA_SharedLoadData* resolveSharedData(GA_Primitive* caller);
76  const GA_SharedLoadData* resolveSharedData(GA_Primitive* caller, GA_SharedDataContext &context);
77 
78  /// Called by shared data users to get metadata on the shared data
79  /// that can be resolved though this handle.
80  /// Note: This function will return NULL if we have already
81  /// resolved our shared data (and hence stating it would not save time)
82  const GA_SharedLoadDataStat* statSharedData();
83 
84  /// Returns true if we have already resolved our shared data
85  bool hasResolvedSharedData() const;
86 
87 private:
88  /// Caller can be null if load is false.
89  /// If load is true geometry will be loaded. If not it will be stated
90  void parseSharedData(UT_DoubleLock<GA_SharedLoadData*>& lock, GA_Primitive* caller, bool load, GA_SharedDataContext &context);
91  void loadOrStatWithParser(UT_DoubleLock<GA_SharedLoadData*>& lock, UT_JSONParser& parser,
92  GA_Primitive* caller, bool load);
93 
94  /// Filename of file where shared data is kept
95  UT_StringHolder myFileName;
96 
97  /// Offset of the shared data into file
98  /// If -1 then we have no index
99  exint myOffset;
100 
101  /// Length of shared data in file
102  exint myLength;
103 
104  /// Loader to load shared data from file
106 
107  /// Storage of loaded shared data
108  /// Will be deleted when shared data handle is destroyed
109  GA_SharedLoadData* myLoadedData;
110 
111  /// Storage of stated shared data
112  /// Will be deleted when shared data handle is destroyed or
113  /// shared data is loaded.
114  GA_SharedLoadDataStat* myStatedData;
115 
116  /// Used to allow resolveSharedData/statSharedData to be safely called from
117  /// multiple threads.
118  UT_Lock myLock;
119 };
120 
122 
123 #endif // GU_SHAREDDATAHANDLE_H_
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:72
#define GA_API
Definition: GA_API.h:12
UT_SharedPtr< GA_SharedDataHandle > GA_SharedDataHandlePtr
UT_StringMap< UT_SCFReader * > mySCFReaders
int64 exint
Definition: SYS_Types.h:109
UT_StringMap< UT_IStream * > myIStreams
GLintptr offset
Definition: glcorearb.h:664
Interface for reading Seekable Compressed Format (SCF) files.
Definition: UT_SCFReader.h:20
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:794