5 #ifndef IBIS_RESOURCE_H
6 #define IBIS_RESOURCE_H
43 typedef std::map< const char*, resource*, ibis::lessi >
gList;
44 typedef std::map< const char*, char*, ibis::lessi > vList;
50 explicit resource(
const char *fn) : prefix(0), context(0) {(void)
read(fn);}
56 groups(rhs.groups), values(rhs.values),
57 prefix(
ibis::util::
strnewdup(rhs.prefix)), context(rhs.context) {}
61 const char*
operator[](
const char *name)
const;
65 bool isTrue(
const char *name)
const;
67 int read(
const char* fn=0);
68 void write(
const char* fn=0)
const;
69 void add(
const char *name,
const char *value);
72 bool empty()
const {
return (values.empty() && groups.empty());}
73 gList::const_iterator gBegin()
const {
return groups.begin();}
74 gList::const_iterator gEnd()
const {
return groups.end();}
75 vList::const_iterator vBegin()
const {
return values.begin();}
76 vList::const_iterator vEnd()
const {
return values.end();}
81 inline const resource*
getGroup(
const char* name)
const;
85 inline const char*
getValue(
const char *name)
const;
90 static void clear(vList &vl);
100 const resource* context;
103 void write(std::ostream& out,
const char* ctx=0)
const;
109 if (name==0)
return group;
110 if (*name==static_cast<char>(0))
return group;
112 gList::const_iterator it = groups.find(name);
113 if (it != groups.end())
114 group = (*it).second;
120 const char* value = 0;
121 if (name==0)
return value;
122 if (*name==static_cast<char>(0))
return value;
124 vList::const_iterator it = values.find(name);
125 if (it != values.end())
126 value = (*it).second;
134 ret = context->getPrefix();
152 return(val != 0 && *val != 0 &&
153 ((*val ==
'1') || (*val ==
't') || (*val ==
'y') ||
154 (*val ==
'T') || (*val ==
'Y') || (stricmp(val,
"on") == 0)));
156 #endif // IBIS_RESOURCE_H
const char * operator[](const char *name) const
Locate the named parameter and return its value in raw string form.
Definition: resource.cpp:233
int read(const char *fn=0)
Read a configuration file.
Definition: resource.cpp:44
void add(const char *name, const char *value)
Add a name-value pair to the resource list.
Definition: resource.cpp:169
const char * getValue(const char *name) const
Find a named parameter.
Definition: resource.h:119
resource & operator=(const resource &rhs)
The assignment operator.
Definition: resource.cpp:444
char * strnewdup(const char *s)
Duplicate string content with C++ default new operator.
Definition: util.cpp:1420
A container for name-value pairs.
Definition: resource.h:38
resource(const resource *ctx, const char *pfx)
Create an empty object with the specified prefix and context.
Definition: resource.h:52
The current implementation of FastBit is code named IBIS; most data structures and functions are in t...
Definition: bord.h:16
resource(const char *fn)
Read the content of a parameter file.
Definition: resource.h:50
bool isTrue(const char *name) const
Locate the named parameter and return its value as true or false.
Definition: resource.cpp:290
void write(const char *fn=0) const
Write the content to a file.
Definition: resource.cpp:513
bool empty() const
Returns true if there is no name-value pair on record.
Definition: resource.h:72
double getNumber(const char *name) const
Locate the named parameter and return its value as a number.
Definition: resource.cpp:273
Defines minor utility functions and common classes used by FastBit.
std::map< const char *, resource *, ibis::lessi > gList
The name-value pairs are categorized into two types, names that map to simple values (vList) and name...
Definition: resource.h:43
static bool isStringTrue(const char *val)
Returns true is the string value should be interpreted as logical truth.
Definition: resource.h:151
static void parseNameValuePairs(const char *in, vList &lst)
Parse a string into a name-value list.
Definition: resource.cpp:347
void clear(ibis::array_t< ibis::bitvector * > &bv)
Clear an array of bit vectors.
Definition: bitvector.cpp:4662
const char * delimiters
Delimiters used to separate a string of names.
Definition: util.cpp:71
resource()
Default constructor. Creates an empty object.
Definition: resource.h:48
std::string getPrefix() const
Return the name of the full prefix of the resource.
Definition: resource.h:131
const resource * getGroup(const char *name) const
Find a group with the given name.
Definition: resource.h:107
resource(const resource &rhs)
Copy constructor. Deep copy.
Definition: resource.h:55