cWidget::WithDataFunctions Class Reference

This class offers functions to parse DataSet and friends. It doesn't parse anything by itself, ProcessDataSet() has to be called by an inherited class. More...

#include <cWidgetBase.h>

Inheritance diagram for cWidget::WithDataFunctions:

Inheritance graph
[legend]
Collaboration diagram for cWidget::WithDataFunctions:

Collaboration graph
[legend]

List of all members.

Public Member Functions

bool Process (tXmlParser::node cur)
 Process a node.

Protected Member Functions

tValue::Set ProcessDataSet (tXmlParser::node cur)
 Processes a given DataSet tag and returns the resulting set.

Private Member Functions

tValue::BaseProcessValue (tXmlParser::node cur)
 Processes a Value node given as its parameter, parses it, and returns a tValue.
tValue::BaseProcessMath (tXmlParser::node cur)
 Processes a Math node given as its parameter and returns it.
tValue::BaseProcessConditionalCore (tXmlParser::node cur)
 Processes an IfTrue or IfFalse node and returns the resulting Value.
tValue::BaseProcessConditional (tXmlParser::node cur)
 Processes a Conditional node given as its parameter and returns it.
tValue::BaseProcessAtomicData (tXmlParser::node cur)
 Processes an AtomicData node and returns the result.
void ProcessDataTags (tXmlParser::node cur, tValue::Base &data)
 Processes the precision="" attributes and friends for a given node and Value.
tValue::BaseProcessDataSource (tString const &data)
 Processes and returns a simple data source (like lvalue and rvalue).


Detailed Description

This class offers functions to parse DataSet and friends. It doesn't parse anything by itself, ProcessDataSet() has to be called by an inherited class.

Definition at line 115 of file cWidgetBase.h.


Member Function Documentation

tValue::Base * cWidget::WithDataFunctions::ProcessValue ( tXmlParser::node  cur  )  [private]

Processes a Value node given as its parameter, parses it, and returns a tValue.

Definition at line 258 of file cWidgetBase.cpp.

References vValue::Parser::parse().

Referenced by ProcessConditionalCore(), and ProcessDataSet().

00258                                                               {
00259 #ifndef WIN32
00260     return tValueParser::parse(cur.GetProp("expr"));
00261 #else
00262     return 0;
00263 #endif

Here is the call graph for this function:

Here is the caller graph for this function:

tValue::Base * cWidget::WithDataFunctions::ProcessMath ( tXmlParser::node  cur  )  [private]

Processes a Math node given as its parameter and returns it.

Definition at line 139 of file cWidgetBase.cpp.

References Add, ProcessConditionalCore(), ProcessDataSource(), ProcessDataTags(), and tERR_WARN.

Referenced by ProcessConditionalCore(), and ProcessDataSet().

00139                                                              {
00140     tValue::BasePtr lvalue(ProcessDataSource(cur.GetProp("lvalue")));
00141     tValue::BasePtr rvalue(ProcessDataSource(cur.GetProp("rvalue")));
00142 
00143     for (tXmlParser::node child = cur.GetFirstChild(); child; ++child) {
00144         tString name = child.GetName();
00145         if(name == "RValue") {
00146             rvalue = tValue::BasePtr(ProcessConditionalCore(child));
00147         } else if(name == "LValue") {
00148             lvalue = tValue::BasePtr(ProcessConditionalCore(child));
00149         }
00150     }
00151 
00152     tValue::Base *val;
00153     if (cur.GetProp("type") == "sum")
00154         val = new tValue::Add(lvalue, rvalue);
00155     else
00156         if (cur.GetProp("type") == "difference")
00157             val = new tValue::Subtract(lvalue, rvalue);
00158         else
00159             if (cur.GetProp("type") == "product")
00160                 val = new tValue::Multiply(lvalue, rvalue);
00161             else
00162                 if (cur.GetProp("type") == "quotient")
00163                     val = new tValue::Divide(lvalue, rvalue);
00164                 else
00165                 {
00166                     tERR_WARN("Type '" + cur.GetProp("type") + "' unknown!");
00167                     val = new tValue::Add(lvalue, rvalue);
00168                 }
00169     ProcessDataTags(cur, *val);
00170     return val;
00171 }

Here is the call graph for this function:

Here is the caller graph for this function:

tValue::Base * cWidget::WithDataFunctions::ProcessConditionalCore ( tXmlParser::node  cur  )  [private]

Processes an IfTrue or IfFalse node and returns the resulting Value.

Definition at line 232 of file cWidgetBase.cpp.

References ProcessAtomicData(), ProcessConditional(), ProcessMath(), ProcessValue(), and tERR_WARN.

Referenced by ProcessConditional(), and ProcessMath().

00232                                                                         {
00233     for (cur = cur.GetFirstChild(); cur; ++cur) {
00234         tString name = cur.GetName();
00235         if(name == "AtomicData") {
00236             return ProcessAtomicData(cur);
00237         }
00238         if(name == "Conditional") {
00239             return ProcessConditional(cur);
00240         }
00241         if(name == "Math") {
00242             return ProcessMath(cur);
00243         }
00244         else
00245             if (name == "Value")
00246                 return ProcessValue(cur);
00247     }
00248     tERR_WARN("IfTrue or IfFalse node doesn't contain an AtomicData or Conditional node")
00249     return new tValue::Base();
00250 }

Here is the call graph for this function:

Here is the caller graph for this function:

tValue::Base * cWidget::WithDataFunctions::ProcessConditional ( tXmlParser::node  cur  )  [private]

Processes a Conditional node given as its parameter and returns it.

Definition at line 173 of file cWidgetBase.cpp.

References NULL, ProcessConditionalCore(), ProcessDataSource(), and tERR_WARN.

Referenced by ProcessConditionalCore(), and ProcessDataSet().

00173                                                                     {
00174     tValue::BasePtr lvalue(ProcessDataSource(cur.GetProp("lvalue")));
00175     tValue::BasePtr rvalue(ProcessDataSource(cur.GetProp("rvalue")));
00176     tValue::BasePtr truevalue(new tValue::Base), falsevalue(new tValue::Base);
00177 
00178     tString oper = cur.GetProp("operator");
00179     tValue::Base *condvalue = NULL;
00180     if (oper.size() == 2)
00181     {
00182         switch (oper[1]) {
00183     case 't': case 'T':
00184             switch (oper[0]) {
00185         case 'g': case 'G':
00186                 condvalue = new tValue::GreaterThan    (lvalue, rvalue);
00187                 break;
00188         case 'l': case 'L':
00189                 condvalue = new tValue::   LessThan    (lvalue, rvalue);
00190                 break;
00191             }
00192             break;
00193     case 'e': case 'E':
00194             switch (oper[0]) {
00195         case 'g': case 'G':
00196                 condvalue = new tValue::GreaterOrEquals(lvalue, rvalue);
00197                 break;
00198         case 'l': case 'L':
00199                 condvalue = new tValue::   LessOrEquals(lvalue, rvalue);
00200                 break;
00201         case 'n': case 'N':
00202                 tValue::BasePtr precond(new tValue::Equals(lvalue, rvalue));
00203                 condvalue = new tValue::Not(precond);
00204                 break;
00205             }
00206             break;
00207     case 'q': case 'Q':
00208             if (oper[0] == 'e' || oper[0] == 'E')
00209                 condvalue = new tValue::         Equals(lvalue, rvalue);
00210             break;
00211         }
00212     }
00213     if (!condvalue)
00214     {
00215         tERR_WARN("Operator '" + oper + "' unknown!");
00216         condvalue = new tValue::Equals(lvalue, rvalue);
00217     }
00218     tValue::BasePtr condvalueP(condvalue);
00219 
00220     for (cur = cur.GetFirstChild(); cur; ++cur) {
00221         tString name = cur.GetName();
00222         if(name == "IfTrue") {
00223             truevalue = tValue::BasePtr(ProcessConditionalCore(cur));
00224         } else if(name == "IfFalse") {
00225             falsevalue = tValue::BasePtr(ProcessConditionalCore(cur));
00226         }
00227     }
00228 
00229     return new tValue::Condition(condvalueP, truevalue, falsevalue);
00230 }

Here is the call graph for this function:

Here is the caller graph for this function:

tValue::Base * cWidget::WithDataFunctions::ProcessAtomicData ( tXmlParser::node  cur  )  [private]

Processes an AtomicData node and returns the result.

Definition at line 252 of file cWidgetBase.cpp.

References ProcessDataSource(), and ProcessDataTags().

Referenced by ProcessConditionalCore(), and ProcessDataSet().

00252                                                                    {
00253     tValue::Base *ret = ProcessDataSource(cur.GetProp("source"));
00254     ProcessDataTags(cur, *ret);
00255     return ret;
00256 }

Here is the call graph for this function:

Here is the caller graph for this function:

void cWidget::WithDataFunctions::ProcessDataTags ( tXmlParser::node  cur,
tValue::Base data 
) [private]

Processes the precision="" attributes and friends for a given node and Value.

Definition at line 265 of file cWidgetBase.cpp.

References vValue::Expr::Core::Base::SetFill(), vValue::Expr::Core::Base::SetMinsize(), vValue::Expr::Core::Base::SetPrecision(), and tERR_WARN.

Referenced by ProcessAtomicData(), and ProcessMath().

00266                                                                             {
00267     int precision, minwidth;
00268     cur.GetProp("precision", precision);
00269     cur.GetProp("minwidth", minwidth);
00270     tString fill = cur.GetProp("fill");
00271     if(fill.size() != 1) {
00272         tERR_WARN("Attribute 'fill' has to have a length of 1!");
00273         fill = "!";
00274     }
00275     data.SetPrecision(precision);
00276     data.SetMinsize(minwidth);
00277     data.SetFill(fill(0));

Here is the call graph for this function:

Here is the caller graph for this function:

tValue::Base * cWidget::WithDataFunctions::ProcessDataSource ( tString const &  data  )  [private]

Processes and returns a simple data source (like lvalue and rvalue).

Definition at line 279 of file cWidgetBase.cpp.

References tString::Convert(), cWidget::Base::m_Cockpit, stc_callbacks, stc_forbiddenCallbacks, and tString::ToLower().

Referenced by ProcessAtomicData(), ProcessConditional(), and ProcessMath().

00280                                                                     {
00281     //is it an integer?
00282     int val_int;
00283     if(data.Convert(val_int)) return new tValue::Int(val_int);
00284     //is it a float
00285     float val_float;
00286     if(data.Convert(val_float)) return new tValue::Float(val_float);
00287 
00288     //is it one of the dynamic callbacks?
00289     std::map<tString, tValue::Callback<cCockpit>::cb_ptr>::const_iterator iter;
00290     if((iter = stc_callbacks.find(data.ToLower())) != stc_callbacks.end()) {
00291         if(stc_forbiddenCallbacks.count(data.ToLower())) return new tValue::Base();
00292         return new tValue::Callback<cCockpit>(iter->second, m_Cockpit);
00293     }
00294 
00295     //growing desperate... is this a configuration value maybe?
00296     tValue::ConfItem *item = new tValue::ConfItem(data);
00297     if(item->Good())
00298         return item;
00299     delete item;
00300 
00301     //Ok, giving up... this has to be a string then.
00302     return new tValue::String(data);

Here is the call graph for this function:

Here is the caller graph for this function:

tValue::Set cWidget::WithDataFunctions::ProcessDataSet ( tXmlParser::node  cur  )  [protected]

Processes a given DataSet tag and returns the resulting set.

Parameters:
cur the node to be parsed as DataSet
Returns:
the resulting data set

Definition at line 97 of file cWidgetBase.cpp.

References ProcessAtomicData(), ProcessConditional(), ProcessMath(), and ProcessValue().

Referenced by cWidget::WithIdData::Process(), and cWidget::WithSingleData::Process().

00097                                                               {
00098     tValue::BasePtr
00099     value(new tValue::Base()),
00100     minimum(new tValue::Base()),
00101     maximum(new tValue::Base());
00102     for (cur = cur.GetFirstChild(); cur; ++cur) {
00103         tValue::Base *newvalue = 0;
00104         tString name = cur.GetName();
00105         if(name == "AtomicData") {
00106             newvalue = ProcessAtomicData(cur);
00107         } else if(name == "Conditional") {
00108             newvalue = ProcessConditional(cur);
00109         } else if(name == "Math") {
00110             newvalue = ProcessMath(cur);
00111         }
00112         else
00113             if (name == "Value")
00114                 newvalue = ProcessValue(cur);
00115         if(newvalue != 0) {
00116             tString field = cur.GetProp("field");
00117             if(field == "source") {
00118                 value = tValue::BasePtr(newvalue);
00119             } else if(field=="minimum") {
00120                 minimum = tValue::BasePtr(newvalue);
00121             } else if(field=="maximum") {
00122                 maximum = tValue::BasePtr(newvalue);
00123             }
00124         }
00125     }
00126     // TODO:
00127     /*
00128     return tValue::Set(
00129                value.release(),
00130                minimum.release(),
00131                maximum.release());
00132     */
00133     return tValue::Set(
00134                value,
00135                minimum,
00136                maximum);
00137 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool cWidget::WithDataFunctions::Process ( tXmlParser::node  cur  )  [virtual]

Process a node.

This needs to be overwritten if the derived class has anyting to parse or can be derived from.

It should try to parse the given node, return true on success or return the result of the Process() function of the widget it's derived from if it fails.

Parameters:
cur the node that's being attempted to parse
Returns:
true on success, false on failure

Reimplemented from cWidget::Base.

Reimplemented in cWidget::BarGauge, cWidget::Label, cWidget::Rectangle, cWidget::WithSingleData, cWidget::WithIdData, and cWidget::WithTable.

Definition at line 91 of file cWidgetBase.cpp.

References cWidget::Base::Process().

Referenced by cWidget::WithIdData::Process(), and cWidget::WithSingleData::Process().

00091                                                   {
00092     return Base::Process(cur);
00093 }

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files:
Generated on Sun Mar 16 00:04:31 2008 for Armagetron Advanced by  doxygen 1.5.4