TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::Any::Data Class Reference

Classes

union  Value
 

Static Public Member Functions

static Datacreate (const Data *d)
 
static Datacreate (Type t, const char *b=NULL, char s= '\0')
 
static void destroy (Data *d)
 

Public Attributes

Type type
 
Value value
 
std::string comment
 
std::string name
 
std::string includeLine
 
AtomicInt32 referenceCount
 
Source source
 
const char * bracket
 
char separator
 

Private Member Functions

 Data (Type t, const char *b, char s)
 
 ~Data ()
 

Constructor & Destructor Documentation

G3D::Any::Data::Data ( Type  t,
const char *  b,
char  s 
)
inlineprivate

Called by create()

280 : type(t), referenceCount(1), bracket(b), separator(s) {}
AtomicInt32 referenceCount
Definition: Any.h:267
const char * bracket
Definition: Any.h:272
Type type
Definition: Any.h:242
char separator
Definition: Any.h:275
G3D::Any::Data::~Data ( )
private

Called by destroy

282  {
283  debugAssertM(referenceCount.value() <= 0, "Deleted while still referenced.");
284 
285  // Destruct but do not deallocate children
286  switch (type) {
287  case STRING:
288  debugAssert(value.s != NULL);
289  value.s->~basic_string();
290  break;
291 
292  case ARRAY:
293  debugAssert(value.a != NULL);
294  value.a->~Array();
295  break;
296 
297  case TABLE:
298  debugAssert(value.t != NULL);
299  value.t->~Table();
300  break;
301 
302  default:
303  // All other types should have a NULL value pointer (i.e., they were used just for name and comment fields)
304  debugAssertM(value.s == NULL, "Corrupt Any::Data::Value");
305  }
306 
307  value.s = NULL;
308 }
Definition: Any.h:187
AtomicInt32 referenceCount
Definition: Any.h:267
Value value
Definition: Any.h:246
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: Any.h:187
AnyTable * t
Definition: Any.h:236
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
virtual ~Table()
Definition: Table.h:331
#define debugAssert(exp)
Definition: debugAssert.h:160
Type type
Definition: Any.h:242
Array< Any > * a
Definition: Any.h:235
int32 value() const
Definition: AtomicInt32.h:67
std::string * s
Definition: Any.h:234
Definition: Any.h:187

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Function Documentation

Any::Data * G3D::Any::Data::create ( const Data d)
static

Clones the argument

169  {
170  Data* p = create(d->type);
171 
172  p->includeLine = d->includeLine;
173  p->bracket = d->bracket;
174  p->separator = d->separator;
175  p->comment = d->comment;
176  p->name = d->name;
177  p->source = d->source;
178 
179  switch (d->type) {
180  case NIL:
181  case BOOLEAN:
182  case NUMBER:
183  case EMPTY_CONTAINER:
184  // No clone needed
185  break;
186 
187  case STRING:
188  *(p->value.s) = *(d->value.s);
189  break;
190 
191  case ARRAY:
192  *(p->value.a) = *(d->value.a);
193  break;
194 
195  case TABLE:
196  *(p->value.t) = *(d->value.t);
197  // Note that placeholders may be copied; that is ok--they are still
198  // just placeholders.
199  break;
200  }
201 
202  return p;
203 }
Definition: Any.h:187
Definition: Any.h:187
Definition: Any.h:187
Definition: Any.h:187
static Data * create(const Data *d)
Definition: Any.cpp:169
Definition: Any.h:187
Definition: Any.h:187
Definition: Any.h:187
Data
Definition: molten_core.h:69

+ Here is the caller graph for this function:

Any::Data * G3D::Any::Data::create ( Any::Type  t,
const char *  b = NULL,
char  s = '\0' 
)
static
206  {
207  size_t s = sizeof(Data);
208 
209  switch (t) {
210  case NIL:
211  case BOOLEAN:
212  case NUMBER:
213  // No extra space needed
214  break;
215 
216  case STRING:
217  s += sizeof(std::string);
218  break;
219 
220  case EMPTY_CONTAINER:
221  // We need to allocate space for the worst-case
222  s += max(sizeof(AnyArray), sizeof(AnyTable));
223  // If no separator and brackets were provided, substitute defaults
224  if (b == NULL) { b = PAREN; }
225  if (sep == '\0') { sep = ','; }
226  break;
227 
228  case ARRAY:
229  s += sizeof(AnyArray);
230  // If no separator and brackets were provided, substitute defaults
231  if (b == NULL) { b = PAREN; }
232  if (sep == '\0') { sep = ','; }
233  break;
234 
235  case TABLE:
236  s += sizeof(AnyTable);
237  // If no separator and brackets were provided, substitute defaults
238  if (b == NULL) { b = BRACE; }
239  if (sep == '\0') { sep = ';'; }
240  break;
241  }
242 
243  // Allocate the data object
244  Data* p = new (MemoryManager::create()->alloc(s)) Data(t, b, sep);
245 
246  // Create the (empty) value object at the end of the Data object
247  switch (t) {
248  case NIL:
249  case BOOLEAN:
250  case NUMBER:
251  case EMPTY_CONTAINER:
252  // No value
253  break;
254 
255  case STRING:
256  p->value.s = new (p + 1) std::string();
257  break;
258 
259  case ARRAY:
260  p->value.a = new (p + 1) AnyArray();
261  break;
262 
263  case TABLE:
264  p->value.t = new (p + 1) AnyTable();
265  break;
266  }
267 
268  if (isContainerType(p->type)) debugAssert(p->separator != '\0');
269 
270  return p;
271 }
Definition: Any.h:187
static MemoryManager::Ref create()
Definition: MemoryManager.cpp:35
static bool isContainerType(Any::Type &t)
Definition: Any.cpp:30
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: Any.h:187
Table< std::string, Any > AnyTable
Definition: Any.h:208
T max(const T &x, const T &y)
Definition: g3dmath.h:320
Array< Any > AnyArray
Definition: Any.h:207
Definition: Any.h:187
#define debugAssert(exp)
Definition: debugAssert.h:160
Definition: Any.h:187
Definition: Any.h:187
Definition: Any.h:187
static const char * BRACE
Definition: Any.h:228
Definition: Any.h:187
static const char * PAREN
Definition: Any.h:226
Data(Type t, const char *b, char s)
Definition: Any.h:280
Data
Definition: molten_core.h:69

+ Here is the call graph for this function:

void G3D::Any::Data::destroy ( Data d)
static

Free d, invoking its destructor and freeing the memory for the value.

274  {
275  if (d != NULL) {
276  d->~Data();
277  MemoryManager::create()->free(d);
278  }
279 }
static MemoryManager::Ref create()
Definition: MemoryManager.cpp:35
arena_t NULL
Definition: jemalloc_internal.h:624

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

const char* G3D::Any::Data::bracket

Two-character string of "{}", "[]", or "()"; to be used when unparsing.

std::string G3D::Any::Data::comment
std::string G3D::Any::Data::includeLine

If this Any was created by parsing an #include expression and has not been modified since, this is the original comment and include statement, as it originally appeared in the file (e.g., it may contain a relative filename). If this is non-empty, then when serialized, this Any will turn into an #include expression instead of unparsing its contents of the any.

std::string G3D::Any::Data::name
AtomicInt32 G3D::Any::Data::referenceCount

For STRING, ARRAY and TABLE types, m_value is shared between multiple instances. Mutation is allowed only if the reference count is exactly 1, otherwise the mutating instance must copy the value. This is not used for other types.

char G3D::Any::Data::separator

';' or ',' separator to be used when unparsing

Source G3D::Any::Data::source
Type G3D::Any::Data::type
Value G3D::Any::Data::value

Always points to memory that is allocated with the Data, so the destructor does not delete this.


The documentation for this class was generated from the following files: