#include <collection.h>
This class is experimental.
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.
ptr_map
(with output=true
) so that they can be referred to by pointers laterplist
(see below). Any pointers which are not already in ptr_map
are added at this point (with output=false
To output individual items, collection::fout() does the following:
ptr_map
. If it is not there, then the object is added and assigned a name. The type and name are then output. If the pointer is 0, then both the type and the name are set to null
. Definition at line 488 of file collection.h.
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... | |
Public Member Functions | |
int | is_parameter (std::string tname) |
Return true if there is a parameter in the collection with the name tname . | |
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 text file 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 | size () |
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_void (std::string name, io_base *tio, void *vec, int sz=0, int sz2=0, bool overwrt=true, bool owner=false) |
int | add_void (std::string name, std::string stype, void *vec, int sz=0, int sz2=0, bool overwrt=true, bool owner=false) |
Machine type get methods | |
bool | getb_def (std::string name, bool def_value) |
Get a boolean value named name with default value def_value . | |
char | getc_def (std::string name, char def_value) |
Get a char named name with default value def_value . | |
double | getd_def (std::string name, double def_value) |
Get a double named name with default value def_value . | |
int | geti_def (std::string name, int def_value) |
Get an integer named name with default value def_value . | |
std::string | gets_def (std::string name, std::string def_value) |
Get a string named name with default value def_value . | |
std::string | getw_def (std::string name, std::string def_value) |
Get a boolean value named name with default value def_value . | |
bool | getb (std::string name) |
Desc. | |
char | getc (std::string name) |
Desc. | |
double | getd (std::string name) |
Desc. | |
int | geti (std::string name) |
Desc. | |
std::string | gets (std::string name) |
Desc. | |
std::string | getw (std::string name) |
Desc. | |
int | getb (std::string name, bool *&op, size_t &sz) |
Desc. | |
int | getb (std::string name, bool **&op, size_t &sz, size_t &sz2) |
Desc. | |
int | getc (std::string name, char *&op, size_t &sz) |
Desc. | |
int | getc (std::string name, char **&op, size_t &sz, size_t &sz2) |
Desc. | |
int | getd (std::string name, double *&op, size_t &sz) |
Desc. | |
int | getd (std::string name, double **&op, size_t &sz, size_t &sz2) |
Desc. | |
int | geti (std::string name, int *&op, size_t &sz) |
Desc. | |
int | geti (std::string name, int **&op, size_t &sz, size_t &sz2) |
Desc. | |
int | gets (std::string name, std::string *&op, size_t &sz) |
Desc. | |
int | gets (std::string name, std::string **&op, size_t &sz, size_t &sz2) |
Desc. | |
int | getw (std::string name, std::string *&op, size_t &sz) |
Desc. | |
int | getw (std::string name, std::string **&op, size_t &sz, size_t &sz2) |
Desc. | |
Generic type get methods | |
template<class obj_t > | |
int | get (std::string name, obj_t *&op) |
Desc. | |
template<class obj_t > | |
int | get (std::string name, obj_t *&op, size_t &sz) |
Desc. | |
template<class obj_t > | |
int | get (std::string name, obj_t **&op, size_t &sz, size_t &sz2) |
Desc. | |
int | get_void (std::string tname, void *&vec) |
Get an object. | |
Text file get and set methods | |
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, bool err_on_notfound=true) |
Set object named name with input from tif . | |
int | set (std::string name, std::string val, bool err_on_notfound=true) |
Set object named name with input from val . | |
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. | |
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. |
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 get_void | ( | std::string | tname, | |
void *& | vec | |||
) |
Get an object.
This should be deprecated, but is presently used in cli.cpp
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 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 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 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".
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.
Project hosting provided by
,
O2scl Sourceforge Project Page