collection Class Reference

#include <collection.h>

Inheritance diagram for collection:

io_base

Detailed Description

Collection of objects.

By default, the fout() functions alphabetize the objects by name, but this is not a requirement for files read using fin().

Important issues: 1. Pointers are not set until after an entire file is read so that objects that are pointed to may occur anywhere in a file. This means that the information that is pointed to cannot be used in the io_tlate_d::input() function.

Todo:
Bug:
Structure: collection::fout() does the following:

To output individual items, collection::fout() does the following:

Definition at line 457 of file collection.h.


Public Member Functions

 collection ()
int get_type (text_out_file &tof, std::string stype, std::string name)
 Output object of type stype and name name to output tof.
int get (text_out_file &tof, std::string &stype, std::string name)
 Output object with name name to output tof.
int set (std::string name, text_in_file &tif)
 Set object named name with input from tif.
int set (std::string name, std::string val)
 Set object named name with input from val.
Output to file methods


int fout (out_file_format *outs)
 Output entire list to outs.
int fout (std::string filename)
 Output entire list to a textfile named filename.
Input from file methods
If overwrt is true, then any objects which already exist with the same name are overwritten with the objects in the file. The collection owns all the objects read. (Since it created them, the collection assumes it ought to be responsible to destroy them.)

int fin (std::string file_name, bool overwrt=false, int verbose=0)
 Read a collection from text file named file_name.
int fin (in_file_format *ins, bool overwrt=false, int verbose=0)
 Read a collection from ins.
Miscellaneous methods
int test_type (o2scl::test_mgr &t, std::string stype, void *obj, void *&newobj, bool scrout=false)
 Test the output for type stype.
int rewrite (std::string in_name, std::string out_name)
 Update a file containing a collection.
int disown (std::string name)
 Force the collection to assume that the ownership of name is external.
int summary (std::ostream *out, bool show_addresses=false)
 Summarize contents of collection.
int remove (std::string name)
 Remove an object for the collection.
void clear ()
 Remove all objects from the list.
int npa ()
 Count number of objects.
Generic add methods
If overwrt is true, then any objects which already exist with the same name as name are overwritten. If owner=true, then the collection will own the memory allocated for the object and will free that memory with delete when the object is removed or the collection is deleted.

int add (std::string name, io_base *tio, void *vec, int sz=0, int sz2=0, bool overwrt=true, bool owner=false)
int add (std::string name, std::string stype, void *vec, int sz=0, int sz2=0, bool overwrt=true, bool owner=false)
Generic get methods
int get (std::string tname, void *&vec)
 Get an object.
int get (std::string tname, void *&vec, int &sz)
 Get an array of objects.
int get (std::string tname, void *&vec, int &sz, int &sz2)
 Get a 2-d array of objects.
int get (std::string tname, std::string &stype, void *&vec)
 Get an object and its type.
int get (std::string tname, std::string &stype, void *&vec, int &sz)
 Get an array of objects and their type.
int get (std::string tname, std::string &stype, void *&vec, int &sz, int &sz2)
 Get a 2-d array of objects and their type.
void * get (std::string name)
 Get an object (alternative form).
Input and output of individual objects


int out_one (out_file_format *outs, std::string stype, std::string name, void *vp, int sz=0, int sz2=0)
 Output one object to a file.
int out_one (std::string fname, std::string stype, std::string name, void *vp, int sz=0, int sz2=0)
 Output one object to a file.
int in_one_name (in_file_format *ins, std::string stype, std::string name, void *&vp, int &sz, int &sz2)
 Input one object from a file with name name.
int in_one (in_file_format *ins, std::string stype, std::string &name, void *&vp, int &sz, int &sz2)
 Input one object from a file.
int in_one (std::string fname, std::string stype, std::string &name, void *&vp, int &sz, int &sz2)
 Input one object from a file.
Iterator functions
iterator begin ()
 Return an iterator to the start of the collection.
iterator end ()
 Return an iterator to the end of the collection.
type_iterator begin (std::string utype)
 Return an iterator to the first element of type utype in the collection.
type_iterator end (std::string utype)
 Return an iterator to the end of the collection.

Protected Types

typedef std::map
< std::string,
collection_entry,
string_comp >
::iterator 
piter
 A convenient iterator definition for the collection.

Protected Attributes

std::map
< std::string,
collection_entry,
string_comp
plist
 The actual collection.

Data Structures

class  iterator
 An iterator for stepping through a collection. More...
class  type_iterator
 An iterator for stepping through the entries in a collection of a particular type. More...

Member Function Documentation

int rewrite ( std::string  in_name,
std::string  out_name 
)

Update a file containing a collection.

This method loads the file from "fin" and produces a file at "fout" containing all of the objects from "fin", updated by their new values in the present list if possible. Then, it adds to the end of "fout" any objects in the present list that were not originally contained in "fin".

int disown ( std::string  name  ) 

Force the collection to assume that the ownership of name is external.

This allows the user to take over ownership of the object named name. This is particularly useful if the object is read from a file (since then object is owned initially by the collection), and you want to delete the collection, but retain the object.

int remove ( std::string  name  ) 

Remove an object for the collection.

Free the memory name if it is owned by the collection and then remove it from the collection.

int out_one ( out_file_format outs,
std::string  stype,
std::string  name,
void *  vp,
int  sz = 0,
int  sz2 = 0 
)

Output one object to a file.

This does not disturb any objects in the collection. The pointer specified does not need to be in the collection and is not added to the collection.

int out_one ( std::string  fname,
std::string  stype,
std::string  name,
void *  vp,
int  sz = 0,
int  sz2 = 0 
)

Output one object to a file.

This does not disturb any objects in the collection. The pointer specified does not need to be in the collection and is not added to the collection.

int in_one_name ( in_file_format ins,
std::string  stype,
std::string  name,
void *&  vp,
int &  sz,
int &  sz2 
)

Input one object from a file with name name.

This does not disturb any objects in the collection. The pointer specified does not need to be in the collection and is not added to the collection.

int in_one ( in_file_format ins,
std::string  stype,
std::string &  name,
void *&  vp,
int &  sz,
int &  sz2 
)

Input one object from a file.

This does not disturb any objects in the collection. The pointer specified does not need to be in the collection and is not added to the collection.

int in_one ( std::string  fname,
std::string  stype,
std::string &  name,
void *&  vp,
int &  sz,
int &  sz2 
)

Input one object from a file.

This does not disturb any objects in the collection. The pointer specified does not need to be in the collection and is not added to the collection.


The documentation for this class was generated from the following file:
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.