From ffd61c58d3fe5a0d21a36c0b1244c513e1d7d35f Mon Sep 17 00:00:00 2001 From: srn Date: Fri, 3 Feb 2006 14:38:46 +0000 Subject: [PATCH] Changed IParameters interafce --- src/SALOMEDS/SALOMEDS_IParameters.cxx | 102 ++++++++++++++++++++++++-- src/SALOMEDS/SALOMEDS_IParameters.hxx | 27 ++++++- 2 files changed, 119 insertions(+), 10 deletions(-) diff --git a/src/SALOMEDS/SALOMEDS_IParameters.cxx b/src/SALOMEDS/SALOMEDS_IParameters.cxx index 1d98810aa..bc51470d7 100644 --- a/src/SALOMEDS/SALOMEDS_IParameters.cxx +++ b/src/SALOMEDS/SALOMEDS_IParameters.cxx @@ -19,6 +19,8 @@ #include "SALOMEDS_IParameters.hxx" #include +#include + using namespace std; #define PT_INTEGER 0 @@ -41,46 +43,132 @@ SALOMEDS_IParameters::SALOMEDS_IParameters(const _PTR(AttributeParameter)& ap) int SALOMEDS_IParameters::append(const string& listName, const string& value) { - return -1; + if(!_ap) return -1; + vector v; + if(!_ap->IsSet(listName, PT_STRARRAY)) _ap->SetStrArray(listName, v); + v = _ap->GetStrArray(listName); + v.push_back(value); + _ap->SetStrArray(listName, v); + return (v.size()-1); } int SALOMEDS_IParameters::nbValues(const string& listName) { - return -1; + if(!_ap) return -1; + if(!_ap->IsSet(listName, PT_STRARRAY)) return 0; + vector v = _ap->GetStrArray(listName); + return v.size(); } vector SALOMEDS_IParameters::getValues(const string& listName) { vector v; - return v; + if(!_ap) return v; + if(!_ap->IsSet(listName, PT_STRARRAY)) return v; + return _ap->GetStrArray(listName); } string SALOMEDS_IParameters::getValue(const string& listName, int index) { - return ""; + if(!_ap) return ""; + if(!_ap->IsSet(listName, PT_STRARRAY)) return ""; + vector v = _ap->GetStrArray(listName); + if(index >= v.size()) return ""; + return v[index]; } void SALOMEDS_IParameters::setParameter(const string& entry, const string& parameterName, const string& value) { - + if(!_ap) return; + vector v; + if(!_ap->IsSet(entry, PT_STRARRAY)) _ap->SetStrArray(entry, v); + v = _ap->GetStrArray(entry); + v.push_back(parameterName); + v.push_back(value); + _ap->SetStrArray(entry, v); } string SALOMEDS_IParameters::getParameter(const string& entry, const string& parameterName) { + if(!_ap) return ""; + if(!_ap->IsSet(entry, PT_STRARRAY)) return ""; + vector v = _ap->GetStrArray(entry); + int length = v.size(); + for(int i = 0; i& names, vector& values) +vector SALOMEDS_IParameters::getAllParameterNames(const string& entry) { + vector v, names; + if(!_ap) return v; + if(!_ap->IsSet(entry, PT_STRARRAY)) return v; + v = _ap->GetStrArray(entry); + int length = v.size(); + for(int i = 0; i SALOMEDS_IParameters::getAllParameterValues(const string& entry) +{ + vector v, values; + if(!_ap) return v; + if(!_ap->IsSet(entry, PT_STRARRAY)) return v; + v = _ap->GetStrArray(entry); + int length = v.size(); + for(int i = 1; iIsSet(entry, PT_STRARRAY)) return -1; + return _ap->GetStrArray(entry).size(); } +void SALOMEDS_IParameters::setProperty(const string& name, const std::string& value) +{ + if(!_ap) return; + _ap->SetString(name, value); +} + +string SALOMEDS_IParameters::getProperty(const string& name) +{ + if(!_ap) return ""; + if(!_ap->IsSet(name, PT_STRING)) return ""; + return _ap->GetString(name); +} + + +vector SALOMEDS_IParameters::parseValue(const string& value, const char separator, bool fromEnd) +{ + TCollection_AsciiString val((char*)value.c_str()); + vector v; + int pos; + if(fromEnd) pos = val.SearchFromEnd(separator); + else pos = val.Search(separator); + + if(pos < 0) { + v.push_back(value); + return v; + } + + TCollection_AsciiString part1, part2; + part1 = val.SubString(1, pos-1); + part2 = val.SubString(pos+1, val.Length()); + v.push_back(part1.ToCString()); + v.push_back(part2.ToCString()); + return v; +} diff --git a/src/SALOMEDS/SALOMEDS_IParameters.hxx b/src/SALOMEDS/SALOMEDS_IParameters.hxx index fb5287215..dad517e37 100644 --- a/src/SALOMEDS/SALOMEDS_IParameters.hxx +++ b/src/SALOMEDS/SALOMEDS_IParameters.hxx @@ -50,7 +50,7 @@ public: std::vector getValues(const std::string& listName); /*! - Returns a value with given index + Returns a value with given %index, where %index is in range [0:nbValues-1] */ std::string getValue(const std::string& listName, int index); @@ -65,15 +65,36 @@ public: std::string getParameter(const std::string& entry, const std::string& parameterName); /*! - Returns all parameter names and their values of the given entry + Returns all parameter names of the given entry */ - void getAllParameters(const std::string& entry, std::vector& names, std::vector& values); + std::vector SALOMEDS_IParameters::getAllParameterNames(const std::string& entry); + + /*! + Returns all parameter values of the given entry + */ + std::vector SALOMEDS_IParameters::getAllParameterValues(const std::string& entry); /*! Returns a number of parameters of the given entry */ int getNbParameters(const std::string& entry); + /*! + Sets a global named property value + */ + void setProperty(const std::string& name, const std::string& value); + + /*! + Gets a value of global named property + */ + std::string getProperty(const std::string& name); + + /*! + Breaks a value string in two parts which is divided %separator. + If fromEnd is True the search of separator starts from the end of the string + */ + std::vector parseValue(const std::string& value, const char separator, bool fromEnd = true); + private: _PTR(AttributeParameter) _ap; -- 2.39.2