[dss-commits] digitalSTROM Server branch, master, updated. c7000db55ee2a8a84d66a0aa9e0c1fa6e163bdb5

git version control dss-commits at forum.digitalstrom.org
Fri Dec 11 15:26:21 CET 2009


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "digitalSTROM Server".

The branch, master has been updated
       via  c7000db55ee2a8a84d66a0aa9e0c1fa6e163bdb5 (commit)
      from  422eccecc7303543ba93b798bd6f6de23c07c56d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit c7000db55ee2a8a84d66a0aa9e0c1fa6e163bdb5
Author: Patrick Stählin <pstaehlin at futurelab.ch>
Date:   Fri Dec 11 15:07:32 2009 +0100

    Added flags to PropertyNode
    
    References #233

-----------------------------------------------------------------------

Changes:
diff --git a/core/propertysystem.cpp b/core/propertysystem.cpp
index 3e96d14..b26dd1e 100644
--- a/core/propertysystem.cpp
+++ b/core/propertysystem.cpp
@@ -131,7 +131,6 @@ namespace dss {
     return versionOK;
   } // loadFromXML
 
-
   bool PropertySystem::saveToXML(const std::string& _fileName, PropertyNodePtr _rootNode) const {
     int rc;
     xmlTextWriterPtr writer;
@@ -160,7 +159,7 @@ namespace dss {
       return false;
     }
 
-    root->saveAsXML(writer);
+    root->saveAsXML(writer, 0);
 
     rc = xmlTextWriterEndElement(writer);
     if(rc < 0) {
@@ -177,7 +176,6 @@ namespace dss {
     return true;
   } // saveToXML
 
-
   PropertyNodePtr PropertySystem::getProperty(const std::string& _propPath) const {
     if(_propPath[ 0 ] != '/') {
       return PropertyNodePtr();
@@ -190,7 +188,6 @@ namespace dss {
     return m_RootNode->getProperty(propPath);
   } // getProperty
 
-
   PropertyNodePtr PropertySystem::createProperty(const std::string& _propPath) {
     if(_propPath[ 0 ] != '/') {
       return PropertyNodePtr();
@@ -286,7 +283,8 @@ namespace dss {
       m_Name(_name),
       m_LinkedToProxy(false),
       m_Aliased(false),
-      m_Index(_index)
+      m_Index(_index),
+      m_Flags(Readable | Writeable)
   {
     memset(&m_PropVal, '\0', sizeof(aPropertyValue));
   } // ctor
@@ -754,7 +752,7 @@ namespace dss {
     }
   }
 
-  bool PropertyNode::saveAsXML(xmlTextWriterPtr _writer) {
+  bool PropertyNode::saveAsXML(xmlTextWriterPtr _writer, const int _flagsMask) {
     int rc = xmlTextWriterStartElement(_writer, (xmlChar*)"property");
     if(rc < 0) {
       return false;
@@ -776,8 +774,10 @@ namespace dss {
 
     for(PropertyList::iterator it = m_ChildNodes.begin();
          it != m_ChildNodes.end(); ++it) {
-      if(!(*it)->saveAsXML(_writer)) {
-        return false;
+      if((_flagsMask == Flag(0)) || (*it)->hasFlag(Flag(_flagsMask))) {
+        if(!(*it)->saveAsXML(_writer, _flagsMask)) {
+          return false;
+        }
       }
     }
 
diff --git a/core/propertysystem.h b/core/propertysystem.h
index faa6e22..9748b37 100644
--- a/core/propertysystem.h
+++ b/core/propertysystem.h
@@ -75,7 +75,7 @@ namespace dss {
     ~PropertySystem();
 
     /** Loads a subtree from XML.
-     * Everything in the XML has to be relatove to _rootNode. */
+     * Everything in the XML has to be relative to _rootNode. */
     bool loadFromXML(const std::string& _fileName, PropertyNodePtr _rootNode);
     /** Saves a subtree to XML. */
     bool saveToXML(const std::string& _fileName, PropertyNodePtr _rootNode) const;
@@ -325,6 +325,12 @@ namespace dss {
 
   /** The heart of the PropertySystem. */
   class PropertyNode : public boost::enable_shared_from_this<PropertyNode> {
+  public:
+    enum Flag {
+      Readable = 1 << 0, /**< Node is readable */
+      Writeable = 1 << 1, /**< Node is writeable */
+      Archive = 1 << 2 /**< Node will get written to XML (hint only) */
+    };
   private:
     aPropertyValue m_PropVal;
     union {
@@ -342,6 +348,7 @@ namespace dss {
     bool m_Aliased;
     PropertyNode* m_AliasTarget;
     int m_Index;
+    int m_Flags;
   private:
     void clearValue();
 
@@ -403,6 +410,9 @@ namespace dss {
     /** Returns the type of the property. */
     aValueType getValueType();
 
+    bool hasFlag(Flag _flag) const { return (m_Flags & _flag) == _flag; }
+    void setFlag(Flag _flag, bool _value) { _value ? m_Flags |= _flag : m_Flags &= ~_flag; }
+
     void alias(PropertyNodePtr _target);
 
     // proxy support
@@ -461,7 +471,7 @@ namespace dss {
     }
   public:
     /** Writes the node to XML */
-    bool saveAsXML(xmlTextWriterPtr _writer);
+    bool saveAsXML(xmlTextWriterPtr _writer, const int _flagsMask);
     /** Loads the node from XML */
     bool loadFromNode(xmlNode* _pNode);
   }; // PropertyNode
diff --git a/tests/propertysystemtests.cpp b/tests/propertysystemtests.cpp
index 824b5bf..988ddea 100644
--- a/tests/propertysystemtests.cpp
+++ b/tests/propertysystemtests.cpp
@@ -258,4 +258,19 @@ BOOST_AUTO_TEST_CASE(testListener) {
   BOOST_CHECK_EQUAL(propSys->getBoolValue(kTriggerPath), true);
 } // testListener
 
+BOOST_AUTO_TEST_CASE(testFlags) {
+  boost::scoped_ptr<PropertySystem> propSys(new PropertySystem());
+  PropertyNodePtr node = propSys->createProperty("/testing");
+
+  BOOST_CHECK(node->hasFlag(PropertyNode::Readable));
+  BOOST_CHECK(node->hasFlag(PropertyNode::Writeable));
+  BOOST_CHECK(!node->hasFlag(PropertyNode::Archive));
+
+  node->setFlag(PropertyNode::Archive, false);
+  BOOST_CHECK(!node->hasFlag(PropertyNode::Archive));
+
+  node->setFlag(PropertyNode::Archive, true);
+  BOOST_CHECK(node->hasFlag(PropertyNode::Archive));
+} // testFlags
+
 BOOST_AUTO_TEST_SUITE_END()


hooks/post-receive
-- 
digitalSTROM Server


More information about the dss-commits mailing list