OSCNamespaceItem.h

00001 /* Open SoundControl kit in C++                                              */
00002 /* Copyright (C) 2002-2004 libOSC++ contributors. See AUTHORS                */
00003 /*                                                                           */
00004 /* This library is free software; you can redistribute it and/or             */
00005 /* modify it under the terms of the GNU Lesser General Public                */
00006 /* License as published by the Free Software Foundation; either              */
00007 /* version 2.1 of the License, or (at your option) any later version.        */
00008 /*                                                                           */
00009 /* This library is distributed in the hope that it will be useful,           */
00010 /* but WITHOUT ANY WARRANTY; without even the implied warranty of            */
00011 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         */
00012 /* Lesser General Public License for more details.                           */
00013 /*                                                                           */
00014 /* You should have received a copy of the GNU Lesser General Public          */
00015 /* License along with this library; if not, write to the Free Software       */
00016 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
00017 /*                                                                           */
00018 /* For questions regarding this program contact                              */
00019 /* Daniel Holth <dholth@fastmail.fm> or visit                                */
00020 /* http://wiretap.stetson.edu/                                               */
00021 
00035 // eventually but not right now, in order to have an elegant implementation,
00036 // there may be a null string item at the beginning of every / :
00037 // ""/foo/bar/baz .  that is because the root of the entire osc namespace,
00038 // before the first /, can also contain a number of elements beginning
00039 // with the # character. Our container will do a very efficient lookup via
00040 // binary search or hashing, and we avoid the horror of ten if statements
00041 // or a completely separate root for the hash namespace.
00042 
00043 /* ChangeLog:
00044  *
00045  * 18 Oct. 2004: created - dwh
00046  * 29 Oct. 2004: begin multiple-result query functions
00047  *  1 Nov. 2004: enough functionality for multiple dispatch
00048  */
00049 
00050 #include <map>
00051 #include <string>
00052 #include <utility>
00053 #include <vector>
00054 #include "OSCCallable.h"
00055 
00056 class OSCNamespaceItem {
00057     public:
00058         // consider substituting hash map
00059         typedef std::map < std::string, OSCNamespaceItem*, std::less<std::string> > ItemMap;
00060 
00061         typedef void (*TraverseFunction)(void* cookie,
00062                                          std::vector < std::string > &address,
00063                                          OSCNamespaceItem *item);
00064 
00065     protected:
00066         bool search_internal(void *cookie,
00067                 TraverseFunction tf, std::vector < std::string > &address,
00068                 const std::string &name, size_t offset);
00069         
00070     public:
00071         ItemMap* mySubItems;
00072         OSCCallable *myCallable; // NULL unless this is a leaf node
00073 
00074     public:
00075         OSCNamespaceItem();
00076         ~OSCNamespaceItem();
00077 
00078         void setCallable(OSCCallable *callback) { this->myCallable = callback; }
00079         OSCCallable *getCallable()              { return this->myCallable; }
00080 
00086         bool traverse(const std::string &pattern, TraverseFunction tf, void *cookie = NULL);
00087 
00089         bool add(std::string name, OSCCallable *callback = NULL);
00090     
00093         bool list(int level);
00094 };

Generated on Thu Mar 2 23:51:35 2006 for libOSC++ by  doxygen 1.4.6