HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 
86  bool isEmpty() const
87  {
88  return entries() == 0;
89  }
90  virtual void clear() = 0;
91  virtual void addAll() = 0;
92  virtual bool isOrdered() const = 0;
93  virtual bool isMixed() const = 0;
94 
95  virtual bool combine(const GA_Group * inputGroup);
96 
97  void clearEntries() { clear(); }
98 
99  /// Fill out information about the group. The default method fills does
100  /// the following:
101  /// @code
102  /// info.sprintf("%s::%s", groupType(classType()), getName());
103  /// memory = 0;
104  /// @endcode
105  virtual bool stat(UT_WorkBuffer &info, uint level) const;
106 
107  /// Check to see whether group should be saved or not.
108  /// The default behaviour checks the map options to see if the group should
109  /// be saved (internal groups, specific types, etc.).
110  virtual bool jsonShouldSave(const GA_SaveMap &map) const;
111 
112  /// Each group saves its data in a different format.
113  ///
114  /// @section JSON-GA_Group JSON Schema: GA_Group
115  /// The schema for a group consistes of an array of two entries. The first
116  /// entry contains the definition of the group. The second is "private"
117  /// data for the group.
118  /// @code
119  /// {
120  /// "name" : "GA_Group",
121  /// "description" :
122  /// "A group is stored in an array of two items. The first
123  /// item stores the definition (or run information). The second
124  /// entry stores the private information for the group.",
125  /// "type" : "array",
126  /// "items" : [
127  /// { "$ref" : "GA_Group-Definition" }, // Definition of primitive
128  /// { "$ref" : "GA_Group-Data" }, // Single primitive data
129  /// ],
130  /// }
131  /// @endcode
132  ///
133  /// @section JSON-GA_Group-Definition JSON Schema: GA_Group-Definition
134  /// The group definition stores the information needed to create a group,
135  /// but does not define the data associated with the group.
136  /// @code
137  /// {
138  /// "name" : "GA_Group-Definition",
139  /// "description" : "Definition of a group",
140  /// "type" : "orderedmap",
141  /// "properties":
142  /// {
143  /// "type":
144  /// {
145  /// "type" : "string"
146  /// "description" : "Type of group (i.e. 'point')",
147  /// }
148  /// "name":
149  /// {
150  /// "type" : "string"
151  /// "description" : "Name of group",
152  /// }
153  /// "internal":
154  /// {
155  /// "type" : "boolean"
156  /// "description" : "Internal or externally visible group",
157  /// "optional" : true,
158  /// "default" : false,
159  /// }
160  /// },
161  /// }
162  /// @endcode
163  bool jsonSaveDefinition(UT_JSONWriter &w, const char *type) const;
164 
165  /// Load the GA_Group-Definition
166  static bool jsonLoadDefinition(UT_JSONParser &p,
167  UT_WorkBuffer &type, UT_WorkBuffer &name,
168  bool &internal);
169 
170  /// Save the private group data
171  virtual bool jsonSaveData(UT_JSONWriter &w,
172  const GA_SaveMap &map) const = 0;
173 
174  /// Load the private group data
175  virtual bool jsonLoadData(UT_JSONParser &p,
176  const GA_LoadMap &map) = 0;
177 
178  /// A convenience function to do a JSON dump of the group contents.
179  void dump(std::ostream &os);
180 protected:
181  /// Only called by GA_GroupTable::rename(const char *, const char *).
182  /// Though sub-classes can override the behaviour
183  virtual bool setName(const UT_StringHolder &n)
184  {
185  myName = n;
186  return true;
187  }
188 
189 private:
190  UT_StringHolder myName;
191  unsigned myInternal:1,
192  myType:5,
193  myDetached:1;
194 
195  friend class GA_GroupTable;
196 };
197 #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:183
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:86
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:75
#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:107
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:40
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:97
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:95
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
GA_GroupMaskType
Definition: GA_Types.h:151
bool getInternal() const
Definition: GA_Group.h:45