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