HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_AgentMetadata.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 
7 #ifndef __GU_AgentMetadata__
8 #define __GU_AgentMetadata__
9 
10 #include "GU_API.h"
11 
12 #include <UT/UT_Assert.h>
13 #include <UT/UT_IntrusivePtr.h>
14 #include <UT/UT_Options.h>
15 #include <UT/UT_StringHolder.h>
16 #include <SYS/SYS_Types.h>
17 
18 class UT_JSONParser;
19 class UT_JSONWriter;
20 class UT_StringArray;
21 
22 class GU_AgentMetadata;
25 
26 /// Provides a simple way to store custom metadata (UT_Options) in the agent
27 /// definition.
28 class GU_API GU_AgentMetadata : public UT_IntrusiveRefCounter<GU_AgentMetadata>
29 {
30 public:
31  /// Use the static addMetadata() method to create new metadata items.
32  /// This is only public for use with UTmakeIntrusive().
35  const UT_OptionsHolder &dict)
36  : myFileName(filename), myDict(dict)
37  {
38  }
39 
41 
42  /// Create new empty metadata.
43  static GU_AgentMetadataPtr addMetadata();
44  /// Load the metadata from a file.
45  static GU_AgentMetadataPtr addMetadataFromFile(
47  UT_StringArray &errors);
48  /// Creates a copy of the metadata. The copy will not be marked as an
49  /// external reference.
50  static GU_AgentMetadataPtr addMetadataCopy(const GU_AgentMetadata &src);
51 
52  /// The amount of memory used by this item.
53  int64 getMemoryUsage(bool inclusive) const;
54 
55  /// Return whether the metadata was loaded from disk.
56  bool isFile() const { return myFileName.isstring(); }
57  /// Clear the flag marking that the metadata references a file on disk.
58  void clearIsFile();
59  /// Returns the name of the file referenced on disk.
60  const UT_StringHolder &fileName() const
61  {
62  UT_ASSERT(isFile());
63  return myFileName;
64  }
65 
66  /// Save the metadata.
67  bool save(UT_JSONWriter &w) const;
68  /// Load the metadata.
69  bool load(UT_JSONParser &p, UT_StringArray &errors);
70 
71  /// Returns the metadata dictionary.
72  const UT_OptionsHolder &dict() const { return myDict; }
73 
74  /// Updates the metadata dictionary.
75  void setDict(const UT_OptionsHolder &dict) { myDict = dict; }
76 
77 private:
78  UT_StringHolder myFileName;
79  UT_OptionsHolder myDict;
80 };
81 
82 #endif
GT_API const UT_StringHolder filename
GU_AgentMetadata(const UT_StringHolder &filename, const UT_OptionsHolder &dict)
void setDict(const UT_OptionsHolder &dict)
Updates the metadata dictionary.
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
const UT_OptionsHolder & dict() const
Returns the metadata dictionary.
const UT_StringHolder & fileName() const
Returns the name of the file referenced on disk.
A reference counter base class for use with UT_IntrusivePtr.
Wrapper around hboost::intrusive_ptr.
long long int64
Definition: SYS_Types.h:116
#define GU_API
Definition: GU_API.h:14
bool isFile() const
Return whether the metadata was loaded from disk.
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
GLenum src
Definition: glcorearb.h:1793