#include <CNCL/Manager.h>
CN_MANAGER
CNObject
None
CNHashTable, CNHashDynamic, CNHashIterator, CNKey, CNKeyString, CNKeyInt
CNManager
is a class which provides facilities for storing and
retrieving CNCL compatible objects in a filesystem-like manner.
Objects of type CN_MANAGER
can be compared with directories,
whereas all other CNCL compatible objects play the role of the files.
CNManager
internally uses a dynamic hash table for managing
the objects.
Constructors:
CNManager(char *object_name = NIL);
CNManager(CNParam *param);
CNManager
.
Destructor:
~CNManager();
In addition to the member functions required by CNCL, CNManager
provides:
CNObject *new_object(char *object_name, CNClassDesc desc, CNParam *param = NIL);
new_object()
is used to create a tree of objects similar to a
filesystem's tree of directories and files. The class descriptor
desc
determines whether a directory (CN_MANAGER
) or a
file (any other type) is to be created.
The object_name
may consist of a pathname and/or a basename.
All directory-names and the basename must be separated by slashes
('/'). The pointer to the new created object is returned, if no
error occurs, otherwise, if e. g. the specified pathname was incorrect,
NIL
is returned.
bool delete_object(char *object_name);
new_object()
is deleted, too.
As described under new_object()
you may pass a filesystem-like
path to delete_object()
. If the object is deleted succesfully,
TRUE
is returned, FALSE
otherwise. If the object to be
deleted is a 'directory' and if the 'directory' still contains valid
'files', delete_object()
fails. You must first delete all
subentries before deleting the entry itself.
CNObject *get_object(char *object_name) const;
NIL
is returned.
char *get_name();
bool is_empty() const;
The following example shows how to use CNManager
objects in
order to store and retrieve CNCL compatible objects.
// this is the root of the example's object hierarchy CNManager root; // some 'directory' pointers CNManager *mobile, *base, *subbase; // some 'file' pointers CNHashDynamic *table1, *table2; // create a 'directory' in the root 'directory' mobile = (CNManager *)root.new_object("mobile", CN_MANAGER); if (mobile == NIL) ... // create another 'directory' base = (CNManager *)root.new_object("base", CN_MANAGER); if (base == NIL) ... // now create a 'file' (CNCL compatible object) in the // 'mobile' 'directory' table1 = (CNHashDynamic *)mobile->new_object("table1", CN_HASHDYNAMIC); if (table1 == NIL) ... // now create a 'subdirectory' of 'base' using an absolute path subbase = (CNManager *)root.new_object("/base/subbase", CN_MANAGER); if (subbase == NIL) ... // create a 'file' using a path relative to 'base' table2 = (CNHashDynamic *)base->new_object("subbase/table2", CN_HASHDYNAMIC); if (table2 == NIL); ... // now try to get an object if (base->get_object("subbase/table2") == table2) ... // try to delete 'subbase' if (!root.delete_object("/base/subbase")) // error, dir not empty ... // first delete all subentries if (!root.delete_object("/base/subbase/table2")) ... // now delete subbase if (!base->delete_object("subbase")) // okay ... ...
Go to the first, previous, next, last section, table of contents.