Jamoma API  0.6.0.a19
TTValue.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup foundationLibrary
4  *
5  * @brief Jamoma Foundation class for representing values
6  *
7  * @details
8  *
9  * @author Tim Place, Théo de la Hogue, Nathan Wolek, Julien Rabin, Nils Peters, Trond Lossius
10  *
11  * @copyright Copyright © 2008, Timothy Place @n
12  * This code is licensed under the terms of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 
17 #include "TTValue.h"
18 #include "TTSymbolTable.h"
19 #include "TTObject.h"
20 #include "TTMatrixBase.h"
21 #include "TTDictionary.h"
22 
23 
24 /****************************************************************************************************/
25 // clear
26 /****************************************************************************************************/
27 
28 #ifdef REVIEW_THIS_BECAUSE_HOW_ARE_WE_DEALING_WITH_STRING_MEM_NOW
29 void TTValue::clear()
30 {
31  if (stringsPresent) {
32  for (TTUInt16 i=0; i<numValues; i++) {
33  if (type[i] == kTypeString)
34  delete data[i].stringPtr;
35  }
36  stringsPresent = false;
37  }
38  delete [] data;
39  delete [] type;
40 
41  init();
42  data->float64 = 0.0;
43  *type = kTypeNone;
44  numValues = 0; // Important: We want TTValue to contain zero values so we can build an array dynamically with the append() method [TAP]
45 }
46 #endif
47 
48 
49 TTElement::~TTElement()
50 {
51  chuck();
52 }
53 
54 
55 TTElement::operator TTDictionary() const
56 {
57  if (mType == kTypeDictionary) {
58  TTBoolean unused;
59  return TTDictionary(TT(mValue.dictionary), unused);
60  }
61  else
62  return TTDictionary();
63  // TODO: should this throw an exception?
64  // otherwise how does the caller know that the empty dictionary is an error?
65 }
66 
67 
68 // The equals operator should assign an existing dictionary, not copy it.
69 
70 TTElement& TTElement::operator = (const TTDictionary value)
71 {
72  chuck();
73 
74  TTBoolean unused;
75 
76  if (mType != kTypeDictionary) {
77  TTDictionary *newDictionary = new TTDictionary(value.name(), unused);
78  mValue.dictionary = (TTSymbolBase*)newDictionary->name().rawpointer();
79  mType = kTypeDictionary;
80  }
81  else {
82  TTDictionary thisDictionary(TT(mValue.dictionary), unused);
83  thisDictionary = value;
84  }
85 
86  return *this;
87 }
88 
2-dimensional matrix of compound values with N elements each.
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
Create Jamoma object instances.
TTSymbol name() const
Return the name associated with the dictionary.
Definition: TTDictionary.h:131
Dictionary type.
Definition: TTBase.h:288
The TTSymbolBase class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbolBase.h:28
Foundation Dictionary Class.
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
A type that represents the key as a C-String and the value as a pointer to the matching TTSymbol obje...
Definition: TTDictionary.h:47
TTPtr rawpointer() const
Get the value of the raw pointer into the symbol table.
Definition: TTSymbol.h:134
Individual items found in a TTValue.
Definition: TTElement.h:89
void clear()
Clear all values from the vector, leaving with size of 0.
Definition: TTValue.h:131
Provides a common way of representing composite values.
String type.
Definition: TTBase.h:285