#include <WOscContainer.h>
Inherits WOscPatternMatch.
Public Member Functions | |
WOscContainer (const WOscContainerInfo &info=WOscContainerInfo("root container"), int defNumChildren=32, int defNumMethods=32) | |
WOscContainer (WOscContainer *parent, const char *name, const WOscContainerInfo &info=WOscContainerInfo(), int defNumChildren=32, int defNumMethods=32) | |
void | AddContainerAlias (WOscContainer *parent, const char *alias) |
void | DispatchMessage (WOscCallbackList &methods, WOscMessage *msg) |
WOscString | GetName () const |
WOscString | GetAddress () const |
WOscString | GetAddressSpace () const |
WOscString | GetMethodList () const |
const WOscContainer * | FindContainer (const char *address) const |
bool | RemoveContainer (const char *name) |
bool | RemoveMethod (const char *name) |
const WOscContainer * | FindRoot () const |
bool | IsRoot () const |
void | RemoveAll () |
Friends | |
class | WOscMethod |
OSC Address-space node. An OSC-address space consists of a tree of containers with methods as leaves.
WOscClient.cpp, WOscServer.cpp, WOscStreamingClient.cpp, and WOscStreamingServer.cpp.
Definition at line 104 of file WOscContainer.h.
WOscContainer::WOscContainer | ( | const WOscContainerInfo & | info = WOscContainerInfo("root container") , |
|
int | defNumChildren = 32 , |
|||
int | defNumMethods = 32 | |||
) |
Constructor for a root container. Root container do not have parents (what's implicated by the name). The root-container is responsible for clean-up. Deletion is not allowed for WOscContainer and WOscMethod objects. The address space can be removed only as whole or be manipulated by dedicated functions.
info | Container information. | |
defNumChildren | Default internal array-size for children-references. If not sufficient during later use, the array-sizes double themselves automatically. | |
defNumMethods | See parameter defNumChildren. |
Definition at line 67 of file WOscContainer.cpp.
WOscContainer::WOscContainer | ( | WOscContainer * | parent, | |
const char * | name, | |||
const WOscContainerInfo & | info = WOscContainerInfo() , |
|||
int | defNumChildren = 32 , |
|||
int | defNumMethods = 32 | |||
) |
Constructor for child containers. Child containers must supply a parent. They get added to the parent-container list of children and can be parents if constructed.
info | Container information. | |
parent | Pointer to the parent-container. Must not be NULL. | |
name | OSC-pattern with the name of the container. This name will be later a part of the OSC-address (/the/"name"/of/mama/mia/is/method ...). If WOSC_ADDR_WILDCARDS is defined 1, wildcard matching will be performed on the address path segments. | |
defNumChildren | (Optional) See WOscContainer::WOscContainer(WOscContainerInfo* info, int defNumChildren, int defNumMethods) | |
defNumMethods | (Optional) See WOscContainer::WOscContainer(WOscContainerInfo* info, int defNumChildren, int defNumMethods) |
WOscException | If parent pointer NULL. That's illegal. Children should have parents |
Definition at line 108 of file WOscContainer.cpp.
References ERR_PARENT_POINTER_NULL.
00108 { 00109 00110 if ( parent == NULL ) 00111 throw WOscException(ERR_PARENT_POINTER_NULL, __FILE__, __LINE__); 00112 00113 m_parent = parent; 00114 m_info = info; 00115 00116 m_containerEntries.reserve(defNumChildren); 00117 m_methodEntries.reserve(defNumMethods); 00118 00119 m_parent->AddContainer(this, name, false); 00120 }
void WOscContainer::AddContainerAlias | ( | WOscContainer * | parent, | |
const char * | alias | |||
) |
Adds an alias of this container to the parent list-of-children.
parent | Pointer to container, which becomes the parent of the alias. | |
alias | New name of container under which the parent saves the alias. |
WOscException | When this container is the root-container, the root-container can not be aliased. When the parent pointer is this container itself. When invalid parent-container pointer (NULL) is passed. |
Definition at line 191 of file WOscContainer.cpp.
References ERR_PARENT_POINTER_NULL, and ERR_RECURSIVE_ALIAS.
00192 { 00193 if ( m_parent == NULL ) 00194 throw WOscException(ERR_ROOT_ALIAS, __FILE__, __LINE__); 00195 00196 if ( parent == this ) 00197 throw WOscException(ERR_RECURSIVE_ALIAS, __FILE__, __LINE__); 00198 00199 if ( parent == NULL ) 00200 throw WOscException(ERR_PARENT_POINTER_NULL, __FILE__, __LINE__); 00201 00202 parent->AddContainer(this, alias, true); 00203 }
void WOscContainer::DispatchMessage | ( | WOscCallbackList & | methods, | |
WOscMessage * | msg | |||
) |
Creates a list of methods which match the address of the message passed as argument. Those lists reflect the effect of an OSC-message. The list can then be used to invoke all matching methods.
msg | Message to be scanned for. |
WOscException | When dispatching is not executed from a root container. (can be removed by first searching for root. discussion?). |
Definition at line 361 of file WOscContainer.cpp.
References ERR_INVALID_ADDRESS_NO_SLASH, ERR_NOT_DISPATCHING_FROM_ROOT, WOscString::GetBuffer(), and WOscMessage::GetOscAddress().
00362 { 00363 if ( m_parent != NULL ) 00364 throw WOscException(ERR_NOT_DISPATCHING_FROM_ROOT, __FILE__, __LINE__); 00365 00366 const char* pattern = msg->GetOscAddress().GetBuffer(); 00367 00368 if ( pattern == NULL || pattern[0] != '/') 00369 throw WOscException(ERR_INVALID_ADDRESS_NO_SLASH, __FILE__, __LINE__); 00370 00371 // dispatch address pattern (note: leading slash removed!) 00372 DispatchSubMessage(methods, pattern+1); 00373 }
const WOscContainer * WOscContainer::FindContainer | ( | const char * | address | ) | const |
Tries to find a certain container by its OSC-address. Not pattern but address (/hello/world/whats/up).
address | String containing OSC-address to be searched for. |
Definition at line 270 of file WOscContainer.cpp.
References WOscPatternMatch::NextSlashOrNull().
00271 { 00272 unsigned int addrlen = strlen(address); 00273 00274 if ( addrlen == 0 ) // no address 00275 return NULL; 00276 if ( address[0] != '/' ) // invalid address 00277 return NULL; 00278 if ( addrlen == 1 && *address == '/' ) // root container "/" 00279 return this; 00280 00281 // find next slash (if any) 00282 const char* next = NextSlashOrNull(address+1); 00283 00284 if ( *next == 0 ) { 00285 // leaf 00286 for (int i = m_containerEntries.size()-1; i >= 0; i-- ) 00287 if ( m_containerEntries[i].m_name == (address+1) ) 00288 return m_containerEntries[i].m_container; 00289 } else { 00290 // not a leaf. just compare node name 00291 unsigned int thisNodeStrLen = next-address; 00292 for ( int i = m_containerEntries.size()-1; i >= 0; i-- ) { 00293 if ( strncmp(m_containerEntries[i].m_name.c_str(), address+1, thisNodeStrLen) == 0 ) { 00294 const WOscContainer* ctnr = m_containerEntries[i].m_container->FindContainer(next); 00295 if ( ctnr ) 00296 return ctnr; 00297 } 00298 } 00299 } 00300 00301 return NULL; 00302 }
const WOscContainer * WOscContainer::FindRoot | ( | ) | const |
Traverses the container-tree upwards until root is reached.
Definition at line 525 of file WOscContainer.cpp.
Referenced by WOscMethod::GetAddressSpace(), GetAddressSpace(), and RemoveAll().
00526 { 00527 00528 const WOscContainer* momentaryParent = m_parent; 00529 const WOscContainer* lastParent = this; 00530 00531 /* traverse tree upwards until root is reached */ 00532 while ( momentaryParent != NULL ){ 00533 lastParent = momentaryParent; 00534 momentaryParent = momentaryParent->m_parent; 00535 } 00536 return lastParent; 00537 }
WOscString WOscContainer::GetAddress | ( | ) | const |
Traverses the container-tree upwards until root is reached and assembles its unaliased address.
Definition at line 449 of file WOscContainer.cpp.
References GetName().
Referenced by GetMethodList().
00450 { 00451 00452 if ( m_parent == NULL) 00453 return WOscString("/"); 00454 00455 WOscContainer* momentaryParent = m_parent; 00456 WOscString address = GetName(); 00457 address += '/'; 00458 00459 /* traverse tree upwards until root is reached */ 00460 while ( momentaryParent != NULL ) { 00461 address = momentaryParent->GetName() + address; 00462 momentaryParent = momentaryParent->m_parent; 00463 } 00464 00465 return address; 00466 }
WOscString WOscContainer::GetAddressSpace | ( | ) | const |
Returns a line-break('\n')-separated list of all OSC-addresses of methods as seen from root.
Definition at line 479 of file WOscContainer.cpp.
References FindRoot(), and GetMethodList().
00480 { 00481 const WOscContainer* root = FindRoot(); 00482 return root->GetMethodList(); 00483 }
WOscString WOscContainer::GetMethodList | ( | ) | const |
Scans for all local methods and aliased methods.
Definition at line 492 of file WOscContainer.cpp.
References GetAddress().
Referenced by WOscMethod::GetAddressSpace(), and GetAddressSpace().
00493 { 00494 WOscString methodList; 00495 00496 // scan for local methods 00497 for ( int m = m_methodEntries.size()-1; m >= 0; m-- ){ 00498 if ( m_methodEntries[m].m_isAlias ) { 00499 methodList += GetAddress(); 00500 methodList += m_methodEntries[m].m_name.c_str(); 00501 } else { 00502 methodList += m_methodEntries[m].m_method->GetAddress(); 00503 } 00504 methodList += '\n'; 00505 } 00506 00507 // scan children containers 00508 for ( int c = m_containerEntries.size()-1; c >= 0; c-- ) { 00509 if ( m_containerEntries[c].m_isAlias ) { 00510 /** \todo Does not handle aliased containers !!!! */ 00511 } else { 00512 methodList += m_containerEntries[c].m_container->GetMethodList(); 00513 } 00514 } 00515 00516 return methodList; 00517 }
WOscString WOscContainer::GetName | ( | ) | const |
Returns the not aliased name (OSC-pattern, not address) of this container.
Definition at line 424 of file WOscContainer.cpp.
Referenced by WOscMethod::GetAddress(), and GetAddress().
00425 { 00426 if ( m_parent != NULL ) { 00427 /* search all children of parent for not aliased name */ 00428 const std::vector<WOscContainerEntry>& entries = m_parent->m_containerEntries; 00429 for ( int i = entries.size()-1; i >= 0; i-- ) 00430 if ( (entries[i].m_container == this) && (!(entries[i].m_isAlias))){ 00431 return WOscString(entries[i].m_name.c_str()); 00432 break; 00433 } 00434 } 00435 return WOscString("/"); 00436 }
bool WOscContainer::IsRoot | ( | ) | const |
Checks if the current container is the root-container.
Definition at line 545 of file WOscContainer.cpp.
Referenced by WOscReceiver::SetAddressSpace().
void WOscContainer::RemoveAll | ( | ) |
Public function for deletion of a whole container-/method-tree. Searches the root and starts a recursive deletion.
Definition at line 169 of file WOscContainer.cpp.
References FindRoot().
00170 { 00171 delete FindRoot(); 00172 }
bool WOscContainer::RemoveContainer | ( | const char * | name | ) |
Removes child container or container alias by name (not address).
Definition at line 308 of file WOscContainer.cpp.
00309 { 00310 for ( int i = m_containerEntries.size()-1; i >= 0; i-- ) 00311 if ( m_containerEntries[i].m_name == name ) { 00312 // deallocated only if not an alias. 00313 if ( ! m_containerEntries[i].m_isAlias ) 00314 delete m_containerEntries[i].m_container; 00315 m_containerEntries.erase(m_containerEntries.begin() + i); 00316 return true; 00317 } 00318 return false; 00319 }
bool WOscContainer::RemoveMethod | ( | const char * | name | ) |
Removes child method or container alias by name (not address).
Definition at line 325 of file WOscContainer.cpp.
00326 { 00327 for ( int i = m_methodEntries.size()-1; i >= 0; i-- ) 00328 if ( m_methodEntries[i].m_name == name ) { 00329 // deallocated only if not an alias. 00330 if ( ! m_methodEntries[i].m_isAlias ) 00331 delete m_methodEntries[i].m_method; 00332 m_methodEntries.erase(m_methodEntries.begin() + i); 00333 return true; 00334 } 00335 return false; 00336 }