jccl::ConfigElement Class Reference

A unit of configuration information. More...

#include <jccl/Config/ConfigElement.h>

List of all members.

Public Member Functions

 ConfigElement ()
 Constructor.
 ConfigElement (ConfigDefinitionPtr def)
 Constructs a ConfigElement matching the given definition.
 ConfigElement (const ConfigElement &c)
 Copy constructor.
 ~ConfigElement ()
 Destroys a ConfigElement and frees associated memory.
bool isValid () const
bool initFromNode (cppdom::NodePtr elementNode)
 Initializes this element from cppdom::Node.
ConfigElementoperator= (const ConfigElement &c)
 Assignment operator.
bool operator== (const ConfigElement &c) const
 Tests for value equality of two ConfigElements.
bool operator!= (const ConfigElement &c) const
 Inequality.
bool operator< (const ConfigElement &c) const
 Lexical comparison based on element names (alphabetically).
ConfigElementPtr getChildElement (const std::string &path)
 Gets a child element from a property of self.
std::string getName () const
 Returns the instance name of this ConfigElement without any hierarchy information.
std::string getFullName () const
 Returns the fully qualified, unique name of this element.
unsigned int getVersion () const
 Returns the version number of the definition used by this ConfigElement.
std::string getID () const
 Returns the string that identifies self's ConfigDefinition.
template<class T>
getProperty (const std::string &prop, int ind) const
 Specialization for ConfigElementPtr's.
template<class T>
getProperty (const std::string &prop) const
 Gets value that defaults to property 0.
template<class T>
bool setProperty (const std::string &prop, const int ind, T val)
 Sets a value for the given property.
bool setProperty (const std::string &prop, const int ind, bool val)
 Specialization for boolean values.
bool setProperty (const std::string &prop, const int ind, ConfigElementPtr val)
 Specialization for ConfigElementPtrs.
std::vector< std::string > getElementPtrDependencies () const
 Returns a list of self's depenencies.
std::vector< jccl::ConfigElementPtrgetChildElements () const
 Return a list of self's child (embedded) elements.
void setDefinition (ConfigDefinitionPtr d)
 Associates the definintion d with this element.
ConfigDefinitionPtr getConfigDefinition ()
 Returns the Config Definition for this ConfigElement.
cppdom::NodePtr getNode () const

Protected Member Functions

std::string getPropertyString (const std::string &prop, int ind) const
 Returns the string value of the given property.
cppdom::NodePtr getPropertyCdataNode (const std::string &prop, int ind, bool autoCreate) const
 Get the property's cdata node.
bool getProperty_bool (const std::string &prop, int ind) const
 Gets a boolean value from the given property.
ConfigElementPtr getProperty_ElementPtr (const std::string &prop, int ind) const
 Gets an element ptr from the given property.

Protected Attributes

cppdom::NodePtr mNode
 Node for the config element.
ConfigDefinitionPtr mDef
 Definition for this element.
bool mValid
 Flag to signal whether element is valid.

Friends

JCCL_API(std::ostream getNum (const std::string &property) const &) operator<<(std unsigned int
 Returns the number of values for the specified property.


Detailed Description

A unit of configuration information.

References a config element DOM node and a definition for the given configuration element type.

Definition at line 55 of file ConfigElement.h.


Constructor & Destructor Documentation

jccl::ConfigElement::ConfigElement (  ) 

Constructor.

Definition at line 83 of file ConfigElement.cpp.

References mValid.

Referenced by getChildElement(), and getProperty_ElementPtr().

00084 {
00085    mValid = true;
00086 }

jccl::ConfigElement::ConfigElement ( ConfigDefinitionPtr  def  ) 

Constructs a ConfigElement matching the given definition.

Parameters:
def Points to a valid ConfigDefinition.

Definition at line 88 of file ConfigElement.cpp.

References mNode, mValid, and setDefinition().

00089 {
00090    mValid = true;
00091    setDefinition(def);
00092    mNode = ElementFactory::instance()->createXMLNode(); // Create a fresh node
00093 }

jccl::ConfigElement::ConfigElement ( const ConfigElement c  ) 

Copy constructor.

Definition at line 95 of file ConfigElement.cpp.

References mValid.

00096 {
00097    mValid = true;
00098    *this = c;
00099 }

jccl::ConfigElement::~ConfigElement (  ) 

Destroys a ConfigElement and frees associated memory.

Postcondition:
Self has been destroyed, along with all properties and values associated with it (but _not_ the memory associated with its ConfigDefinition).

Definition at line 101 of file ConfigElement.cpp.

References mValid.

00102 {
00103    mValid = false;
00104 }


Member Function Documentation

bool jccl::ConfigElement::isValid (  )  const

Definition at line 106 of file ConfigElement.cpp.

References mValid.

00107 {
00108    return mValid;
00109 }

bool jccl::ConfigElement::initFromNode ( cppdom::NodePtr  elementNode  ) 

Initializes this element from cppdom::Node.

Constructs the element to reference the given element node.

Postcondition:
This element is set up and initialized.
Returns:
false if failed to initialize.

Definition at line 111 of file ConfigElement.cpp.

References mNode, mValid, setDefinition(), and jccl::configuration_tokens::VERSION().

00112 {
00113    bool ret_val(false);
00114    vprASSERT(elementNode.get() != NULL);    // Make sure we have a valid node
00115 
00116    // Lookup our definintion.
00117    std::string my_type = elementNode->getName();
00118    ConfigDefinitionPtr def_ptr =
00119       ElementFactory::instance()->getConfigDefinition(my_type);
00120 
00121    if(def_ptr.get() == NULL)
00122    {
00123       const unsigned int my_version =
00124          elementNode->getAttribute(tokens::VERSION).getValue<unsigned int>();
00125       vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
00126          << clrOutBOLD(clrYELLOW, "WARNING")
00127          << ": Failed to get definition for element type '" << my_type
00128          << "' version " << my_version
00129          << "\n\tYou may have an invalid configuration element.\n"
00130          << vprDEBUG_FLUSH;
00131       ret_val = false;
00132    }
00133    else
00134    {
00135       mNode = elementNode;
00136       mValid = true;
00137       setDefinition(def_ptr);
00138       ret_val = true;
00139    }
00140    return ret_val;
00141 }

ConfigElement & jccl::ConfigElement::operator= ( const ConfigElement c  ) 

Assignment operator.

Definition at line 143 of file ConfigElement.cpp.

References mDef, mNode, and mValid.

00144 {
00145    if (! (this == &c) )    // Different objects
00146    {
00147       mNode  = c.mNode;
00148       mDef   = c.mDef;
00149       mValid = c.mValid;
00150    }
00151 
00152    return *this;
00153 }

bool jccl::ConfigElement::operator== ( const ConfigElement c  )  const

Tests for value equality of two ConfigElements.

Returns:
True iff self and c have the same values for all properties.

Definition at line 155 of file ConfigElement.cpp.

References mDef, and mNode.

00156 {
00157    // Check definitions first, then check the xml node contents
00158    if ( mDef.get() != c.mDef.get() )
00159    {
00160       return false;
00161    }
00162 
00163    bool is_equal = mNode->isEqual(c.mNode);
00164    /*
00165    std::ostringstream self_string, c_string;
00166    mNode->save(self_string);
00167    c.mNode->save(c_string);
00168    */
00169 
00170    return is_equal;
00171 }

bool jccl::ConfigElement::operator!= ( const ConfigElement c  )  const

Inequality.

Definition at line 173 of file ConfigElement.cpp.

00174 {
00175    return !(*this == c);
00176 }

bool jccl::ConfigElement::operator< ( const ConfigElement c  )  const

Lexical comparison based on element names (alphabetically).

Definition at line 178 of file ConfigElement.cpp.

References getName().

00179 {
00180    std::string s1 = getName();
00181    std::string s2 = c.getName();
00182    return (s1 < s2);
00183 }

ConfigElementPtr jccl::ConfigElement::getChildElement ( const std::string &  path  ) 

Gets a child element from a property of self.

Parameters:
path The complete name of a child element in self. The form is, for example, "property_token/instance_name".
Note:
This uses the name attribute of the elements.
Returns:
The ConfigElementPtr that is the child element. This may be a NULL ConfigElementPtr if the child element name was not found. Check before use.

Definition at line 203 of file ConfigElement.cpp.

References ConfigElement(), getFirstNameComponent(), getRemainder(), jccl::PropertyDefinition::getVarType(), hasSeparator(), mDef, mNode, and jccl::T_CHILD_ELEMENT.

00204 {
00205    std::string working_path(path), prop_token;
00206    cppdom::NodePtr root(mNode);
00207    cppdom::NodeList props;
00208 
00209    while ( hasSeparator(working_path) )
00210    {
00211       prop_token = getFirstNameComponent(working_path);
00212 
00213       // Move on to the next element in the path.
00214       working_path = getRemainder(working_path);
00215 
00216       PropertyDefinition prop_def = mDef->getPropertyDefinition(prop_token);
00217 
00218       // Now find the property child matching the current path element and the
00219       // corresponding property definition.
00220       props = root->getChildren(prop_token);
00221 
00222       if ( prop_def.getVarType() == jccl::T_CHILD_ELEMENT && ! props.empty() )
00223       {
00224          // Get the name of the child element we want.
00225          std::string child_element_name = getFirstNameComponent(working_path);
00226          working_path = getRemainder(working_path);
00227 
00228          // Reset root to NULL so that we can use its internal value later to
00229          // determine if we are done.
00230          root.reset();
00231 
00232          NamePred name_pred(child_element_name);
00233          cppdom::NodeList children;
00234 
00235          // Search the properties for a child whose "name" attribute matches
00236          // child_element_name.
00237          for ( cppdom::NodeList::iterator i = props.begin();
00238                i != props.end();
00239                ++i )
00240          {
00241             children = (*i)->getChildrenPred(name_pred);
00242             vprASSERT((children.empty() || children.size() <= 1) && "Element name not unique");
00243 
00244             if ( ! children.empty() )
00245             {
00246                root = *(children.begin());
00247                break;
00248             }
00249          }
00250       }
00251    }
00252 
00253    if ( root.get() != NULL )
00254    {
00255       ConfigElementPtr ret_node(new ConfigElement());
00256       ret_node->initFromNode(root);
00257       return ret_node;
00258    }
00259    else
00260    {
00261       return ConfigElementPtr();
00262    }
00263 }

std::string jccl::ConfigElement::getName (  )  const

Returns the instance name of this ConfigElement without any hierarchy information.

See also:
getFullName

Definition at line 265 of file ConfigElement.cpp.

References mNode, and jccl::configuration_tokens::NAME().

Referenced by getFullName(), getProperty_bool(), and operator<().

00266 {
00267    return mNode->getAttribute(tokens::NAME).getString();
00268 }

std::string jccl::ConfigElement::getFullName (  )  const

Returns the fully qualified, unique name of this element.

This will be different from getName() when this element is a child of another element. In that case, the name will be based on the element hierarchy and the property token. The format in that case will be "element name 0/property_token_0/element name 1/property_token_1/..."

Definition at line 270 of file ConfigElement.cpp.

References jccl::configuration_tokens::ELEMENTS(), jccl::EMBEDDED_SEPARATOR(), getName(), mNode, and jccl::configuration_tokens::NAME().

00271 {
00272    cppdom::Node *element_parent, *prop_parent;
00273    std::string full_name(getName());
00274 
00275    element_parent = mNode.get();
00276 
00277    while ( (prop_parent = element_parent->getParent()) != NULL &&
00278            prop_parent->getName() != std::string("root") &&
00279            prop_parent->getName() != tokens::ELEMENTS )
00280    {
00281       full_name = prop_parent->getName() + jccl::EMBEDDED_SEPARATOR + full_name;
00282       element_parent = prop_parent->getParent();
00283       full_name = element_parent->getAttribute(tokens::NAME).getString() +
00284                   EMBEDDED_SEPARATOR + full_name;
00285    }
00286 
00287    return full_name;
00288 }

unsigned int jccl::ConfigElement::getVersion (  )  const

Returns the version number of the definition used by this ConfigElement.

Definition at line 290 of file ConfigElement.cpp.

References mNode, and jccl::configuration_tokens::VERSION().

00291 {
00292    return mNode->getAttribute(tokens::VERSION).getValue<unsigned int>();
00293 }

std::string jccl::ConfigElement::getID (  )  const

Returns the string that identifies self's ConfigDefinition.

Definition at line 457 of file ConfigElement.cpp.

References mDef.

00458 {
00459    return mDef->getToken();
00460 }

ConfigElementPtr jccl::ConfigElement::getProperty< ConfigElementPtr > ( const std::string &  prop,
int  ind 
) const [inline]

Specialization for ConfigElementPtr's.

Parameters:
prop The token string for a property.
ind The index to the property's list of values. Use getNum() to determine the number of values for a given property. The valid range is 0 to getNum()-1.
Note:
Call with a template parameter equal to the type to return ie. getProperty<int>("int_property", 3);
Todo:
This function could throw I/O exceptions. Maybe catch those and turn them into something JCCL'ish.

Definition at line 174 of file ConfigElement.h.

00175    {
00176       std::string prop_string = getPropertyString(prop,ind);
00177 
00178       T ret_val = T();
00179       std::istringstream iss(prop_string);
00180       iss >> ret_val;
00181       return ret_val;
00182    }

template<class T>
T jccl::ConfigElement::getProperty ( const std::string &  prop  )  const [inline]

Gets value that defaults to property 0.

Note:
Can't use default param because GCC doesn't allow specialization in a declaration. In other words we couldn't use a default value for the property index within the std::string and ConfigElementPtr specializations.

Definition at line 363 of file ConfigElement.h.

00364 {
00365    return getProperty<T>(prop, 0);
00366 }

template<class T>
bool jccl::ConfigElement::setProperty ( const std::string &  prop,
const int  ind,
val 
) [inline]

Sets a value for the given property.

Parameters:
prop The token string for a property.
ind The index to the property's list of values.
val The value to set.
Note:
If property does not exist yet, then we create it in the element.

Definition at line 242 of file ConfigElement.h.

00243    {
00244       cppdom::NodePtr cdata_node = getPropertyCdataNode(prop, ind, true);
00245       vprASSERT(cdata_node.get() != NULL && "Autogrow failed");
00246 
00247       std::ostringstream oss;
00248       oss << val;
00249       cdata_node->setCdata(oss.str());
00250       return true;
00251    }

bool jccl::ConfigElement::setProperty ( const std::string &  prop,
const int  ind,
bool  val 
)

Specialization for boolean values.

Definition at line 462 of file ConfigElement.cpp.

References getPropertyCdataNode().

00463 {
00464    cppdom::NodePtr cdata_node = getPropertyCdataNode(prop, ind, true);
00465    vprASSERT(cdata_node.get() != NULL && "Autogrow failed");
00466 
00467    std::string str_val;
00468 
00469    if (true == val)
00470    {
00471       str_val = "true";
00472    }
00473    else
00474    {
00475       str_val = "false";
00476    }
00477    cdata_node->setCdata(str_val);
00478 
00479    return true;
00480 }

bool jccl::ConfigElement::setProperty ( const std::string &  prop,
const int  ind,
ConfigElementPtr  val 
)

Specialization for ConfigElementPtrs.

Definition at line 482 of file ConfigElement.cpp.

00483 {
00484    boost::ignore_unused_variable_warning(prop);
00485    boost::ignore_unused_variable_warning(ind);
00486    boost::ignore_unused_variable_warning(val);
00487    vprASSERT(false && "Not implemented");
00488    return false;
00489 }

std::vector< std::string > jccl::ConfigElement::getElementPtrDependencies (  )  const

Returns a list of self's depenencies.

Dependencies are any config elements named by an "Element Pointer" property of self (or any element embedded in self).

Returns:
A vector of the names of all config elements referenced by self, which can be used for dependency checking.

Definition at line 369 of file ConfigElement.cpp.

References getNum, mDef, jccl::T_CHILD_ELEMENT, and jccl::T_ELEMENT_PTR.

00370 {
00371    std::vector<std::string> dep_list;     // Create return vector
00372    std::string prop_token;
00373 
00374    std::vector<PropertyDefinition> prop_defs = mDef->getAllPropertyDefinitions();
00375 
00376    //cout << "Dependency test for " << getProperty ("name") << endl;
00377    // For each property definition.
00378    for ( unsigned int i = 0; i < prop_defs.size(); ++i )
00379    {
00380       VarType var_type = prop_defs[i].getVarType();
00381 
00382       // If it is an element ptr or a child element.
00383       if ( (var_type == T_ELEMENT_PTR) || (var_type == T_CHILD_ELEMENT) )
00384       {
00385          std::string prop_token = prop_defs[i].getToken();         // Get the property name
00386          unsigned int num_props = getNum(prop_token);    // How many entries
00387 
00388          // For each sub property.
00389          for ( unsigned int j = 0; j < num_props; ++j )
00390          {
00391             // Just get the element names and add it.
00392             if(var_type == T_ELEMENT_PTR)
00393             {
00394                std::string element_name = this->getProperty<std::string>(prop_token, j);
00395                if ( element_name != "")
00396                {
00397                   dep_list.push_back(element_name);
00398                }
00399             }
00400             else if(var_type == T_CHILD_ELEMENT)   // Recurse and add
00401             {
00402                std::vector<std::string> child_deps;
00403                ConfigElementPtr child_element = this->getProperty<ConfigElementPtr>(prop_token, j);
00404                vprASSERT(child_element.get() != NULL);
00405                child_deps = child_element->getElementPtrDependencies();
00406                dep_list.insert(dep_list.end(), child_deps.begin(), child_deps.end());
00407             }
00408          }
00409       }
00410    }
00411 
00412    return dep_list;      // Return the list
00413 }

std::vector< jccl::ConfigElementPtr > jccl::ConfigElement::getChildElements (  )  const

Return a list of self's child (embedded) elements.

Returns:
A vector of ConfigElementPtr objects that are the config elements embedded in self.

Definition at line 415 of file ConfigElement.cpp.

References getNum, mDef, and jccl::T_CHILD_ELEMENT.

00416 {
00417    std::vector<jccl::ConfigElementPtr> embedded_list;     // Create return vector
00418    std::string prop_token;
00419 
00420    std::vector<PropertyDefinition> prop_defs = mDef->getAllPropertyDefinitions();
00421 
00422    //cout << "Dependency test for " << getProperty ("name") << endl;
00423    // For each property definition.
00424    for ( unsigned int i = 0; i < prop_defs.size(); ++i )
00425    {
00426       VarType var_type = prop_defs[i].getVarType();
00427       if ( (var_type == T_CHILD_ELEMENT) )   // If property is a child element
00428       {
00429          prop_token = prop_defs[i].getToken();         // Get the property name
00430          unsigned int num_props = getNum(prop_token);    // How many entries
00431 
00432          // For each entry.
00433          for ( unsigned int j = 0; j < num_props; ++j )
00434          {
00435             ConfigElementPtr child_element =
00436                this->getProperty<ConfigElementPtr>(prop_token, j);
00437             vprASSERT(child_element.get() != NULL);
00438             embedded_list.push_back(child_element);
00439          }
00440       }
00441    }
00442 
00443    return embedded_list;      // Return the list
00444 }

void jccl::ConfigElement::setDefinition ( ConfigDefinitionPtr  d  ) 

Associates the definintion d with this element.

Postcondition:
Set the definintion for this element.

Definition at line 491 of file ConfigElement.cpp.

References mDef.

Referenced by ConfigElement(), and initFromNode().

00492 {
00493    vprASSERT(def.get() != NULL && "Trying to set a null definition");
00494    mDef = def;
00495 }

ConfigDefinitionPtr jccl::ConfigElement::getConfigDefinition (  ) 

Returns the Config Definition for this ConfigElement.

Definition at line 497 of file ConfigElement.cpp.

References mDef.

00498 {
00499    return mDef;
00500 }

cppdom::NodePtr jccl::ConfigElement::getNode (  )  const

Definition at line 502 of file ConfigElement.cpp.

References mNode.

00503 {
00504    return mNode;
00505 }

std::string jccl::ConfigElement::getPropertyString ( const std::string &  prop,
int  ind 
) const [protected]

Returns the string value of the given property.

Postcondition:
If property is found, then return the contents. Else return "".
Parameters:
prop The token string for the property.
ind The index of the property.

Definition at line 564 of file ConfigElement.cpp.

References jccl::definition_tokens::ENUM_VALUE(), jccl::definition_tokens::ENUMERATION(), jccl::PropertyDefinition::getDefaultValueString(), jccl::PropertyDefinition::getNode(), getPropertyCdataNode(), jcclDBG_CONFIG(), jccl::definition_tokens::LABEL(), mDef, mNode, jccl::configuration_tokens::NAME(), and jccl::definition_tokens::VALUE().

Referenced by getProperty_bool().

00565 {
00566    vprASSERT(mNode.get() != NULL);
00567    vprASSERT(tokens::NAME != prop && "Use getName() to get an element's name");
00568 
00569    std::string prop_string_rep("");     // The String rep to convert from
00570    PropertyDefinition prop_def = mDef->getPropertyDefinition(prop);
00571 
00572    // Ensure that a valid property was requested before taking any action.
00573    if ( prop_def.getNode().get() == NULL )
00574    {
00575       vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL)
00576          << clrOutBOLD(clrRED, "ERROR")
00577          << ": [jccl::ConfigElement::getPropertyString()] Invalid property '"
00578          << prop << "' requested!\n" << vprDEBUG_FLUSH;
00579       vprASSERT(false && "Invalid property requested.");
00580    }
00581    else
00582    {
00583       // Get the cdata node without auto create
00584       cppdom::NodePtr cdata_node = getPropertyCdataNode(prop,ind,false);
00585 
00586       if(cdata_node.get() != NULL)
00587       {
00588          prop_string_rep = cdata_node->getCdata();            // Get the cdata
00589       }
00590       // Fall back on the default value.
00591       else
00592       {
00593          prop_string_rep = prop_def.getDefaultValueString(ind);
00594       }
00595 
00596       cppdom::NodePtr enum_child(prop_def.getNode()->getChild(definition_tokens::ENUMERATION));
00597 
00598       if ( enum_child.get() != NULL )
00599       {
00600          cppdom::NodeList enum_vals(enum_child->getChildren(definition_tokens::ENUM_VALUE));
00601 
00602          // If the property definition has an enumeration, the string in
00603          // prop_string_rep may be symbolic.  We need to translate it to the
00604          // real value before returning.
00605          if ( ! enum_vals.empty() )
00606          {
00607             for ( cppdom::NodeList::iterator i = enum_vals.begin();
00608                   i != enum_vals.end();
00609                   ++i )
00610             {
00611                if ( prop_string_rep == (std::string) (*i)->getAttribute(definition_tokens::LABEL) )
00612                {
00613                   vprDEBUG(jcclDBG_CONFIG, vprDBG_HVERB_LVL)
00614                      << "jccl::ConfigElement::getPropertyString(): Converting '"
00615                      << prop_string_rep << "' to '"
00616                      << (std::string) (*i)->getAttribute(definition_tokens::VALUE)
00617                      << "'\n" << vprDEBUG_FLUSH;
00618                   prop_string_rep =
00619                      (std::string) (*i)->getAttribute(definition_tokens::VALUE);
00620                }
00621             }
00622          }
00623       }
00624    }
00625 
00626    return prop_string_rep;
00627 }

cppdom::NodePtr jccl::ConfigElement::getPropertyCdataNode ( const std::string &  prop,
int  ind,
bool  autoCreate 
) const [protected]

Get the property's cdata node.

Parameters:
prop The property token.
ind The index inside the property.
autoCreate If true, then autocreate the property node to use.
Note:
We always autocreate the cdata node if need be.

Definition at line 514 of file ConfigElement.cpp.

References jccl::PropertyDefinition::getDefaultValueString(), mDef, and mNode.

Referenced by getPropertyString(), and setProperty().

00515 {
00516    vprASSERT(mNode.get() != NULL);
00517 
00518    cppdom::NodePtr cdata_node(NULL);
00519    cppdom::NodeList prop_children(mNode->getChildren(prop));    // Get all children call prop
00520 
00521    // -- Autogrow for children --- //
00522    if( !(prop_children.size() > unsigned(ind)) && autoCreate)      // If child not in range and autocreate
00523    {
00524       PropertyDefinition prop_def = mDef->getPropertyDefinition(prop);
00525 
00526       while( !(prop_children.size() > unsigned(ind) ))     // While not in range
00527       {
00528          cppdom::NodePtr new_node = ElementFactory::instance()->createXMLNode();
00529          new_node->setName(prop);
00530          new_node->setCdata(prop_def.getDefaultValueString(ind));
00531          mNode->addChild(new_node);                      // Add Child
00532          prop_children = mNode->getChildren(prop);       // Get children again to check size
00533       }
00534    }
00535 
00536    // --- GET the cdata node --- //
00537    if(prop_children.size() > unsigned(ind))                                 // If we have children in range
00538    {
00539       cppdom::NodeList::iterator property_i(prop_children.begin());
00540       std::advance(property_i, ind);                                    // Advance to the correct child
00541       cdata_node = (*property_i)->getChild("cdata");        // Get the text node
00542 
00543       if(cdata_node.get() == NULL)     // If no cdata node, then make one
00544       {
00545          cppdom::NodePtr new_cdata_node = ElementFactory::instance()->createXMLNode();
00546          new_cdata_node->setName("cdata");
00547 #if CPPDOM_VERSION_MAJOR == 0 && CPPDOM_VERSION_MINOR < 4
00548          new_cdata_node->setType(cppdom::xml_nt_cdata);
00549 #else
00550          new_cdata_node->setType(cppdom::Node::xml_nt_cdata);
00551 #endif
00552          (*property_i)->addChild(new_cdata_node);
00553          cdata_node = new_cdata_node;
00554       }
00555 
00556       vprASSERT(cdata_node.get() != NULL);
00557    }
00558    else
00559    { vprASSERT(!autoCreate && "Auto create failed"); }
00560 
00561    return cdata_node;
00562 }

bool jccl::ConfigElement::getProperty_bool ( const std::string &  prop,
int  ind 
) const [protected]

Gets a boolean value from the given property.

Have to call this way because std::stringstring does not convert "true" and "false" into corresponding bool values.

Definition at line 295 of file ConfigElement.cpp.

References getName(), getPropertyString(), and jcclDBG_CONFIG().

00296 {
00297    const std::string prop_string = getPropertyString(prop, ind);
00298    if ( std::string("false") == prop_string || std::string("0") == prop_string )
00299    {
00300       return false;
00301    }
00302    else if ( std::string("true") == prop_string ||
00303              std::string("1") == prop_string )
00304    {
00305       return true;
00306    }
00307    else
00308    {
00309       vprDEBUG(jcclDBG_CONFIG, vprDBG_CONFIG_LVL)
00310          << "Expecting boolean string for property '" << prop
00311          << "' in config element '" << getName() << "'. Got '"
00312          << prop_string << "' instead. Assuming value of true.\n"
00313          << vprDEBUG_FLUSH;
00314       return true;
00315    }
00316 }

ConfigElementPtr jccl::ConfigElement::getProperty_ElementPtr ( const std::string &  prop,
int  ind 
) const [protected]

Gets an element ptr from the given property.

Have to call this way because specialization would use symbols that aren't available.

Definition at line 318 of file ConfigElement.cpp.

References ConfigElement(), mDef, mNode, and jccl::T_CHILD_ELEMENT.

00321 {
00322    // Get the var type
00323    vprASSERT(mDef->getPropertyDefinition(prop).getVarType() == T_CHILD_ELEMENT);
00324    vprASSERT(mNode.get() != NULL);
00325 
00326    // Get all property children matching the given property type.
00327    cppdom::NodeList prop_children(mNode->getChildren(prop));
00328 
00329    cppdom::NodePtr embedded_node(NULL);
00330 
00331    // --- GET the cdata node --- //
00332    if(prop_children.size() > unsigned(ind))                       // If we have children in range
00333    {
00334       cppdom::NodeList::iterator property_i(prop_children.begin());
00335       std::advance(property_i, ind);                              // Advance to the correct property
00336 
00337       // Get the children of this property.  There should only be one child
00338       // that is the element.
00339       cppdom::NodeList emb_nodes = (*property_i)->getChildren();
00340       vprASSERT(! emb_nodes.empty() && "Empty property");
00341       embedded_node = *(emb_nodes.begin());
00342    }
00343 
00344    ConfigElementPtr ret_val;
00345    if(embedded_node.get() != NULL)
00346    {
00347       // Create a new config element refrencing the embedded node.
00348       ret_val = ConfigElementPtr( new ConfigElement());
00349       bool init_status = ret_val->initFromNode(embedded_node);
00350       // check for failure
00351       if(!init_status)
00352       {
00353          vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL)
00354             << "Failed to initialize embedded config element" << std::endl
00355             << vprDEBUG_FLUSH;
00356          vprDEBUG_NEXT(vprDBG_ALL, vprDBG_CRITICAL_LVL)
00357             << "(property '" << prop << "')\n" << vprDEBUG_FLUSH;
00358 
00359          ret_val = ConfigElementPtr();      // Set to NULL
00360       }
00361    }
00362 
00363    return ret_val;
00364 }


Friends And Related Function Documentation

unsigned int jccl::ConfigElement::getNum ( const std::string &  property  )  const [friend]

Returns the number of values for the specified property.

Precondition:
The named property exists in the definition for this config element.
Parameters:
property The token of a property. This comes from the definition for this config element.
Returns:
The number of values that exist for the given property which may be 0.

Definition at line 452 of file ConfigElement.cpp.

Referenced by getChildElements(), and getElementPtrDependencies().

00453 {
00454    return mNode->getChildren(property_token).size();
00455 }


Member Data Documentation

cppdom::NodePtr jccl::ConfigElement::mNode [protected]

Node for the config element.

Definition at line 329 of file ConfigElement.h.

Referenced by ConfigElement(), getChildElement(), getFullName(), getName(), getNode(), getProperty_ElementPtr(), getPropertyCdataNode(), getPropertyString(), getVersion(), initFromNode(), operator=(), and operator==().

ConfigDefinitionPtr jccl::ConfigElement::mDef [protected]

Definition for this element.

Definition at line 330 of file ConfigElement.h.

Referenced by getChildElement(), getChildElements(), getConfigDefinition(), getElementPtrDependencies(), getID(), getProperty_ElementPtr(), getPropertyCdataNode(), getPropertyString(), operator=(), operator==(), and setDefinition().

bool jccl::ConfigElement::mValid [protected]

Flag to signal whether element is valid.

Definition at line 331 of file ConfigElement.h.

Referenced by ConfigElement(), initFromNode(), isValid(), operator=(), and ~ConfigElement().


The documentation for this class was generated from the following files:
Generated on Thu Jan 4 10:49:53 2007 for JCCL: Juggler Configuration and Control Library by  doxygen 1.5.1