Main Page   Class Hierarchy   Compound List   File List   Compound Members  

xpath_value.h

00001 //  -*- c++ -*-
00002 
00003 #ifndef XPATH_VALUE_H
00004 #define XPATH_VALUE_H
00005 
00006 #include <qstring.h>
00007 #include <qcstring.h>
00008 
00009 #include <dom/dom_node.h>
00010 #include <xpath/xpath_node.h>
00011 
00012 namespace XPath {
00013 
00014 class Exception;
00015 class NodeSet;
00016 class Boolean;
00017 class Number;
00018 class String;
00019 
00030 class Value : public XPathNode
00031 {
00032 public:
00033     enum ValueType {
00034         ValueNull, ValueException,
00035         ValueNodeSet, ValueBoolean, ValueNumber, ValueString
00036     };
00037 
00038     Value() : tp(ValueNull) {}
00039     Value( const Value &res );
00040     virtual ~Value() {}
00041 
00042     bool isNull() const { return tp == ValueNull; }
00043     bool isException() const { return tp == ValueException; }
00044     bool isNodeSet() const { return tp == ValueNodeSet; }
00045     bool isBoolean() const { return tp == ValueBoolean; }
00046     bool isNumber() const { return tp == ValueNumber; }
00047     bool isString() const { return tp == ValueString; }
00048 
00049     ValueType type() const { return tp; }
00050 
00051     Exception toException();
00052     NodeSet toNodeSet();
00053     Boolean toBoolean();
00054     Number toNumber();
00055     String toString();
00056 
00057     virtual QString qstring() const;
00058     QCString toCString() const { return qstring().local8Bit(); }
00059 
00060 protected:
00061     Value( ValueType t ) : tp(t) {}
00062 
00063 private:
00064     ValueType tp;
00065 };
00066 
00070 class Exception : public Value
00071 {
00072 public:
00073     Exception();
00074     Exception( const Exception &ex );
00075     Exception( const QString &msg );
00076     virtual ~Exception();
00077 
00078     virtual QString qstring() const;
00079     QString message() const { return msg; }
00080 
00081 private:
00082     QString msg;
00083 };
00084 
00089 class NodeSet : public Value
00090 {
00091 public:
00092     NodeSet();
00093     NodeSet( const NodeSet &ns );
00094     virtual ~NodeSet();
00095 
00096     ulong count() const { return val.length(); }
00097     DOM::NodeList toNodeList() const { return val; }
00098 
00099 private:
00100     DOM::NodeList val;
00101 };
00102 
00107 class String : public Value
00108 {
00109 public:
00110     String() : Value(ValueString) {}
00111     String( const String &s ) : Value(ValueString), val(s.val) {}
00112     String( const QString &s ) : Value(ValueString), val(s) {}
00113     String( const char *s ) : Value(ValueString), val(s) {}
00114     virtual ~String() {}
00115 
00116     QString toQString() const { return val; }
00117 
00118     virtual QString qstring() const;
00119 
00120 private:
00121     QString val;
00122 };
00123 
00128 class Boolean : public Value
00129 {
00130 public:
00131     Boolean();
00132     Boolean( const Boolean &b );
00133     virtual ~Boolean();
00134 
00135     bool toBool() const { return val; }
00136 
00137     virtual QString qstring() const;
00138 
00139 private:
00140     bool val;
00141 };
00142 
00147 class Number : public Value
00148 {
00149 public:
00150     Number() : Value(ValueNumber), val(0.0L) {}
00151     Number( const Number &n ) : Value(ValueNumber), val(n.val) {}
00152 
00153     Number( int i ) : Value(ValueNumber), val(i) {}
00154     Number( uint i ) : Value(ValueNumber), val(i) {}
00155     Number( long l ) : Value(ValueNumber), val(l) {}
00156     Number( ulong l ) : Value(ValueNumber), val(l) {}
00157     Number( double d ) : Value(ValueNumber), val(d) {}
00158 
00159     virtual ~Number();
00160 
00161     double toDouble() const { return val; }
00162     int toInt() const { return (int) val; }
00163 
00164     virtual QString qstring() const;
00165 
00166 private:
00167     double val;
00168 };
00169 
00170 }; // namespace XPath
00171 
00172 #endif // XPATH_VALUE_H
00173 
00174 // Local Variables:
00175 // c-basic-offset: 4
00176 // End:

Generated at Sat Feb 15 02:18:35 2003 for 'KHTML::XPath' by doxygen1.2.9.1 written by Dimitri van Heesch, © 1997-2001