From: stephan b. <st...@ei...> - 2003-09-04 10:22:50
|
i've got my lex-based serial-text parser working, including a very rudimentary classloader, and it parses the GEV maps wonderfully. i'm experimenting with a SerialTree-like class which works a bit differently. Mainly, instead of children having to be Serializable, that type is simply a template type, and the STree can have any number of children /of any type/. Each child list gets it's own type, at compile time, and the object does some jumping-through-hoops to make sure all the various template-based containers are cleaned up when the object is destroyed (this one was tricky, though). Here's a sample of how a mutli-type list is used: SerTree tree( "Root" ); tree.set( "ClassName", "SerTree" ); SerTree * chtree = 0; typedef std::vector<SerTree *> SerTreeList; SerTreeList & sertreelist = tree.children<SerTree>(); //COUT << "SerTreeList = " << hex << sertreelist << endl; chtree = new SerTree( "Tree Named Fred" ); chtree->set( "bar", "foo" ); sertreelist.push_back( chtree ); chtree->set( "foo", "bar" ); EPropertyList * pchild = new SerTree( "Another Tree Named Fred" ); tree.children<EPropertyList>().push_back( pchild ); // note that we just stuck a SerTree * into the EPropertyList children. pchild->set( "thisispchild", "yes" ); pchild = new EPropertyList( "An EPropertyList" ); pchild->set( "thisisanotherpchild", "yesyes" ); pchild->set( "42", 17 ); tree.children<EPropertyList>().push_back( pchild ); i'll admit that the template parms make it a bit verbose, but it's very flexible (and typedefs can clean it up a bit). The core of it is one static-only class which can dole out arbitrary containers of pointers to type Foo, and maps those containers to a given parent object. This means you can add new children type at any time to any object which proxies this "container doler-outer". Note that this unifies the interface for accessing any child list type (well, any list of pointers to children), regardless of the underlying child pointer type: EMTCoP list; // EMTCoP = Multi-Type Container of Pointers EMTCoP::iter<FooChild>::list_type & li = EMTCoP::children<FooChild>(); EMTCoP::iter<BarChild>::list_type & li3 = EMTCoP::children<BarChild>(); EMTCoP::iter<int>::list_type & li4 = EMTCoP::children<int>(); (integral types are untested!) Your parent container need not know that it will handle these types. Doing the above will automatically register all entries for each of these 3 lists (and the lists themselves) to be destroyed when 'list' is destroyed. Alternately, remove the items from the list yourself so cleanup is not necessary. This SerTree is not yet usable - i just threw together a quick PropertyList subclass to try it out with. But the concept appears to work, so i'm going to experiment with it more. -- ----- stephan st...@ei... - http://www.einsurance.de "...control is a degree of inhibition, and a system which is perfectly inhibited is completely frozen." -- Alan W. Watts |