Config_WidgetReader.h
Config_PointerMessage.h
Config_Common.h
+ Config_ValidatorMessage.h
)
SET(PROJECT_SOURCES
Config_WidgetReader.cpp
Config_PointerMessage.cpp
Config_Common.cpp
+ Config_ValidatorMessage.cpp
)
SET(XML_RESOURCES
*/
#include "Config_Common.h"
+#include <Config_Keywords.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
+#include <sstream> //for stringstream
+
bool isElementNode(xmlNodePtr theNode)
{
return theNode->type == XML_ELEMENT_NODE;
return false;
}
+bool getValidatorInfo(xmlNodePtr theNode,
+ std::string& outValidatorId,
+ std::list<std::string>& outValidatorParameters)
+{
+ //Validator id:
+ char* anIdProp = (char*) xmlGetProp(theNode, BAD_CAST _ID);
+ if (!anIdProp || anIdProp[0] == 0) {
+ return false;
+ }
+ outValidatorId = std::string(anIdProp);
+
+ //Validator parameters:
+ char* aParamProp = (char*) xmlGetProp(theNode, BAD_CAST VALIDATOR_PARAMETERS);
+ if (aParamProp && aParamProp[0] != 0) {
+ std::string aPropString = std::string(aParamProp);
+ std::stringstream aPropStringStream(aPropString);
+ char COMMA_DELIM = ',';
+ std::string aValidatorParameter;
+ while (std::getline(aPropStringStream, aValidatorParameter, ',')) {
+ outValidatorParameters.push_back(aValidatorParameter);
+ }
+ }
+ return true;
+}
+
std::string library(const std::string& theLibName)
{
std::string aLibName = theLibName;
#include "Config_def.h"
#include <string>
+#include <list>
#include <stdarg.h>
//>> Forward declaration of xmlNodePtr.
*/
CONFIG_EXPORT bool hasChild(xmlNodePtr theNode);
+/*
+ *
+ */
+CONFIG_EXPORT bool getValidatorInfo(xmlNodePtr theNode,
+ std::string& outValidatorId,
+ std::list<std::string>& outValidatorParameters);
+
/*!
\brief Convert the given parameter to the platform-specific library name.
myNestedFeatures = "";
}
+Config_FeatureMessage::~Config_FeatureMessage()
+{
+
+}
+
const std::string& Config_FeatureMessage::icon() const
{
return myIcon;
public:\r
//const Events_ID theID, const void* theSender = 0\r
CONFIG_EXPORT Config_FeatureMessage(const Events_ID theId, const void* theParent = 0);\r
+ CONFIG_EXPORT virtual ~Config_FeatureMessage();\r
\r
//Auto-generated getters/setters\r
CONFIG_EXPORT const std::string& icon() const;\r
#include <string>
#include <algorithm>
+#include <list>
#ifdef _DEBUG
#include <iostream>
//If a feature has xml definition for it's widget:
aMessage.setUseInput(hasChild(theNode));
aEvLoop->send(aMessage);
- }
//The m_last* variables always defined before fillFeature() call. XML is a tree.
- if (isNode(theNode, NODE_GROUP, NULL)) {
+ } else if (isNode(theNode, NODE_GROUP, NULL)) {
myLastGroup = getProperty(theNode, _ID);
- }
- if (isNode(theNode, NODE_WORKBENCH, NULL)) {
+ } else if (isNode(theNode, NODE_WORKBENCH, NULL)) {
myLastWorkbench = getProperty(theNode, _ID);
+ //Process SOURCE, VALIDATOR nodes.
}
- //Process SOURCE nodes.
Config_XMLReader::processNode(theNode);
}
bool Config_FeatureReader::processChildren(xmlNodePtr theNode)
{
- return isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL);
+ return isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NODE_FEATURE, NULL);
}
-void Config_FeatureReader::fillFeature(xmlNodePtr theRoot, Config_FeatureMessage& outFtMessage)
+void Config_FeatureReader::fillFeature(xmlNodePtr theNode,
+ Config_FeatureMessage& outFeatureMessage)
{
- outFtMessage.setId(getProperty(theRoot, _ID));
- outFtMessage.setPluginLibrary(myLibraryName);
- outFtMessage.setNestedFeatures(getProperty(theRoot, FEATURE_NESTED));
- bool isFtInternal = isInternalFeature(theRoot);
- outFtMessage.setInternal(isFtInternal);
- if(isFtInternal) {
+ outFeatureMessage.setId(getProperty(theNode, _ID));
+ outFeatureMessage.setPluginLibrary(myLibraryName);
+ outFeatureMessage.setNestedFeatures(getProperty(theNode, FEATURE_NESTED));
+
+ bool isInternal = isInternalFeature(theNode);
+ outFeatureMessage.setInternal(isInternal);
+ if(isInternal) {
//Internal feature has no visual representation.
return;
}
- outFtMessage.setText(getProperty(theRoot, FEATURE_TEXT));
- outFtMessage.setTooltip(getProperty(theRoot, FEATURE_TOOLTIP));
- outFtMessage.setIcon(getProperty(theRoot, FEATURE_ICON));
- outFtMessage.setKeysequence(getProperty(theRoot, FEATURE_KEYSEQUENCE));
- outFtMessage.setGroupId(myLastGroup);
- outFtMessage.setWorkbenchId(myLastWorkbench);
+ outFeatureMessage.setText(getProperty(theNode, FEATURE_TEXT));
+ outFeatureMessage.setTooltip(getProperty(theNode, FEATURE_TOOLTIP));
+ outFeatureMessage.setIcon(getProperty(theNode, FEATURE_ICON));
+ outFeatureMessage.setKeysequence(getProperty(theNode, FEATURE_KEYSEQUENCE));
+ outFeatureMessage.setGroupId(myLastGroup);
+ outFeatureMessage.setWorkbenchId(myLastWorkbench);
}
-bool Config_FeatureReader::isInternalFeature(xmlNodePtr theRoot)
+bool Config_FeatureReader::isInternalFeature(xmlNodePtr theNode)
{
- std::string prop = getProperty(theRoot, FEATURE_INTERNAL);
+ std::string prop = getProperty(theNode, FEATURE_INTERNAL);
std::transform(prop.begin(), prop.end(), prop.begin(), ::tolower);
if(prop.empty() || prop == "false" || prop == "0") {
return false;
const static char* NODE_GROUP = "group";
const static char* NODE_FEATURE = "feature";
const static char* NODE_SOURCE = "source";
+const static char* NODE_VALIDATOR = "validator";
//Widgets
const static char* WDG_DOUBLEVALUE = "doublevalue";
const static char* WDG_FEATURE_OR_ATTRIBUTE_SELECTOR = "feature_or_attribute_selector";
const static char* WDG_DOUBLEVALUE_EDITOR = "doublevalue_editor";
+//Common Widget's or Feature's Properties
const static char* _ID = "id";
-//const static char* WORKBENCH_ID = "id";
-//const static char* GROUP_ID = "id";
-//const static char* FEATURE_ID = "id";
-const static char* FEATURE_TEXT = "title";
const static char* FEATURE_TOOLTIP = "tooltip";
const static char* FEATURE_ICON = "icon";
+const static char* FEATURE_TEXT = "title";
const static char* FEATURE_KEYSEQUENCE = "keysequence";
const static char* FEATURE_NESTED = "nested";
const static char* FEATURE_INTERNAL = "internal";
-const static char* SOURCE_FILE = "path";
-
+// TODO: Rename
const static char* PREVIOUS_FEATURE_PARAM = "previous_feature_param";
+const static char* ANY_WDG_TOOLTIP = FEATURE_TOOLTIP;
+const static char* ANY_WDG_ICON = FEATURE_ICON;
+const static char* ANY_WDG_LABEL = "label";
+
+const static char* SOURCE_FILE = "path";
+const static char* VALIDATOR_PARAMETERS = "parameters";
// doublevalue properties:
const static char* INFO_WDG_TEXT = FEATURE_TEXT;
--- /dev/null
+/*
+ * Config_ValidatorMessage.cpp
+ *
+ * Created on: 08 èþëÿ 2014 ã.
+ * Author: sbh
+ */
+
+#include <Config_ValidatorMessage.h>
+
+Config_ValidatorMessage::Config_ValidatorMessage(const Events_ID theId, const void* theParent)
+: Events_Message(theId, theParent)
+{
+ myValidatorId = "";
+ myFeatureId = "";
+ myAttributeId = "";
+}
+
+Config_ValidatorMessage::~Config_ValidatorMessage()
+{
+}
+
+//static const const char* Config_ValidatorMessage::UID() const
+//{
+// return "ValidatorMessage";
+//}
+
+const std::string& Config_ValidatorMessage::validatorId() const
+{
+ return myValidatorId;
+}
+
+const std::string& Config_ValidatorMessage::featureId() const
+{
+ return myFeatureId;
+}
+
+const std::string& Config_ValidatorMessage::attributeId() const
+{
+ return myAttributeId;
+}
+
+const std::list<std::string>& Config_ValidatorMessage::parameters() const
+{
+ return myVaidatorParameters;
+}
+
+bool Config_ValidatorMessage::isValid() const
+{
+ return !myValidatorId.empty();
+}
+
+void Config_ValidatorMessage::setValidatorId(const std::string& validatorId)
+{
+ myValidatorId = validatorId;
+}
+
+void Config_ValidatorMessage::setValidatorParameters(const std::list<std::string>& parameters)
+{
+ myVaidatorParameters = parameters;
+}
+
+void Config_ValidatorMessage::setFeatureId(const std::string& theId)
+{
+ myFeatureId = theId;
+}
+
+void Config_ValidatorMessage::setAttributeId(const std::string& theId)
+{
+ myAttributeId = theId;
+}
--- /dev/null
+/*
+ * Config_ValidatorMessage.h
+ *
+ * Created on: 08 èþëÿ 2014 ã.
+ * Author: sbh
+ */
+
+#ifndef Config_ValidatorMessage_H_
+#define Config_ValidatorMessage_H_
+
+#include <Events_Message.h>
+#include <Config_def.h>
+
+#include <list>
+#include <string>
+
+/// Event ID that feature is loaded (comes with Config_FeatureMessage)
+static const char * EVENT_VALIDATOR_LOADED = "ValidatorLoaded";
+
+class Config_ValidatorMessage : public Events_Message
+{
+ std::string myValidatorId;
+ std::string myFeatureId;
+ std::string myAttributeId;
+ std::list<std::string> myVaidatorParameters;
+
+public:
+ CONFIG_EXPORT Config_ValidatorMessage(const Events_ID theId, const void* theParent = 0);
+ CONFIG_EXPORT virtual ~Config_ValidatorMessage();
+
+ //CONFIG_EXPORT static const char* UID() const;
+
+ CONFIG_EXPORT const std::string& validatorId() const;
+ const std::string& featureId() const;
+ const std::string& attributeId() const;
+ CONFIG_EXPORT const std::list<std::string>& parameters() const;
+ CONFIG_EXPORT bool isValid() const;
+
+ CONFIG_EXPORT void setValidatorId(const std::string& theId);
+ CONFIG_EXPORT void setFeatureId(const std::string& theId);
+ CONFIG_EXPORT void setAttributeId(const std::string& theId);
+ CONFIG_EXPORT void setValidatorParameters(const std::list<std::string>& parameters);
+};
+
+#endif /* Config_ValidatorMessage_H_ */
std::string Config_WidgetAPI::widgetId() const
{
- return getProperty("id");
+ return getProperty(_ID);
}
-std::string Config_WidgetAPI::widgetTooltip() const
+std::string Config_WidgetAPI::widgetIcon() const
{
- return getProperty("tooltip");
+ return getProperty(ANY_WDG_ICON);
}
-std::string Config_WidgetAPI::widgetIcon() const
+std::string Config_WidgetAPI::widgetLabel() const
{
- return getProperty("icon");
+ return getProperty(ANY_WDG_LABEL);
}
-std::string Config_WidgetAPI::widgetLabel() const
+std::string Config_WidgetAPI::widgetTooltip() const
{
- return getProperty("label");
+ return getProperty(ANY_WDG_TOOLTIP);
}
{
if (isNode(theNode, NODE_FEATURE, NULL)) {
std::string aNodeName = getProperty(theNode, _ID);
- myWidgetCache[aNodeName] = dumpNode(theNode);;
+ myWidgetCache[aNodeName] = dumpNode(theNode);
myDescriptionCache[aNodeName] = getProperty(theNode, FEATURE_TEXT);
}
//Process SOURCE nodes.
if (isNode(aChildrenNode, NODE_SOURCE, NULL)) {
Config_XMLReader aSourceReader =
Config_XMLReader(getProperty(aChildrenNode, SOURCE_FILE));
+ //Register all validators in the sourced xml
+ aSourceReader.readAll();
+ //Dump!
xmlNodePtr aSourceRoot = aSourceReader.findRoot();
int size = xmlNodeDump(buffer, aSourceRoot->doc, aSourceRoot, 0, 1);
} else {
#include <Config_XMLReader.h>
#include <Config_Keywords.h>
#include <Config_Common.h>
+#include <Config_ValidatorMessage.h>
#include <Events_Loop.h>
#include <libxml/parser.h>
#ifdef _DEBUG
std::cout << "Config_XMLReader::sourced node: " << aSourceFile << std::endl;
#endif
+ } else if (isNode(theNode, NODE_VALIDATOR, NULL)) {
+ processValidator(theNode);
}
}
*/
xmlNodePtr Config_XMLReader::findRoot()
{
- myXmlDoc = xmlParseFile(myDocumentPath.c_str());
+ if (myXmlDoc == NULL) {
+ myXmlDoc = xmlParseFile(myDocumentPath.c_str());
+ }
if (myXmlDoc == NULL) {
#ifdef _DEBUG
std::cout << "Config_XMLReader::import: " << "Document " << myDocumentPath
return;
xmlNodePtr aNode = theParent->xmlChildrenNode;
for(; aNode; aNode = aNode->next) {
- processNode(aNode);
+ //Still no text processing in features...
+ if(isElementNode(aNode)) {
+ processNode(aNode);
+ }
if (processChildren(aNode)) {
readRecursively(aNode);
}
/*
* Returns named property for a given node as std::string.
*/
-std::string Config_XMLReader::getProperty(xmlNodePtr theNode, const char* name)
+std::string Config_XMLReader::getProperty(xmlNodePtr theNode, const char* theName)
{
std::string result = "";
- char* aPropChars = (char*) xmlGetProp(theNode, BAD_CAST name);
+ char* aPropChars = (char*) xmlGetProp(theNode, BAD_CAST theName);
if (!aPropChars || aPropChars[0] == 0)
return result;
result = std::string(aPropChars);
return result;
}
+void Config_XMLReader::processValidator(xmlNodePtr theNode)
+{
+ Events_ID aValidatoEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED);
+ Events_Loop* aEvLoop = Events_Loop::loop();
+ Config_ValidatorMessage aMessage(aValidatoEvent, this);
+ std::string aValidatorId;
+ std::list<std::string> aValidatorParameters;
+ getValidatorInfo(theNode, aValidatorId, aValidatorParameters);
+ aMessage.setValidatorId(aValidatorId);
+ aMessage.setValidatorParameters(aValidatorParameters);
+ if(isNode(theNode->parent, NODE_FEATURE, NULL)) {
+ aMessage.setFeatureId(getProperty(theNode->parent, _ID));
+ } else {
+ xmlNodePtr aWdgNode = theNode->parent;
+ aMessage.setAttributeId(getProperty(aWdgNode, _ID));
+ aMessage.setFeatureId(getProperty(aWdgNode->parent, _ID));
+ }
+ aEvLoop->send(aMessage);
+}
xmlNodePtr node(void* theNode);
std::string getProperty(xmlNodePtr theNode, const char* property);
+ void processValidator(xmlNodePtr theNode);
protected:
std::string myDocumentPath;