Update of /cvsroot/wpdev/wolfpack
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8083
Modified Files:
basics.cpp basics.h commands.cpp definitions.cpp
Log Message:
Documented elements and finished the .exportdefinitions command.
Index: basics.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/basics.cpp,v
retrieving revision 1.38
retrieving revision 1.39
diff -C2 -d -r1.38 -r1.39
*** basics.cpp 19 Aug 2004 01:55:55 -0000 1.38
--- basics.cpp 19 Aug 2004 13:53:03 -0000 1.39
***************
*** 30,34 ****
#include "coord.h"
#include "exceptions.h"
! #include "uobject.h"
// Library Includes
--- 30,34 ----
#include "coord.h"
#include "exceptions.h"
! #include "persistentobject.h"
// Library Includes
Index: basics.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/basics.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -d -r1.31 -r1.32
*** basics.h 19 Aug 2004 05:29:06 -0000 1.31
--- basics.h 19 Aug 2004 13:53:03 -0000 1.32
***************
*** 54,59 ****
unsigned int getNormalizedTime();
-
-
template <class T>
struct destroy_obj : std::unary_function<T, void>
--- 54,57 ----
Index: definitions.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/definitions.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** definitions.cpp 13 Aug 2004 08:55:25 -0000 1.14
--- definitions.cpp 19 Aug 2004 13:53:03 -0000 1.15
***************
*** 719,722 ****
--- 719,726 ----
}
+ /*
+ \object element
+ \description This object type represents an element in the definitions.
+ */
struct wpElement
{
***************
*** 740,743 ****
--- 744,754 ----
};
+ /*
+ \method element.hasattribute
+ \param name The name of the attribute
+ \return True or False.
+ \description This method checks if the element has an attribute with the
+ given name and returns True if so, False otherwise.
+ */
static PyObject* wpElement_hasattribute( wpElement* self, PyObject* args )
{
***************
*** 754,757 ****
--- 765,776 ----
}
+ /*
+ \method element.getattribute
+ \param name The name of the attribute.
+ \param default The return value if the attribute doesn't exist. Defaults to an empty string.
+ \return A unicode string containing the value of the attribute or the default value if the
+ attribute doesn't exist.
+ \description This method retrieves the string value of an attribute.
+ */
static PyObject* wpElement_getattribute( wpElement* self, PyObject* args )
{
***************
*** 774,787 ****
QString result = self->element->getAttribute( name, defvalue );
! if ( result == QString::null )
! {
! return PyUnicode_FromUnicode( ( Py_UNICODE * ) L"", 0 );
! }
! else
! {
! return PyUnicode_FromUnicode( ( Py_UNICODE * ) result.ucs2(), result.length() );
! }
}
static PyObject* wpElement_findchild( wpElement* self, PyObject* args )
{
--- 793,806 ----
QString result = self->element->getAttribute( name, defvalue );
! return QString2Python(result);
}
+ /*
+ \method element.findchild
+ \param name The name of the child element.
+ \return An <object id="element">element</object> object for the child or None.
+ \description This method tries to find a child element with the given name. If
+ none could be found, None is returned. Otherwise the child element is returned.
+ */
static PyObject* wpElement_findchild( wpElement* self, PyObject* args )
{
***************
*** 805,808 ****
--- 824,834 ----
}
+ /*
+ \method element.getchild
+ \param index The index of the child element.
+ \return An <object id="element">element</object> object for the child or None.
+ \description This method returns a child element at the given index or None if
+ the index exceeds the number of child elements - 1.
+ */
static PyObject* wpElement_getchild( wpElement* self, PyObject* args )
{
***************
*** 835,842 ****
--- 861,873 ----
cElement* element = self->element;
+ // \rproperty element.name A string containing the name of the element.
if ( !strcmp( name, "name" ) )
{
return PyString_FromString( element->name().data() );
}
+ /*
+ \rproperty element.parent An <object id="element">element</object> object for the parent of this element.
+ If there is no parent this property is None.
+ */
else if ( !strcmp( name, "parent" ) )
{
***************
*** 851,880 ****
}
}
! else if ( !strcmp( name, "value" ) )
! {
! QString value = element->value();
!
! if ( value == QString::null )
! {
! return PyUnicode_FromUnicode( ( Py_UNICODE * ) L"", 0 );
! }
! else
! {
! return PyUnicode_FromUnicode( ( Py_UNICODE * ) value.ucs2(), value.length() );
! }
}
else if ( !strcmp( name, "text" ) )
{
! QString value = element->text();
!
! if ( value == QString::null )
! {
! return PyUnicode_FromUnicode( ( Py_UNICODE * ) L"", 0 );
! }
! else
! {
! return PyUnicode_FromUnicode( ( Py_UNICODE * ) value.ucs2(), value.length() );
! }
}
else if ( !strcmp( name, "childcount" ) )
{
--- 882,904 ----
}
}
! /*
! \rproperty element.value The parsed value of this node.
! This converts hexadecimal numbers to decimal numers and
! computes random values. The result still is a unicode string.
! */
! else if ( !strcmp( name, "value" ) ) {
! return QString2Python(element->value());
}
+ /*
+ \rproperty element.text This is the text enclosed by this element.
+ */
else if ( !strcmp( name, "text" ) )
{
! return QString2Python(element->text());
}
+ /*
+ \rproperty element.childcount This is the number of children this
+ element has.
+ */
else if ( !strcmp( name, "childcount" ) )
{
Index: commands.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/commands.cpp,v
retrieving revision 1.256
retrieving revision 1.257
diff -C2 -d -r1.256 -r1.257
*** commands.cpp 19 Aug 2004 02:14:36 -0000 1.256
--- commands.cpp 19 Aug 2004 13:53:03 -0000 1.257
***************
*** 750,753 ****
--- 750,755 ----
}
+ Console::instance()->log(LOG_MESSAGE, QString("Exporting definitions to %1.\n").arg("categories.db"));
+
try {
// Create Tables
***************
*** 867,870 ****
--- 869,941 ----
driver.exec(sql);
}
+
+ categories.clear();
+ lastcategory = 0;
+
+ sections = Definitions::instance()->getSections(WPDT_LOCATION);
+ for (sectionIt = sections.begin(); sectionIt != sections.end(); ++sectionIt) {
+ const cElement *element = Definitions::instance()->getDefinition(WPDT_LOCATION, *sectionIt);
+
+ QString category = element->getAttribute("category");
+ if (category.isNull()) {
+ continue;
+ }
+
+ int pos = category.findRev('\\');
+
+ if (pos == -1) {
+ continue;
+ }
+
+ QString name = category.right(category.length() - (pos + 1));
+ category = category.left(pos);
+
+ // Create an id for the category
+ unsigned int categoryId;
+ if (!categories.contains(category)) {
+ ensureCategory(categories, lastcategory, category);
+ categoryId = lastcategory;
+ } else {
+ categoryId = categories[category];
+ }
+
+ Coord_cl coord;
+ parseCoordinates(element->text(), coord);
+ QString id = *sectionIt;
+
+ QString sql = QString("INSERT INTO locations VALUES(NULL,'%1',%2,%3,%4,%5,%6,'%7');")
+ .arg(name.replace("'", "''"))
+ .arg(categoryId)
+ .arg(coord.x)
+ .arg(coord.y)
+ .arg(coord.z)
+ .arg(coord.map)
+ .arg(id.replace("'", "''"));
+
+ driver.exec(sql);
+ }
+
+ // Ensure that all categories are in the list
+ for (categoriesIt = categories.begin(); categoriesIt != categories.end(); ++categoriesIt) {
+ unsigned int parent = 0;
+ int pos = categoriesIt.key().findRev('\\');
+ if (pos != -1) {
+ QString parentName = categoriesIt.key().left(pos);
+ if (categories.contains(parentName)) {
+ parent = categories[parentName];
+ }
+ }
+
+ QString name = categoriesIt.key();
+ name = name.right(name.length() - (pos + 1));
+
+ QString sql = QString("INSERT INTO locationcategories VALUES(%1,'%2',%3,0);")
+ .arg(categoriesIt.data())
+ .arg(name.replace("'", "''"))
+ .arg(parent);
+ driver.exec(sql);
+ }
+
+ socket->sysMessage("Finished exporting definitions to categories.db.");
} catch(const QString &e) {
socket->sysMessage(e);
|