9 #ifndef DISABLE_NODELIB
11 #include "TTFoundationAPI.h"
14 #include <boost/regex.hpp>
15 using namespace boost;
21 TTFOUNDATION_EXPORT TTRegex* ttRegexForDirectory = NULL;
22 TTFOUNDATION_EXPORT TTRegex* ttRegexForAttribute = NULL;
23 TTFOUNDATION_EXPORT TTRegex* ttRegexForParent = NULL;
24 TTFOUNDATION_EXPORT TTRegex* ttRegexForInstance = NULL;
27 TTSymbolBase(newAddressString, newAddressTableId, newId),
28 directory(NO_DIRECTORY),
29 parent(NO_PARENT.getBasePointer()),
31 instance(NO_INSTANCE),
32 attribute(NO_ATTRIBUTE),
35 this->
init(newAddressString, newAddressTableId, newId);
75 return this->attribute;
91 nameInstance += C_INSTANCE;
103 return this->normalized;
111 if (attribute != NO_ATTRIBUTE)
112 return edit(this->directory, this->parent, this->name, this->instance, NO_ATTRIBUTE);
122 return edit(this->directory, this->parent, this->name, this->instance, anAttribute);
127 if (*toAppend == kTTAdrsEmpty || *toAppend == kTTAdrsRoot)
130 else if (
this == kTTAdrsEmpty)
156 return edit(this->directory, this->parent, this->name, anInstance, this->attribute);
168 if (newDirectory != NO_DIRECTORY) {
169 address = newDirectory.
c_str();
173 if (newParent != NO_PARENT.getBasePointer()) {
174 if (newDirectory == NO_DIRECTORY)
175 address = newParent->normalized->
getCString();
177 address += newParent->normalized->
getCString();
180 if(newName != NO_NAME){
181 if((newName != S_SEPARATOR) && (newParent != kTTAdrsRoot.getBasePointer()))
182 if (newDirectory != NO_DIRECTORY || newParent != NO_PARENT.getBasePointer())
183 address += S_SEPARATOR.c_str();
184 address += newName.
c_str();
187 if (newInstance != NO_INSTANCE) {
188 address += S_INSTANCE.c_str();
189 address += newInstance.
c_str();
192 if(newAttribute != NO_ATTRIBUTE){
193 address += S_ATTRIBUTE.c_str();
194 address += newAttribute.
c_str();
200 TTErr TTAddressBase::parse()
205 if (*
this == *kTTAdrsEmpty.getBasePointer()) {
206 this->directory = NO_DIRECTORY;
207 this->parent = NO_PARENT.getBasePointer();
208 this->name = NO_NAME;
209 this->instance = NO_INSTANCE;
210 this->attribute = NO_ATTRIBUTE;
213 this->normalized =
this;
218 if (*
this == *kTTAdrsRoot.getBasePointer()) {
219 this->directory = NO_DIRECTORY;
220 this->parent = NO_PARENT.getBasePointer();
221 this->name = S_SEPARATOR;
222 this->instance = NO_INSTANCE;
223 this->attribute = NO_ATTRIBUTE;
226 this->normalized =
this;
247 TTLogError(
"TTAddressBase::parse : special regex characters have been detected in %s address\n", s_toParse.data());
251 if (!ttRegexForDirectory->parse(s_toParse.begin(), s_toParse.end()))
253 s_directory =
TTString(ttRegexForDirectory->begin(), ttRegexForDirectory->end());
254 s_toParse.erase(ttRegexForDirectory->begin(), ttRegexForDirectory->end()+1);
257 if (s_toParse[0] == C_SEPARATOR && s_toParse[1] ==
'\0')
259 this->directory =
TTSymbol(s_directory);
260 this->parent = NO_PARENT.getBasePointer();
261 this->name = S_SEPARATOR;
262 this->instance = NO_INSTANCE;
263 this->attribute = NO_ATTRIBUTE;
266 this->normalized = kTTAdrsRoot.getBasePointer();
270 this->directory =
TTSymbol(s_directory);
273 if (!ttRegexForAttribute->parse(s_toParse.begin(), s_toParse.end()))
275 s_attribute =
TTString(ttRegexForAttribute->end(), s_toParse.end());
276 s_toParse.erase(ttRegexForAttribute->begin(), s_toParse.end()-1);
278 this->attribute =
TTSymbol(s_attribute);
281 if (!ttRegexForParent->parse(s_toParse.begin(), s_toParse.end()))
284 if (ttRegexForParent->begin() == ttRegexForParent->end())
285 s_parent += C_SEPARATOR;
288 else if (this->directory != kTTSymEmpty)
290 s_parent = s_directory;
292 s_parent +=
TTString(ttRegexForParent->begin(), ttRegexForParent->end());
296 s_parent +=
TTString(ttRegexForParent->begin(), ttRegexForParent->end());
298 s_toParse.erase(ttRegexForParent->begin(), ttRegexForParent->end()+1);
303 if (!ttRegexForInstance->parse(s_toParse.begin(), s_toParse.end()))
305 s_instance =
TTString(ttRegexForInstance->end(), s_toParse.end()-1);
306 s_toParse.erase(ttRegexForInstance->begin(), s_toParse.end()-1);
308 this->instance =
TTSymbol(s_instance);
314 if (*this->parent != *NO_PARENT.getBasePointer())
315 this->type = this->parent->
getType();
317 this->type = (
TTAddressType)(this->directory != NO_DIRECTORY || this->name == S_SEPARATOR);
320 this->normalized =
edit(NO_DIRECTORY, this->parent, this->name, this->instance, NO_ATTRIBUTE);
337 bool cParent, cName, cInstance;
342 if (adrs1 == adrs2) {
348 else if (adrs1 == kTTAdrsRoot) {
356 else if (adrs2 == kTTAdrsRoot) {
366 err1 = adrs1->
splitAt(0, &top1, &rest1);
367 err2 = adrs2->
splitAt(0, &top2, &rest2);
370 while ((top1 == top2) && (err1 == 0) && (err2 == 0))
372 err1 = rest1->
splitAt(0, &top1, &rest1);
373 err2 = rest2->
splitAt(0, &top2, &rest2);
400 if (cParent && cName && cInstance ){
407 else if (!err1 && err2) {
413 return rest1->
compare(rest2, depthDifference);
431 while(i <= whereToSplit)
433 nb = std::count(part2.begin(), part2.end(), C_SEPARATOR);
438 part1 += part2.
substr(0, pos+1);
439 part2 = part2.
substr(pos+1, part2.
size() - (pos+1));
454 if (part1.at(part1.
size()-1) == C_SEPARATOR) {
458 if (sc > 0 && sc != part1.
size()-2)
473 return count(toCount.begin(), toCount.end(), C_SEPARATOR);
478 if (!parsed) parse();
480 if (*
this != kTTAdrsEmpty && *
this != kTTAdrsRoot) {
485 if (directory != NO_DIRECTORY) {
487 if (this->parent == kTTAdrsRoot) {
488 nameInstanceList.append(directory);
489 nameInstanceList.append(kTTSymEmpty);
492 else if (this->parent == NO_PARENT && this->name == S_SEPARATOR) {
493 nameInstanceList.append(directory);
494 nameInstanceList.append(kTTSymEmpty);
499 nameInstanceList.append(name);
500 nameInstanceList.append(instance);
TTAddressBase * appendInstance(const TTSymbol &anInstance)
Return a new TTAddress with a instance part.
TTSymbol & getDirectory()
Get the directory part.
this flag means that address1 an address2 refer to nodes which are in a different branch in the tree ...
TTErr listNameInstance(TTList &nameInstanceList)
A parsing tool : return a list containing all name.instance part (without any S_SEPARATOR) ...
TTAddressComparisonFlag compare(TTAddressBase *toCompare, TTInt8 &depthDifference)
A comparison tool.
TTSymbolBase * lookup(const char *aString)
Look in the symbol table for this string.
TTAddressType getType()
Get the type.
TTSymbol getNameInstance()
Get the name.instance part.
this flag means that an address have no leading slash
TTSymbol & getAttribute()
Get the attribute part.
TTAddressType
Type flags to state about absolute or relative address.
The TTSymbolBase class is used to represent a string and efficiently pass and compare that string...
TTAddressBase * appendAddress(TTAddressBase *toAppend)
Return a new TTAddress with the appended part.
TTAddressBase(const TTString &newAddressString, TTPtrSizedInt newAddressTableId, TTInt32 newId)
Constructor.
const char * getCString() const
Return a pointer to the internal string as a C-string.
this flag means that address1 an address2 refer to the same node in the tree structure ...
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
void TTFOUNDATION_EXPORT TTLogError(TTImmutableCString message,...)
Platform and host independent method for posting errors.
TTUInt32 countSeparator()
A parsing tool : count how many C_SEPARATOR there is in the address.
void init(const TTString &newString, TTPtrSizedInt newSymbolTableId, TTInt32 newSymbolId)
used by the constructors to create the new symbol
TTAddressBase * removeAttribute()
Return a new TTAddress without attribute part.
TTErr splitAt(TTUInt32 whereToSplit, TTAddressBase **returnedPart1, TTAddressBase **returnedPart2)
A parsing tool : split address in two part from a given '/' position.
this flag means that an address have a leading slash
this flag means that address1 refers to a node at a lower level than address2 in the tree structure ...
TTAddressBase * normalize()
Normalize an address for lookup and other directory operations This would return an address without d...
TTString substr(size_t pos=0, size_t n=1) const
Returns a string object with its contents initialized to a substring of the current object...
const char * c_str() const
Return a pointer to the internal string as a C-string.
std::int32_t TTInt32
32 bit signed integer
TTSymbol & getInstance()
Get the instance part.
TTSymbol & getName()
Get the name part.
TTAddressComparisonFlag
Comparison flags between address returned by address1->compare(address2).
this flag means that address1 refers to a node at a upper level than address2 in the tree structure ...
long TTPtrSizedInt
An integer that is the same size as a pointer.
Something went wrong, but what exactly is not known. Typically used for context-specific problems...
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
TTAddressBase * appendAttribute(TTSymbol &anAttribute)
Return a new TTAddress with attribute part.
signed char TTInt8
8 bit signed integer (char)
std::uint32_t TTUInt32
32 bit unsigned integer
size_t size() const
Find out the length of a string.
TTAddressBase * getParent()
Get a pointer to the parent address.
size_t find_first_of(const char aChar, size_t from=0)
Return the index of the first instance of a specified char in the string.
virtual ~TTAddressBase()
Destructor.
The TTString class is used to represent a string.
TTAddressBase * edit(const TTSymbol &newDirectory, const TTAddressBase *newParent, const TTSymbol &newName, const TTSymbol &newInstance, const TTSymbol &newAttribute)
Edit address from directory, parent, name, instance and attribute part.