Re: config library



Pardon my delurking -- I may have no clue what I'm talking about (I have
only read the config thread with a limited amount of attention), so please
discard this mail without another thought if such is found to be the case.
:)

"Fox, Kevin M" wrote:

> how about somthing like:
> in the file test.cfg
>
> #filecfg.o
> object1{
>   object2{
>     attribute1="something"
>   }
>   object3{
>   }
>   attribute2="something else"
>   attribute3="more something"
> }
> attribute4="global somthing"

Or, for those pining for an XML-style config file:

<OBJECT NAME="object1">
  <OBJECT NAME="object2">
    <ATTRIBUTE NAME="attribute1">something</ATTRIBUTE>
  </OBJECT>
  <OBJECT NAME="object3">
  </OBJECT>
  <ATTRIBUTE NAME="attribute2">something else</ATTRIBUTE>
  <ATTRIBUTE NAME="attribute3">more something</ATTRIBUTE>
</OBJECT>
<ATTRIBUTE NAME="attribute4">global something</ATTRIBUTE>

You might also want a TYPE field within the <ATTRIBUTE> tag -- e.g.
TYPE=string, TYPE=int, etc.  Someone mentioned this earlier.  I'm sure
there are lots of other things that could be stuck in the <OBJECT> and
<ATTRIBUTE> tags too, but I haven't really thought about it much.

> in the test program:
>
> config=cfg_open("test");
> objects=cfg_list_objects("/");
> object_count=cfg_count_objects("/");
> attribute_count=cfg_count_attributes("/object1");
> attributes_of_object1=cfg_get_attributes("/object2");

Do you not mean "/object1"?

> attribute1_of_object1=cfg_get_attribute("/object2", "attribute1");

Do you not mean "/object1/object2" or something like that?  I guess I don't
see what your "/" signs mean.  I had assumed they referred to levels of
object hierarchy.

> cfg_create_object("/object4");

Do you not need a parent object for the new object?  Or is this
automatically "/"?  As in, if you wanted to create a subobject of object3,
you'd create (e.g.) "/object1/object3/object4"?  Sounds awfully verbose. :)

> cfg_set_attribute("/object4", "attribute4", "blar");
> cfg_destroy_attribute("/object4", "attribute4");
> cfg_destroy_object("/object4");

A few overall comments: should an "object" not be a structure in C (a
GTK-style object, maybe -- as in, a structure with a GtkObjectClass * and
all that stuff)?  It would sure save on the very error-prone, verbose, and
slow "/object4" and such things.  Perhaps an attribute should be an object
too.  Thus cfg_get_attribute has the prototype:

CfgAttribute *cfg_get_attribute ( const CfgConfig *config, const CfgObject
*object );

and cfg_create_object has the prototype:

CfgObject *cfg_create_object ( CfgConfig *config, CfgObject *parent, char
*name );

Er, I haven't actually looked at GTK's object system very much, so I
apologize if the above looks really awful.

Anyway, your test program would then look something like the following:

CfgConfig    *config                 = cfg_open ( "test" );
CfgObject    *root                   = cfg_config_get_root ( config );
CfgObject    **objects               = cfg_object_get_subobjects ( config, root );
int          object_count            = cfg_object_count_subobjects ( config, root );
CfgObject    *object1                = cfg_object_get ( config, "/object1" );
int          attribute_count         = cfg_object_count_attributes ( config, object1 );
CfgAttribute **attributes_of_object1 = cfg_object_get_attributes ( config, object1 );
CfgObject    *object2                = cfg_object_get ( config, "/object1/object2" );
/* or: CfgObject *object2 = cfg_object_get_subobject ( config, object1, "object2" ); */
CfgAttribute *attribute1_of_object2  = cfg_object_get_attribute ( config, object2 );
/* or: CfgAttribute *blah = cfg_get_attribute ( config, "/object1/object2/attribute1" );
/* here you want something about cfg_attribute_get_type () and cfg_attribute_get_value () */
CfgObject    *object4                = cfg_create_object ( config, object1, "object4" );
CfgAttribute *attribute4_of_object4  = cfg_attribute_new ( whatever );
cfg_object_add_attribute ( config, object4, "attribute4", attribute4_of_object4 );
cfg_object_destroy_attribute ( config, object4, attribute4_of_object4 );
/* or maybe: cfg_object_destroy_attribute ( config, object4, "attribute4" ) */
/* or: cfg_destroy_attribute ( config, "/object1/object4/attribute4" );
cfg_destroy_object ( config, object4 );

Well, clearly there's some more thinking out to do.  In particular, what
happens to an "object" object or an "attribute" object when it's deleted
from the config?  Also, the variable "objects" in the test program above
necessarily contains object1 and object2 as some of its components.  How do
those get updated when the objects are modified?  Do they at all?  It can't
be modified if you add another object to "/".

Anyway, enough rambling. :)  I hope that's provided a bit of food for
thought.

     - Eric (re-engaging lurk mode...)

--
----=--=-=-==-===-=====//=====\\=====-===-==-=-=--=----------------- <>< -
"God is real, unless  // Name: \\ Eric Galluzzo | Software Engineer | SDRC
 declared integer."  // E-mail: \\ Eric.Galluzzo@sdrc.com
                    // SDRC WWW: \\ http://www.sdrc.com/
    -- Unknown     // http://www.geocities.com/SiliconValley/Vista/5567/
--=-=-==-===-=====//===============\\=====-===-==-=-=--=------------ <>< -





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]