Jamoma API  0.6.0.a19
TTAddressBase.h
1 /*
2  * TTAddressBase
3  * Copyright © 2011, Théo de la Hogue
4  *
5  * License: This code is licensed under the terms of the "New BSD License"
6  * http://creativecommons.org/licenses/BSD/
7  */
8 
9 #ifndef __TT_ADDRESS_BASE_H__
10 #define __TT_ADDRESS_BASE_H__
11 
12 //#ifdef WIN_VERSION
13 //#pragma warning(disable:4083) //warning C4083: expected 'newline'; found identifier 's'
14 //#endif // WIN_VERSION
15 
16 #include "TTSymbol.h"
17 
18 class TTRegex;
19 class TTList;
20 
21 #define NO_DIRECTORY kTTSymEmpty
22 #define NO_PARENT kTTAdrsEmpty
23 #define NO_NAME kTTSymEmpty
24 #define NO_INSTANCE kTTSymEmpty
25 #define NO_ATTRIBUTE kTTSymEmpty
26 
27 #define S_DIRECTORY TTSymbol(":/")
28 #define S_SEPARATOR kTTSymSlash
29 #define S_INSTANCE kTTSymDot
30 #define S_ATTRIBUTE kTTSymColon
31 #define S_WILDCARD kTTSymStar
32 #define S_ZERO TTSymbol("0")
33 
34 #define C_SEPARATOR '/'
35 #define C_INSTANCE '.'
36 #define C_ATTRIBUTE ':'
37 #define C_WILDCARD '*'
38 #define C_ZERO '0'
39 
40 
41 /** \ingroup enums
42  Comparison flags between address returned by address1->compare(address2).
43  The comparison function doesn't compare attribute part.
44 */
46  kAddressLower = -1, ///< this flag means that address1 refers to a node at a lower level than address2 in the tree structure
47  kAddressDifferent = 0, ///< this flag means that address1 an address2 refer to nodes which are in a different branch in the tree structure
48  kAddressEqual = 1, ///< this flag means that address1 an address2 refer to the same node in the tree structure
49  kAddressUpper = 2 ///< this flag means that address1 refers to a node at a upper level than address2 in the tree structure
50 };
51 
52 /** \ingroup enums
53  Notification flags to notify observers of a directory.
54 */
56  kAddressDestroyed = 0, ///< this flag means that a TTNode have been destroyed in the tree structure
57  kAddressCreated = 1 ///< this flag means that a TTNode have been created in the tree structure
58 };
59 
60 /** \ingroup enums
61  Type flags to state about absolute or relative address.
62 */
64  kAddressRelative = 0, ///< this flag means that an address have no leading slash
65  kAddressAbsolute = 1, ///< this flag means that an address have a leading slash
66 };
67 
68 extern TTFOUNDATION_EXPORT TTRegex* ttRegexForDirectory; ///< The global regex to parse directory part
69 extern TTFOUNDATION_EXPORT TTRegex* ttRegexForAttribute; ///< The global regex to parse attribute part
70 extern TTFOUNDATION_EXPORT TTRegex* ttRegexForParent; ///< The global regex to parse parent part
71 extern TTFOUNDATION_EXPORT TTRegex* ttRegexForInstance; ///< The global regex to parse instance part
72 
73 /****************************************************************************************************/
74 // Class Specifications
75 
76 /**
77 
78  An address could be
79 
80  directory:/parent/name.instance:attribute
81 
82  */
83 
84 class TTFOUNDATION_EXPORT TTAddressBase : public TTSymbolBase
85 {
86 private:
87 
88  TTSymbol directory; ///< the directory part (optional)
89 
90  TTAddressBase* parent; ///< the parent address pointer (optional)
91 
92  TTSymbol name; ///< the name part
93  TTSymbol instance; ///< the instance part (optional)
94 
95  TTSymbol attribute; ///< the attribute part (optional)
96 
97  TTAddressType type; ///< is the address relative or absolute
98 
99  TTBoolean parsed; ///< is the address has been parsed ?
100 
101  TTAddressBase* normalized; ///< the normalized address (without directory and attribute part
102 
103 public:
104 
105  /** Constructor */
106  TTAddressBase(const TTString& newAddressString, TTPtrSizedInt newAddressTableId, TTInt32 newId);
107 
108  /** Destructor */
109  virtual ~TTAddressBase();
110 
111  /** Get the directory part */
112  TTSymbol& getDirectory();
113 
114  /** Get a pointer to the parent address */
115  TTAddressBase* getParent();
116 
117  /** Get the name part */
118  TTSymbol& getName();
119 
120  /** Get the instance part */
121  TTSymbol& getInstance();
122 
123  /** Get the attribute part */
124  TTSymbol& getAttribute();
125 
126  /** Get the type */
127  TTAddressType getType();
128 
129  /** Get the name.instance part */
130  TTSymbol getNameInstance();
131 
132  /** Normalize an address for lookup and other directory operations
133  This would return an address without directory and attribute */
134  TTAddressBase* normalize();
135 
136  /** Return a new TTAddress without attribute part */
137  TTAddressBase* removeAttribute();
138 
139  /** Return a new TTAddress with attribute part */
140  TTAddressBase* appendAttribute(TTSymbol& anAttribute);
141 
142  /** Return a new TTAddress with the appended part */
143  TTAddressBase* appendAddress(TTAddressBase* toAppend);
144 
145  /** Return a new TTAddress with a instance part */
146  TTAddressBase* appendInstance(const TTSymbol& anInstance);
147 
148  /** Edit address from directory, parent, name, instance and attribute part
149  @return A new TTAddressPtr */
150  TTAddressBase* edit(const TTSymbol& newDirectory, const TTAddressBase* newParent, const TTSymbol& newName, const TTSymbol& newInstance, const TTSymbol& newAttribute);
151 
152  /** A comparison tool
153  @param toCompare An address to compare (it doesn't compare attribute part)
154  @param depthDifference Return the number of level separating the compared addresses (> 0 for lower result, < 0 for upper result)
155  @return An comparison flag */
156  TTAddressComparisonFlag compare(TTAddressBase* toCompare, TTInt8& depthDifference);
157 
158  /** A parsing tool : split address in two part from a given '/' position
159  @param whereToSplit An int to give the '/' id where to split
160  @param returnedPart1 A pointer to upper part (before the given position) : /part1
161  @param returnedPart2 A pointer to lower part (after the given position) : /part2
162  @return kTTValueNotFound if the given '/' id doesn't exist */
163  TTErr splitAt(TTUInt32 whereToSplit, TTAddressBase** returnedPart1, TTAddressBase** returnedPart2);
164 
165  /** A parsing tool : count how many C_SEPARATOR there is in the address
166  @return The number of C_SEPARATOR */
167  TTUInt32 countSeparator();
168 
169  /** A parsing tool : return a list containing all name.instance part (without any S_SEPARATOR)
170  @param The list of name.instance part to fill */
171  TTErr listNameInstance(TTList& nameInstanceList);
172 
173 
174 private:
175 
176  /** Parse the address to get directory, parent, name, instance and attribute part
177  @return An error code if the parsing failed */
178  TTErr parse();
179 
180 };
181 
182 #endif // __TT_ADDRESS_BASE_H__
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
this flag means that a TTNode have been destroyed in the tree structure
Definition: TTAddressBase.h:56
this flag means that address1 an address2 refer to nodes which are in a different branch in the tree ...
Definition: TTAddressBase.h:47
TTAddressNotificationFlag
Notification flags to notify observers of a directory.
Definition: TTAddressBase.h:55
An address could be.
Definition: TTAddressBase.h:84
this flag means that an address have no leading slash
Definition: TTAddressBase.h:64
TTAddressType
Type flags to state about absolute or relative address.
Definition: TTAddressBase.h:63
The TTSymbolBase class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbolBase.h:28
this flag means that address1 an address2 refer to the same node in the tree structure ...
Definition: TTAddressBase.h:48
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
this flag means that an address have a leading slash
Definition: TTAddressBase.h:65
this flag means that address1 refers to a node at a lower level than address2 in the tree structure ...
Definition: TTAddressBase.h:46
std::int32_t TTInt32
32 bit signed integer
Definition: TTBase.h:177
TTAddressComparisonFlag
Comparison flags between address returned by address1->compare(address2).
Definition: TTAddressBase.h:45
this flag means that address1 refers to a node at a upper level than address2 in the tree structure ...
Definition: TTAddressBase.h:49
long TTPtrSizedInt
An integer that is the same size as a pointer.
Definition: TTBase.h:240
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
signed char TTInt8
8 bit signed integer (char)
Definition: TTBase.h:173
this flag means that a TTNode have been created in the tree structure
Definition: TTAddressBase.h:57
std::uint32_t TTUInt32
32 bit unsigned integer
Definition: TTBase.h:178
The TTString class is used to represent a string.
Definition: TTString.h:34