[DM-dev] Properties object status
Brought to you by:
acdalton,
henningsen
From: Stephan B. <st...@wa...> - 2001-04-25 23:13:59
|
The DMProperties object (replaces 'config object') is now in CVS and can load and save itself to/from text or to/from another DMProperties object. What this means, is, we can have an ini file like this one: andthisone=is at the front of the list bool_true=false bool_words=yesireebob double=2.315680 eat=this one=1 string=hey xxx=in the middle ;comment foostr=bar fooint=42 ;comment2 #comment3 crawler.prop1=yes crawler.foostr=bar crawler.fooint=42 And then read it in into two different properties objects, like this: (assume for a moment that Crawler subclass DMProperties!) int main (int argc, char *argv[]) { string filename = argv[1] ? argv[1] : "my.dungeoninfo"; DMProperties file( filename, true ); if( ! file.load() ) exit( 666 ); //file.toCerr(); DMProperties crawler( "crawler" ); crawler.loadFromProperties( file ); crawler.toCerr( false ); exit( 0 ); } This prints out the following: <<< crawler: >>> fuckoff=yes maza foostr=bar fooint=42 >>> :crawler <<< Notice how it only contains keys from our config file which started with this object's name ("crawler"). This alllows us to store any number of objects in the object. Their file output could look like this: crawler.1.prop1=yes crawler.1.foostr=bar crawler.1.fooint=42 crawler.2.prop1=eat this crawler.2.foostr=hello, world crawler.2.fooint=21 These could be programatically created with this code: DMProperties c; c = DMProperties( "crawler.1" ); c.set( "foostr", "hello, world" ); ... One good question is: How do you read them back, if you don't know what their names are? There are two options: First: We cheat a little: we have the user tell us: crawlers=1 2 or: crawlers=bill, ted, 1-10 Then we create DMProperties objects with those names and populate them. Items not listed like this are effectively "commented out" of the config data. But the config reader still keeps them in pure text form, and they will be written back out to the file when it is saved, so no data is lost. This gives a lot of room for flexibility in testing out changes to your config files. But, yes, it is a slight hassle if you're creating them by hand. Second: We make some rules regarding the naming of objects, and then do something like this with the naming: objectype.name.property=val Then, when someone calls: DMPropertiesList *DMProperties::getObjects( "objecttype" ); we will instantiate all objects of that type (they're all just DMProperties with different names, after all), set all of it's properties, and give back a list of them. That function is not yet implemented by the way. Number 2 sounds like the way to go, so that's what I'm gonna work on next. Tomorrow night, anyway. ----- Stephan Beal - st...@wa... http://qub.sourceforge.net - http://stephan.rootonfire.org http://dungeonmaker.sourceforge.net "Now I'm not normally the kind of person who likes to trespass, but sometimes you just find yourself over the line." -- Bob Dylan |