[Ocipl-commits] SF.net SVN: ocipl: [40] trunk/xmlstorage
Brought to you by:
martinfuchs
|
From: <mar...@us...> - 2008-02-09 10:10:57
|
Revision: 40
http://ocipl.svn.sourceforge.net/ocipl/?rev=40&view=rev
Author: martinfuchs
Date: 2008-02-09 02:10:53 -0800 (Sat, 09 Feb 2008)
Log Message:
-----------
update to XMLStorage version 1.3
Modified Paths:
--------------
trunk/xmlstorage/xmlstorage-license.txt
trunk/xmlstorage/xmlstorage.cpp
trunk/xmlstorage/xmlstorage.h
trunk/xmlstorage/xs-native.cpp
Modified: trunk/xmlstorage/xmlstorage-license.txt
===================================================================
--- trunk/xmlstorage/xmlstorage-license.txt 2008-02-04 09:35:35 UTC (rev 39)
+++ trunk/xmlstorage/xmlstorage-license.txt 2008-02-09 10:10:53 UTC (rev 40)
@@ -2,7 +2,7 @@
//
// XML storage classes
//
- // Copyright (c) 2004, 2005, 2006, 2007 Martin Fuchs <mar...@gm...>
+ // Copyright (c) 2004, 2005, 2006, 2007, 2008 Martin Fuchs <mar...@gm...>
//
Modified: trunk/xmlstorage/xmlstorage.cpp
===================================================================
--- trunk/xmlstorage/xmlstorage.cpp 2008-02-04 09:35:35 UTC (rev 39)
+++ trunk/xmlstorage/xmlstorage.cpp 2008-02-09 10:10:53 UTC (rev 40)
@@ -56,7 +56,11 @@
const LPCXSSTR XS_FLOATFMT = XS_FLOATFMT_STR;
#endif
+const XS_String XS_KEY = XS_KEY_STR;
+const XS_String XS_VALUE = XS_VALUE_STR;
+const XS_String XS_PROPERTY = XS_PROPERTY_STR;
+
/// remove escape characters from zero terminated string
static std::string unescape(const char* s, char b, char e)
{
@@ -216,7 +220,7 @@
}
-XPath::XPath(const char* path)
+void XPath::init(const char* path)
{
// Is this an absolute path?
if (*path == '/') {
@@ -919,5 +923,91 @@
XS_String XMLWriter::s_empty_attr;
+void XMLWriter::create(const XS_String& name)
+{
+ if (!_stack.empty()) {
+ StackEntry& last = _stack.top();
+ if (last._state < PRE_CLOSED) {
+ write_attributes(last);
+ close_pre(last);
+ }
+
+ ++last._children;
+ }
+
+ StackEntry entry;
+ entry._node_name = name;
+ _stack.push(entry);
+
+ write_pre(entry);
+}
+
+bool XMLWriter::back()
+{
+ if (!_stack.empty()) {
+ write_post(_stack.top());
+
+ _stack.pop();
+ return true;
+ } else
+ return false;
+}
+
+void XMLWriter::close_pre(StackEntry& entry)
+{
+ _out << '>';
+
+ entry._state = PRE_CLOSED;
+}
+
+void XMLWriter::write_pre(StackEntry& entry)
+{
+ if (_format._pretty >= PRETTY_LINEFEED)
+ _out << _format._endl;
+
+ if (_format._pretty == PRETTY_INDENT)
+ for(size_t i=_stack.size(); --i>0; )
+ _out << XML_INDENT_SPACE;
+
+ _out << '<' << EncodeXMLString(entry._node_name);
+ //entry._state = PRE;
+}
+
+void XMLWriter::write_attributes(StackEntry& entry)
+{
+ for(AttrMap::const_iterator it=entry._attributes.begin(); it!=entry._attributes.end(); ++it)
+ _out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\"";
+
+ entry._state = ATTRIBUTES;
+}
+
+void XMLWriter::write_post(StackEntry& entry)
+{
+ if (entry._state < ATTRIBUTES)
+ write_attributes(entry);
+
+ if (entry._children || !entry._content.empty()) {
+ if (entry._state < PRE_CLOSED)
+ close_pre(entry);
+
+ _out << entry._content;
+ //entry._state = CONTENT;
+
+ if (_format._pretty>=PRETTY_LINEFEED && entry._content.empty())
+ _out << _format._endl;
+
+ if (_format._pretty==PRETTY_INDENT && entry._content.empty())
+ for(size_t i=_stack.size(); --i>0; )
+ _out << XML_INDENT_SPACE;
+
+ _out << "</" << EncodeXMLString(entry._node_name) << ">";
+ } else {
+ _out << "/>";
+ }
+
+ entry._state = POST;
+}
+
+
} // namespace XMLStorage
Modified: trunk/xmlstorage/xmlstorage.h
===================================================================
--- trunk/xmlstorage/xmlstorage.h 2008-02-04 09:35:35 UTC (rev 39)
+++ trunk/xmlstorage/xmlstorage.h 2008-02-09 10:10:53 UTC (rev 40)
@@ -202,7 +202,7 @@
#endif
#ifdef __BORLANDC__
-#define _strcmpi strcmpi
+#define _stricmp stricmp
#endif
@@ -395,6 +395,10 @@
#define XS_INTFMT_STR XS_TEXT("%d")
#define XS_FLOATFMT_STR XS_TEXT("%f")
+#define XS_KEY_STR XS_TEXT("key")
+#define XS_VALUE_STR XS_TEXT("value")
+#define XS_PROPERTY_STR XS_TEXT("property")
+
// work around GCC's wide string constant bug
#ifdef __GNUC__
extern const LPCXSSTR XS_EMPTY;
@@ -410,7 +414,11 @@
#define XS_FLOATFMT XS_FLOATFMT_STR
#endif
+extern const XS_String XS_KEY;
+extern const XS_String XS_VALUE;
+extern const XS_String XS_PROPERTY;
+
#ifndef XS_STRING_UTF8
// from UTF-8 to XS internal string encoding
@@ -812,8 +820,11 @@
struct XPath : std::list<XPathElement>
{
- XPath(const char* path);
+ XPath(const char* path) {init(path);}
+ XPath(const std::string path) {init(path.c_str());}
+ void init(const char* path);
+
bool _absolute;
};
@@ -1257,6 +1268,7 @@
struct iterator
{
typedef XMLNode::Children::iterator BaseIterator;
+ typedef iterator myType;
iterator(BaseIterator begin, BaseIterator end, const XS_String& filter_name)
: _cur(begin),
@@ -1281,7 +1293,7 @@
return *_cur;
}
- iterator& operator++()
+ myType& operator++()
{
++_cur;
search_next();
@@ -1289,9 +1301,9 @@
return *this;
}
- iterator operator++(int)
+ myType operator++(int)
{
- iterator ret = *this;
+ myType ret = *this;
++_cur;
search_next();
@@ -1299,14 +1311,14 @@
return ret;
}
- bool operator==(const BaseIterator& other) const
+ bool operator==(const myType& other) const
{
- return _cur == other;
+ return _cur == other._cur;
}
- bool operator!=(const BaseIterator& other) const
+ bool operator!=(const myType& other) const
{
- return _cur != other;
+ return _cur != other._cur;
}
protected:
@@ -1356,6 +1368,7 @@
struct const_iterator
{
typedef XMLNode::Children::const_iterator BaseIterator;
+ typedef const_iterator myType;
const_iterator(BaseIterator begin, BaseIterator end, const XS_String& filter_name)
: _cur(begin),
@@ -1375,7 +1388,7 @@
return *_cur;
}
- const_iterator& operator++()
+ myType& operator++()
{
++_cur;
search_next();
@@ -1383,9 +1396,9 @@
return *this;
}
- const_iterator operator++(int)
+ myType operator++(int)
{
- const_iterator ret = *this;
+ myType ret = *this;
++_cur;
search_next();
@@ -1393,14 +1406,14 @@
return ret;
}
- bool operator==(const BaseIterator& other) const
+ bool operator==(const myType& other) const
{
- return _cur == other;
+ return _cur == other._cur;
}
- bool operator!=(const BaseIterator& other) const
+ bool operator!=(const myType& other) const
{
- return _cur != other;
+ return _cur != other._cur;
}
protected:
@@ -1686,6 +1699,15 @@
XS_String& str() {return *_cur;}
const XS_String& str() const {return *_cur;}
+ // property (key/value pair) setter functions
+ void set_property(const XS_String& key, int value, const XS_String& name=XS_PROPERTY);
+ void set_property(const XS_String& key, double value, const XS_String& name=XS_PROPERTY);
+ void set_property(const XS_String& key, const XS_String& value, const XS_String& name=XS_PROPERTY);
+ void set_property(const XS_String& key, const struct XMLBool& value, const XS_String& name=XS_PROPERTY);
+
+ void set_property(const XS_String& key, const char* value, const XS_String& name=XS_PROPERTY)
+ {set_property(key, XS_String(value), name);}
+
protected:
XMLNode* _root;
XMLNode* _cur;
@@ -1815,7 +1837,7 @@
XMLBool(LPCXSSTR value, bool def=false)
{
- if (value && *value)
+ if (value && *value)//@@ also handle white space and return def instead of false
_value = !XS_icmp(value, XS_TRUE);
else
_value = def;
@@ -1905,7 +1927,7 @@
XMLInt(LPCXSSTR value, int def=0)
{
- if (value && *value)
+ if (value && *value)//@@ also handle white space and return def instead of 0
_value = XS_toi(value);
else
_value = def;
@@ -1930,7 +1952,7 @@
{
XS_CHAR buffer[32];
XS_snprintf(buffer, COUNTOF(buffer), XS_INTFMT, _value);
- return buffer;
+ return XS_String(buffer);
}
protected:
@@ -1986,7 +2008,7 @@
{
LPTSTR end;
- if (value && *value)
+ if (value && *value)//@@ also handle white space and return def instead of 0
_value = XS_tod(value, &end);
else
_value = def;
@@ -2012,7 +2034,7 @@
{
XS_CHAR buffer[32];
XS_snprintf(buffer, COUNTOF(buffer), XS_FLOATFMT, _value);
- return buffer;
+ return XS_String(buffer);
}
protected:
@@ -2160,6 +2182,141 @@
}
+inline void XMLPos::set_property(const XS_String& key, int value, const XS_String& name)
+{
+ smart_create(name, XS_KEY, key);
+ XMLIntRef(_cur, XS_VALUE) = value;
+ back();
+}
+
+inline void XMLPos::set_property(const XS_String& key, double value, const XS_String& name)
+{
+ smart_create(name, XS_KEY, key);
+ XMLDoubleRef(_cur, XS_VALUE) = value;
+ back();
+}
+
+inline void XMLPos::set_property(const XS_String& key, const XS_String& value, const XS_String& name)
+{
+ smart_create(name, XS_KEY, key);
+ put(XS_VALUE, value);
+ back();
+}
+
+inline void XMLPos::set_property(const XS_String& key, const XMLBool& value, const XS_String& name)
+{
+ smart_create(name, XS_KEY, key);
+ XMLBoolRef(_cur, XS_VALUE) = value;
+ back();
+}
+
+
+ /// a key/value pair for property data access
+struct XMLProperty {
+ XMLProperty(const XMLNode* node)
+ : _key(node->get(XS_KEY)),
+ _value(node->get(XS_VALUE))
+ {
+ }
+
+ XS_String _key;
+ XS_String _value;
+};
+
+
+ /// utility class to read property settings from a XML tree
+struct XMLPropertyReader
+{
+ XMLPropertyReader(const XMLNode::Children& children)
+ : _filter(children, XS_PROPERTY),
+ _begin(_filter.begin(), _filter.end()),
+ _end(_filter.end(), _filter.end())
+ {
+ }
+
+ XMLPropertyReader(const XMLNode* node)
+ : _filter(node, XS_PROPERTY),
+ _begin(_filter.begin(), _filter.end()),
+ _end(_filter.end(), _filter.end())
+ {
+ }
+
+ /// internal iterator class
+ struct const_iterator
+ {
+ typedef const_XMLChildrenFilter::const_iterator BaseIterator;
+ typedef const_iterator myType;
+
+ const_iterator(BaseIterator begin, BaseIterator end)
+ : _cur(begin),
+ _end(end)
+ {
+ }
+
+ operator BaseIterator()
+ {
+ return _cur;
+ }
+
+ XMLProperty operator*() const
+ {
+ return XMLProperty(*_cur);
+ }
+
+ const XMLNode* get_node() const
+ {
+ return *_cur;
+ }
+
+ myType& operator++()
+ {
+ ++_cur;
+
+ return *this;
+ }
+
+ myType operator++(int)
+ {
+ myType ret = *this;
+
+ ++_cur;
+
+ return ret;
+ }
+
+ bool operator==(const myType& other) const
+ {
+ return _cur == other._cur;
+ }
+
+ bool operator!=(const myType& other) const
+ {
+ return _cur != other._cur;
+ }
+
+ protected:
+ BaseIterator _cur;
+ BaseIterator _end;
+ };
+
+ const_iterator begin()
+ {
+ return _begin;
+ }
+
+ const_iterator end()
+ {
+ return _end;
+ }
+
+protected:
+ const_XMLChildrenFilter _filter;
+
+ const_iterator _begin;
+ const_iterator _end;
+};
+
+
#ifdef _MSC_VER
#pragma warning(disable: 4355)
#endif
@@ -2664,38 +2821,11 @@
}
/// create node and move to it
- void create(const XS_String& name)
- {
- if (!_stack.empty()) {
- StackEntry& last = _stack.top();
+ void create(const XS_String& name);
- if (last._state < PRE_CLOSED) {
- write_attributes(last);
- close_pre(last);
- }
-
- ++last._children;
- }
-
- StackEntry entry;
- entry._node_name = name;
- _stack.push(entry);
-
- write_pre(entry);
- }
-
/// go back to previous position
- bool back()
- {
- if (!_stack.empty()) {
- write_post(_stack.top());
+ bool back();
- _stack.pop();
- return true;
- } else
- return false;
- }
-
/// attribute setting
void put(const XS_String& attr_name, const XS_String& value)
{
@@ -2745,60 +2875,10 @@
static XS_String s_empty_attr;
- void close_pre(StackEntry& entry)
- {
- _out << '>';
-
- entry._state = PRE_CLOSED;
- }
-
- void write_pre(StackEntry& entry)
- {
- if (_format._pretty >= PRETTY_LINEFEED)
- _out << _format._endl;
-
- if (_format._pretty == PRETTY_INDENT)
- for(size_t i=_stack.size(); --i>0; )
- _out << XML_INDENT_SPACE;
-
- _out << '<' << EncodeXMLString(entry._node_name);
- //entry._state = PRE;
- }
-
- void write_attributes(StackEntry& entry)
- {
- for(AttrMap::const_iterator it=entry._attributes.begin(); it!=entry._attributes.end(); ++it)
- _out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\"";
-
- entry._state = ATTRIBUTES;
- }
-
- void write_post(StackEntry& entry)
- {
- if (entry._state < ATTRIBUTES)
- write_attributes(entry);
-
- if (entry._children || !entry._content.empty()) {
- if (entry._state < PRE_CLOSED)
- close_pre(entry);
-
- _out << entry._content;
- //entry._state = CONTENT;
-
- if (_format._pretty>=PRETTY_LINEFEED && entry._content.empty())
- _out << _format._endl;
-
- if (_format._pretty==PRETTY_INDENT && entry._content.empty())
- for(size_t i=_stack.size(); --i>0; )
- _out << XML_INDENT_SPACE;
-
- _out << "</" << EncodeXMLString(entry._node_name) << ">";
- } else {
- _out << "/>";
- }
-
- entry._state = POST;
- }
+ void close_pre(StackEntry& entry);
+ void write_pre(StackEntry& entry);
+ void write_attributes(StackEntry& entry);
+ void write_post(StackEntry& entry);
};
Modified: trunk/xmlstorage/xs-native.cpp
===================================================================
--- trunk/xmlstorage/xs-native.cpp 2008-02-04 09:35:35 UTC (rev 39)
+++ trunk/xmlstorage/xs-native.cpp 2008-02-09 10:10:53 UTC (rev 40)
@@ -1,8 +1,8 @@
//
- // XML storage C++ classes version 1.2
+ // XML storage C++ classes version 1.3
//
- // Copyright (c) 2006, 2007 Martin Fuchs <mar...@gm...>
+ // Copyright (c) 2006, 2007, 2008 Martin Fuchs <mar...@gm...>
//
/// \file xs-native.cpp
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|