HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 "GA_API.h"
15 #include "GA_PrimitiveDefinition.h"
16 
17 #include <UT/UT_StringHolder.h>
18 #include <UT/UT_SharedPtr.h>
19 #include <UT/UT_Lock.h>
20 #include <UT/UT_DoubleLock.h>
21 #include <SYS/SYS_Types.h>
22 
23 class GA_Primitive;
25 class GA_SharedLoadData;
27 
28 class UT_JSONParser;
29 
30 
31 ///
32 ///
33 ///
35 {
36 public:
37  /// @param filename Filename to retrieve shared data from
38  /// @param offset Offset into file given (usually given from index, -1 if no index)
39  /// @param loader The loader to use to retrieve the shared data
40  /// Setting the offset to -1 means that there was no index in the file.
42  exint offset,
43  exint length,
46 
47  /// Forces the loading of the shared data immediately from the
48  /// parser given. Used for backwards compatibility with files that
49  /// do not have an index.
50  void forceLoadSharedData(GA_SharedLoadData* loaded_data);
51 
52  /// Called by shared data users when they want to retrieve the
53  /// loaded data. After calling this function they should clear
54  /// Their shared pointer to this object so the loaded data
55  /// can be freed.
56  const GA_SharedLoadData* resolveSharedData(GA_Primitive* caller);
57  const GA_SharedLoadData* resolveSharedData(GA_Primitive* caller, GA_SharedDataContext &context);
58 
59  /// Called by shared data users to get metadata on the shared data
60  /// that can be resolved though this handle.
61  /// Note: This function will return NULL if we have already
62  /// resolved our shared data (and hence stating it would not save time)
63  const GA_SharedLoadDataStat* statSharedData();
64 
65  /// Returns true if we have already resolved our shared data
66  bool hasResolvedSharedData() const;
67 
68 private:
69  /// Caller can be null if load is false.
70  /// If load is true geometry will be loaded. If not it will be stated
71  void parseSharedData(UT_DoubleLock<GA_SharedLoadData*>& lock, GA_Primitive* caller, bool load, GA_SharedDataContext &context);
72  void loadOrStatWithParser(UT_DoubleLock<GA_SharedLoadData*>& lock, UT_JSONParser& parser,
73  GA_Primitive* caller, bool load);
74 
75  /// Filename of file where shared data is kept
76  UT_StringHolder myFileName;
77 
78  /// Offset of the shared data into file
79  /// If -1 then we have no index
80  exint myOffset;
81 
82  /// Length of shared data in file
83  exint myLength;
84 
85  /// Loader to load shared data from file
87 
88  /// Storage of loaded shared data
89  /// Will be deleted when shared data handle is destroyed
90  GA_SharedLoadData* myLoadedData;
91 
92  /// Storage of stated shared data
93  /// Will be deleted when shared data handle is destroyed or
94  /// shared data is loaded.
95  GA_SharedLoadDataStat* myStatedData;
96 
97  /// Used to allow resolveSharedData/statSharedData to be safely called from
98  /// multiple threads.
99  UT_Lock myLock;
100 };
101 
103 
104 #endif // GU_SHAREDDATAHANDLE_H_
GT_API const UT_StringHolder filename
int64 exint
Definition: SYS_Types.h:125
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
#define GA_API
Definition: GA_API.h:14
UT_SharedPtr< GA_SharedDataHandle > GA_SharedDataHandlePtr
GLintptr offset
Definition: glcorearb.h:665
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36