HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GA_Group.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: GA_Group.h (GA Library, C++)
7  *
8  * COMMENTS: Base class for groups.
9  *
10  */
11 
12 #pragma once
13 
14 #ifndef __GA_Group_h__
15 #define __GA_Group_h__
16 
17 #include "GA_API.h"
18 #include "GA_Types.h"
19 
20 #include <UT/UT_StringHolder.h>
21 #include <SYS/SYS_Inline.h>
22 #include <SYS/SYS_Types.h>
23 #include <iosfwd>
24 
25 class GA_Detail;
26 class GA_LoadMap;
27 class GA_SaveMap;
28 
29 class UT_JSONParser;
30 class UT_JSONWriter;
31 class UT_WorkBuffer;
32 class UT_MemoryCounter;
33 
35 {
36 protected:
37  GA_Group(const UT_StringHolder &name, bool internal, GA_GroupType type, bool detached);
38 public:
39  virtual ~GA_Group();
40 
41  const UT_StringHolder &getName() const { return myName; }
42  virtual const GA_Detail &getDetail() const = 0;
43 
44  bool isInternal() const { return myInternal; }
45  bool getInternal() const { return myInternal; }
46  void setInternal(bool onOff) { myInternal = onOff; }
47 
48  /// Detached groups are not owned by a GA_Detail. This means
49  /// they will not update if their GA_Detail's element count changes.
50  /// It also means they must be explicitly deleted
51  bool isDetached() const { return myDetached; }
52 
53  GA_GroupType classType(void) const
54  { return GA_GroupType(myType); }
56  { return GA_GroupMaskType(1 << myType); }
57  static const char *groupType(GA_GroupType type)
58  { return GAgroupType(type); }
59  static GA_GroupType groupType(const char *type)
60  { return GAgroupType(type); }
61 
62  bool isElementGroup() const
63  {
64  return (classMaskType() & (GA_GMASK_POINT | GA_GMASK_VERTEX | GA_GMASK_PRIMITIVE)) != 0;
65  }
66 
67  /// Report memory usage
68  /// NOTE: GA_ElementGroup DOES NOT include the memory for the attribute
69  /// unless the attribute is detached, because the GA_ElementGroup
70  /// only owns the attribute if it is detached.
71  virtual int64 getMemoryUsage(bool inclusive) const = 0;
72 
73  /// Count memory usage using a UT_MemoryCounter in order to count
74  /// shared memory correctly.
75  /// If inclusive is true, the size of this object is counted,
76  /// else only memory owned by this object is counted.
77  /// If this is pointed to by the calling object, inclusive should be true.
78  /// If this is contained in the calling object, inclusive should be false.
79  /// (Its memory was already counted in the size of the calling object.)
80  virtual void countMemory(UT_MemoryCounter &counter,
81  bool inclusive) const = 0;
82 
83  virtual GA_Size entries() const = 0;
84 
85  // FIXME: Switch this back to SYS_FORCE_INLINE when Microsoft fixes
86  // Visual Studio bug report ID 2154929.
87  // It seems to be fixed in Update 3, so I updated the define,
88  // but we haven't switched our builds over yet from Update 1.
89 #if defined(_MSC_VER) && (_MSC_VER >= 1900) && (_MSC_FULL_VER < 190024210)
90  inline
91 #else
93 #endif
94  bool isEmpty() const
95  {
96  return entries() == 0;
97  }
98  virtual void clear() = 0;
99  virtual void addAll() = 0;
100  virtual bool isOrdered() const = 0;
101  virtual bool isMixed() const = 0;
102 
103  virtual bool combine(const GA_Group * inputGroup);
104 
105  void clearEntries() { clear(); }
106 
107  /// Fill out information about the group. The default method fills does
108  /// the following:
109  /// @code
110  /// info.sprintf("%s::%s", groupType(classType()), getName());
111  /// memory = 0;
112  /// @endcode
113  virtual bool stat(UT_WorkBuffer &info, uint level) const;
114 
115  /// Check to see whether group should be saved or not.
116  /// The default behaviour checks the map options to see if the group should
117  /// be saved (internal groups, specific types, etc.).
118  virtual bool jsonShouldSave(const GA_SaveMap &map) const;
119 
120  /// Each group saves its data in a different format.
121  ///
122  /// @section JSON-GA_Group JSON Schema: GA_Group
123  /// The schema for a group consistes of an array of two entries. The first
124  /// entry contains the definition of the group. The second is "private"
125  /// data for the group.
126  /// @code
127  /// {
128  /// "name" : "GA_Group",
129  /// "description" :
130  /// "A group is stored in an array of two items. The first
131  /// item stores the definition (or run information). The second
132  /// entry stores the private information for the group.",
133  /// "type" : "array",
134  /// "items" : [
135  /// { "$ref" : "GA_Group-Definition" }, // Definition of primitive
136  /// { "$ref" : "GA_Group-Data" }, // Single primitive data
137  /// ],
138  /// }
139  /// @endcode
140  ///
141  /// @section JSON-GA_Group-Definition JSON Schema: GA_Group-Definition
142  /// The group definition stores the information needed to create a group,
143  /// but does not define the data associated with the group.
144  /// @code
145  /// {
146  /// "name" : "GA_Group-Definition",
147  /// "description" : "Definition of a group",
148  /// "type" : "orderedmap",
149  /// "properties":
150  /// {
151  /// "type":
152  /// {
153  /// "type" : "string"
154  /// "description" : "Type of group (i.e. 'point')",
155  /// }
156  /// "name":
157  /// {
158  /// "type" : "string"
159  /// "description" : "Name of group",
160  /// }
161  /// "internal":
162  /// {
163  /// "type" : "boolean"
164  /// "description" : "Internal or externally visible group",
165  /// "optional" : true,
166  /// "default" : false,
167  /// }
168  /// },
169  /// }
170  /// @endcode
171  bool jsonSaveDefinition(UT_JSONWriter &w, const char *type) const;
172 
173  /// Load the GA_Group-Definition
174  static bool jsonLoadDefinition(UT_JSONParser &p,
175  UT_WorkBuffer &type, UT_WorkBuffer &name,
176  bool &internal);
177 
178  /// Save the private group data
179  virtual bool jsonSaveData(UT_JSONWriter &w,
180  const GA_SaveMap &map) const = 0;
181 
182  /// Load the private group data
183  virtual bool jsonLoadData(UT_JSONParser &p,
184  const GA_LoadMap &map) = 0;
185 
186  /// A convenience function to do a JSON dump of the group contents.
187  void dump(std::ostream &os);
188 protected:
189  /// Only called by GA_GroupTable::rename(const char *, const char *).
190  /// Though sub-classes can override the behaviour
191  virtual bool setName(const UT_StringHolder &n)
192  {
193  myName = n;
194  return true;
195  }
196 
197 private:
198  UT_StringHolder myName;
199  unsigned myInternal:1,
200  myType:5,
201  myDetached:1;
202 
203  friend class GA_GroupTable;
204 };
205 #endif
static GA_GroupType groupType(const char *type)
Definition: GA_Group.h:59
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
virtual bool setName(const UT_StringHolder &n)
Definition: GA_Group.h:191
GA_GroupMaskType classMaskType() const
Definition: GA_Group.h:55
GA_API const char * GAgroupType(GA_GroupType owner)
Lookup the owner name from the owner type.
GLint level
Definition: glcorearb.h:107
SYS_FORCE_INLINE bool isEmpty() const
Definition: GA_Group.h:94
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:72
#define GA_API
Definition: GA_API.h:12
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
long long int64
Definition: SYS_Types.h:100
GLdouble n
Definition: glcorearb.h:2007
void setInternal(bool onOff)
Definition: GA_Group.h:46
bool isElementGroup() const
Definition: GA_Group.h:62
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
Options during loading.
Definition: GA_LoadMap.h:42
bool isDetached() const
Definition: GA_Group.h:51
bool isInternal() const
Definition: GA_Group.h:44
GLuint const GLchar * name
Definition: glcorearb.h:785
const UT_StringHolder & getName() const
Definition: GA_Group.h:41
unsigned int uint
Definition: SYS_Types.h:33
GA_GroupType classType(void) const
Definition: GA_Group.h:53
png_infop png_sPLT_tpp entries
Definition: png.h:2481
GA_GroupType
An ordinal enum for the different types of groups in GA.
Definition: GA_Types.h:138
void clearEntries()
Definition: GA_Group.h:105
static const char * groupType(GA_GroupType type)
Definition: GA_Group.h:57
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
Container class for all geometry.
Definition: GA_Detail.h:96
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
GA_GroupMaskType
Definition: GA_Types.h:151
bool getInternal() const
Definition: GA_Group.h:45