-// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
+// License as published by the Free Software Foundation; either
// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.salome-platform.org/
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+
// File : SALOMEDSImpl_AttributeParameter.cxx
// Author : Sergey RUIN
// Module : SALOME
-
-
+//
#include "SALOMEDSImpl_AttributeParameter.hxx"
-#include <Standard_Failure.hxx>
#include <stdio.h>
#include <stdlib.h>
-#include <strstream>
-
-using namespace std;
-
-
-
-IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributeParameter, SALOMEDSImpl_GenericAttribute )
-IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributeParameter, SALOMEDSImpl_GenericAttribute )
+#include <sstream>
+#include <sstream>
// Purpose: Each character in the string is replaced by 3 characters: '%' and hex number
// of the character (2 characters)
-string convertString(const string& S)
+std::string convertString(const std::string& S)
{
int length = S.size();
const char *s = S.c_str();
for(int i = 0, pos = 0; i<length; i++, pos+=3) {
int val = (int)s[i];
buffer[pos] = '%';
- sprintf(c, "%x", val);
+ sprintf(c, "%.2x", val);
buffer[pos+1] = c[0];
buffer[pos+2] = c[1];
}
- string RS(buffer);
+ std::string RS(buffer);
delete c;
delete buffer;
return RS;
}
//Restors a string converted by the function convertString
-string restoreString(const string& S)
+std::string restoreString(const std::string& S)
{
int length = S.size();
char *c = new char[3], *buffer = new char[length/3+1];
buffer[pos] = (char)val;
}
- string RS(buffer);
+ std::string RS(buffer);
delete c;
delete buffer;
return RS;
* Purpose : Returns GUID of the attribute
*/
//=======================================================================
-const Standard_GUID& SALOMEDSImpl_AttributeParameter::GetID ()
+const std::string& SALOMEDSImpl_AttributeParameter::GetID ()
{
- static Standard_GUID ParemeterID ("BA75F3A1-E40B-46b8-8D24-B1D3C3BB1A8C");
+ static std::string ParemeterID ("BA75F3A1-E40B-46b8-8D24-B1D3C3BB1A8C");
return ParemeterID;
}
* Purpose : Adds an attribute to the label
*/
//=======================================================================
-Handle(SALOMEDSImpl_AttributeParameter) SALOMEDSImpl_AttributeParameter::Set (const TDF_Label& L)
+SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_AttributeParameter::Set (const DF_Label& L)
{
- Handle(SALOMEDSImpl_AttributeParameter) A;
- if (!L.FindAttribute(SALOMEDSImpl_AttributeParameter::GetID(), A)) {
+ SALOMEDSImpl_AttributeParameter* A = NULL;
+ if (!(A=(SALOMEDSImpl_AttributeParameter*)L.FindAttribute(SALOMEDSImpl_AttributeParameter::GetID()))) {
A = new SALOMEDSImpl_AttributeParameter();
L.AddAttribute(A);
}
* Purpose : Associates a integer value with the ID
*/
//=======================================================================
-void SALOMEDSImpl_AttributeParameter::SetInt(const string& theID, const int& theValue)
+void SALOMEDSImpl_AttributeParameter::SetInt(const std::string& theID, const int& theValue)
{
CheckLocked();
+ if(theID.size() == 0) return;
+
Backup();
_ints[theID] = theValue;
* Purpose : Returns a int value associated with the given ID
*/
//=======================================================================
-int SALOMEDSImpl_AttributeParameter::GetInt(const string& theID)
+int SALOMEDSImpl_AttributeParameter::GetInt(const std::string& theID)
{
- if(!IsSet(theID, PT_INTEGER)) Standard_Failure::Raise("Invalid ID");
+ if(!IsSet(theID, PT_INTEGER)) throw DFexception("Invalid ID");
return _ints[theID];
}
* Purpose : Associates a double value with the ID
*/
//=======================================================================
-void SALOMEDSImpl_AttributeParameter::SetReal(const string& theID, const double& theValue)
+void SALOMEDSImpl_AttributeParameter::SetReal(const std::string& theID, const double& theValue)
{
CheckLocked();
+ if(theID.size() == 0) return;
+
Backup();
_reals[theID] = theValue;
* Purpose : Returns a double value associated with the given ID
*/
//=======================================================================
-double SALOMEDSImpl_AttributeParameter::GetReal(const string& theID)
+double SALOMEDSImpl_AttributeParameter::GetReal(const std::string& theID)
{
- if(!IsSet(theID, PT_REAL)) Standard_Failure::Raise("Invalid ID");
+ if(!IsSet(theID, PT_REAL)) throw DFexception("Invalid ID");
return _reals[theID];
}
* Purpose : Associates a string with the ID
*/
//=======================================================================
-void SALOMEDSImpl_AttributeParameter::SetString(const string& theID, const string& theValue)
+void SALOMEDSImpl_AttributeParameter::SetString(const std::string& theID, const std::string& theValue)
{
CheckLocked();
+ if(theID.size() == 0) return;
+
Backup();
_strings[theID] = theValue;
* Purpose : Returns a string associated with the given ID
*/
//=======================================================================
-string SALOMEDSImpl_AttributeParameter::GetString(const string& theID)
+std::string SALOMEDSImpl_AttributeParameter::GetString(const std::string& theID)
{
- if(!IsSet(theID, PT_STRING)) Standard_Failure::Raise("Invalid ID");
+ if(!IsSet(theID, PT_STRING)) throw DFexception("Invalid ID");
return _strings[theID];
}
* Purpose : Associates a bool value with the ID
*/
//=======================================================================
-void SALOMEDSImpl_AttributeParameter::SetBool(const string& theID, const bool& theValue)
+void SALOMEDSImpl_AttributeParameter::SetBool(const std::string& theID, const bool& theValue)
{
CheckLocked();
+ if(theID.size() == 0) return;
+
Backup();
_bools[theID] = theValue;
* Purpose : Returns a bool value associated with the ID
*/
//=======================================================================
-bool SALOMEDSImpl_AttributeParameter::GetBool(const string& theID)
+bool SALOMEDSImpl_AttributeParameter::GetBool(const std::string& theID)
{
- if(!IsSet(theID, PT_BOOLEAN)) Standard_Failure::Raise("Invalid ID");
+ if(!IsSet(theID, PT_BOOLEAN)) throw DFexception("Invalid ID");
return _bools[theID];
}
* Purpose : Associates an array of double values with the given ID
*/
//=======================================================================
-void SALOMEDSImpl_AttributeParameter::SetRealArray(const string& theID, const vector<double>& theArray)
+void SALOMEDSImpl_AttributeParameter::SetRealArray(const std::string& theID, const std::vector<double>& theArray)
{
CheckLocked();
+ if(theID.size() == 0) return;
+
Backup();
_realarrays[theID] = theArray;
* Purpose : Returns double values associated with the ID
*/
//=======================================================================
-vector<double> SALOMEDSImpl_AttributeParameter::GetRealArray(const string& theID)
+std::vector<double> SALOMEDSImpl_AttributeParameter::GetRealArray(const std::string& theID)
{
- if(!IsSet(theID, PT_REALARRAY)) Standard_Failure::Raise("Invalid ID");
+ if(!IsSet(theID, PT_REALARRAY)) throw DFexception("Invalid ID");
return _realarrays[theID];
}
* Purpose : Associates an array of int values with the given ID
*/
//=======================================================================
-void SALOMEDSImpl_AttributeParameter::SetIntArray(const string& theID, const vector<int>& theArray)
+void SALOMEDSImpl_AttributeParameter::SetIntArray(const std::string& theID, const std::vector<int>& theArray)
{
CheckLocked();
+ if(theID.size() == 0) return;
+
Backup();
_intarrays[theID] = theArray;
* Purpose : Returns int values associated with the ID
*/
//=======================================================================
-vector<int> SALOMEDSImpl_AttributeParameter::GetIntArray(const string& theID)
+std::vector<int> SALOMEDSImpl_AttributeParameter::GetIntArray(const std::string& theID)
{
- if(!IsSet(theID, PT_INTARRAY)) Standard_Failure::Raise("Invalid ID");
+ if(!IsSet(theID, PT_INTARRAY)) throw DFexception("Invalid ID");
return _intarrays[theID];
}
* Purpose : Associates an array of string values with the given ID
*/
//=======================================================================
-void SALOMEDSImpl_AttributeParameter::SetStrArray(const string& theID, const vector<string>& theArray)
+void SALOMEDSImpl_AttributeParameter::SetStrArray(const std::string& theID, const std::vector<std::string>& theArray)
{
CheckLocked();
+ if(theID.size() == 0) return;
+
Backup();
_strarrays[theID] = theArray;
* Purpose : Returns string values associated with the ID
*/
//=======================================================================
-vector<string> SALOMEDSImpl_AttributeParameter::GetStrArray(const string& theID)
+std::vector<std::string> SALOMEDSImpl_AttributeParameter::GetStrArray(const std::string& theID)
{
- if(!IsSet(theID, PT_STRARRAY)) Standard_Failure::Raise("Invalid ID");
+ if(!IsSet(theID, PT_STRARRAY)) throw DFexception("Invalid ID");
return _strarrays[theID];
}
* a value in the attribute
*/
//=======================================================================
-bool SALOMEDSImpl_AttributeParameter::IsSet(const string& theID, const Parameter_Types theType)
+bool SALOMEDSImpl_AttributeParameter::IsSet(const std::string& theID, const Parameter_Types theType)
{
switch(theType) {
case PT_INTEGER: {
* Purpose : Removes a parameter with given ID
*/
//=======================================================================
-bool SALOMEDSImpl_AttributeParameter::RemoveID(const string& theID, const Parameter_Types theType)
+bool SALOMEDSImpl_AttributeParameter::RemoveID(const std::string& theID, const Parameter_Types theType)
{
Backup();
SetModifyFlag();
* Purpose : Returns a father attribute for this attribute
*/
//=======================================================================
-Handle(SALOMEDSImpl_AttributeParameter) SALOMEDSImpl_AttributeParameter::GetFather()
+SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_AttributeParameter::GetFather()
{
- Handle(SALOMEDSImpl_AttributeParameter) aFather;
- TDF_Label L = Label();
+ SALOMEDSImpl_AttributeParameter* aFather;
+ DF_Label L = Label();
if(L.IsRoot()) return aFather;
while(!L.IsRoot()) {
L = L.Father();
- if(L.FindAttribute(SALOMEDSImpl_AttributeParameter::GetID(), aFather)) break;
+ if((aFather=(SALOMEDSImpl_AttributeParameter*)L.FindAttribute(SALOMEDSImpl_AttributeParameter::GetID()))) break;
}
return aFather;
//=======================================================================
bool SALOMEDSImpl_AttributeParameter::HasFather()
{
- TDF_Label L = Label();
+ DF_Label L = Label();
if(L.IsRoot()) return false;
while(!L.IsRoot()) {
L = L.Father();
* Purpose : Returns an array of all ID's of the given type
*/
//=======================================================================
-vector<string> SALOMEDSImpl_AttributeParameter::GetIDs(const Parameter_Types theType)
+std::vector<std::string> SALOMEDSImpl_AttributeParameter::GetIDs(const Parameter_Types theType)
{
- vector<string> anArray;
+ std::vector<std::string> anArray;
int i = 0;
switch(theType) {
case PT_INTEGER: {
if(_ints.size()) {
anArray.resize(_ints.size());
- for(map<string,int>::const_iterator p = _ints.begin(); p != _ints.end(); p++, i++)
- anArray[i] = p->first;
+ for(std::map<std::string,int>::const_iterator p = _ints.begin(); p != _ints.end(); p++, i++)
+ anArray[i] = p->first;
}
break;
}
case PT_REAL: {
if(_reals.size()) {
anArray.resize(_reals.size());
- for(map<string,double>::const_iterator p = _reals.begin(); p != _reals.end(); p++, i++)
- anArray[i] = p->first;
+ for(std::map<std::string,double>::const_iterator p = _reals.begin(); p != _reals.end(); p++, i++)
+ anArray[i] = p->first;
}
break;
}
case PT_BOOLEAN: {
if(_bools.size()) {
anArray.resize(_bools.size());
- for(map<string,bool>::const_iterator p = _bools.begin(); p != _bools.end(); p++, i++)
- anArray[i] = p->first;
+ for(std::map<std::string,bool>::const_iterator p = _bools.begin(); p != _bools.end(); p++, i++)
+ anArray[i] = p->first;
}
break;
}
case PT_STRING: {
if(_strings.size()) {
anArray.resize(_strings.size());
- for(map<string,string>::const_iterator p = _strings.begin(); p!= _strings.end(); p++)
- anArray[i] = p->first;
+ for(std::map<std::string,std::string>::const_iterator p = _strings.begin(); p!= _strings.end(); p++)
+ anArray[i] = p->first;
}
break;
}
case PT_REALARRAY: {
if(_realarrays.size()) {
anArray.resize(_realarrays.size());
- for(map< string, vector<double> >::const_iterator p = _realarrays.begin(); p!= _realarrays.end(); p++)
- anArray[i] = p->first;
+ for(std::map< std::string, std::vector<double> >::const_iterator p = _realarrays.begin(); p!= _realarrays.end(); p++)
+ anArray[i] = p->first;
}
break;
}
case PT_INTARRAY: {
if(_intarrays.size()) {
anArray.resize(_intarrays.size());
- for(map< string, vector<int> >::const_iterator p = _intarrays.begin(); p!= _intarrays.end(); p++)
- anArray[i] = p->first;
+ for(std::map< std::string, std::vector<int> >::const_iterator p = _intarrays.begin(); p!= _intarrays.end(); p++)
+ anArray[i] = p->first;
}
break;
}
case PT_STRARRAY: {
if(_strarrays.size()) {
anArray.resize(_strarrays.size());
- for(map< string, vector<string> >::const_iterator p = _strarrays.begin(); p!= _strarrays.end(); p++)
- anArray[i] = p->first;
+ for(std::map< std::string, std::vector<std::string> >::const_iterator p = _strarrays.begin(); p!= _strarrays.end(); p++)
+ anArray[i] = p->first;
}
break;
}
* Purpose : Rteurns an GUID of the attribute
*/
//=======================================================================
-const Standard_GUID& SALOMEDSImpl_AttributeParameter::ID () const { return GetID(); }
+const std::string& SALOMEDSImpl_AttributeParameter::ID () const { return GetID(); }
-Handle(TDF_Attribute) SALOMEDSImpl_AttributeParameter::NewEmpty () const
+DF_Attribute* SALOMEDSImpl_AttributeParameter::NewEmpty () const
{
return new SALOMEDSImpl_AttributeParameter();
}
* Purpose : Restors the content of the attribute from another
*/
//=======================================================================
-void SALOMEDSImpl_AttributeParameter::Restore(const Handle(TDF_Attribute)& with)
+void SALOMEDSImpl_AttributeParameter::Restore(DF_Attribute* with)
{
- Handle(SALOMEDSImpl_AttributeParameter) A = Handle(SALOMEDSImpl_AttributeParameter)::DownCast (with);
+ SALOMEDSImpl_AttributeParameter* A = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(with);
_ints.clear();
_reals.clear();
_bools.clear();
_intarrays.clear();
_strarrays.clear();
- for(map<string,int>::const_iterator p = A->_ints.begin(); p!= A->_ints.end(); p++) _ints[p->first] = p->second;
- for(map<string,double>::const_iterator p = A->_reals.begin(); p!= A->_reals.end(); p++) _reals[p->first] = p->second;
- for(map<string,bool>::const_iterator p = A->_bools.begin(); p!= A->_bools.end(); p++) _bools[p->first] = p->second;
- for(map<string,string>::const_iterator p = A->_strings.begin(); p!= A->_strings.end(); p++)
- _strings[p->first] = p->second;
- for(map< string,vector<double> >::const_iterator p = A->_realarrays.begin(); p!= A->_realarrays.end(); p++)
- _realarrays[p->first] = p->second;
- for(map< string,vector<int> >::const_iterator p = A->_intarrays.begin(); p!= A->_intarrays.end(); p++)
- _intarrays[p->first] = p->second;
- for(map< string,vector<string> >::const_iterator p = A->_strarrays.begin(); p!= A->_strarrays.end(); p++)
- _strarrays[p->first] = p->second;
+ for(std::map<std::string,int>::const_iterator p = A->_ints.begin(); p!= A->_ints.end(); p++)
+ if(p->first.size()) _ints[p->first] = p->second;
+ for(std::map<std::string,double>::const_iterator p = A->_reals.begin(); p!= A->_reals.end(); p++)
+ if(p->first.size()) _reals[p->first] = p->second;
+ for(std::map<std::string,bool>::const_iterator p = A->_bools.begin(); p!= A->_bools.end(); p++)
+ if(p->first.size()) _bools[p->first] = p->second;
+ for(std::map<std::string,std::string>::const_iterator p = A->_strings.begin(); p!= A->_strings.end(); p++)
+ if(p->first.size()) _strings[p->first] = p->second;
+ for(std::map< std::string,std::vector<double> >::const_iterator p = A->_realarrays.begin(); p!= A->_realarrays.end(); p++)
+ if(p->first.size()) _realarrays[p->first] = p->second;
+ for(std::map< std::string,std::vector<int> >::const_iterator p = A->_intarrays.begin(); p!= A->_intarrays.end(); p++)
+ if(p->first.size()) _intarrays[p->first] = p->second;
+ for(std::map< std::string,std::vector<std::string> >::const_iterator p = A->_strarrays.begin(); p!= A->_strarrays.end(); p++)
+ if(p->first.size()) _strarrays[p->first] = p->second;
}
//=======================================================================
* Purpose : Pastes the content of attribute to another
*/
//=======================================================================
-void SALOMEDSImpl_AttributeParameter::Paste (const Handle(TDF_Attribute)& into,
- const Handle(TDF_RelocationTable)& RT) const
+void SALOMEDSImpl_AttributeParameter::Paste (DF_Attribute* into)
{
into->Restore(this);
}
* Purpose : Saves a content of the attribute as a string
*/
//=======================================================================
-TCollection_AsciiString SALOMEDSImpl_AttributeParameter::Save()
+std::string SALOMEDSImpl_AttributeParameter::Save()
{
- ostrstream buffer;
+ std::ostringstream buffer;
char *tmpBuffer = new char[255];
buffer << _ints.size() << " ";
- for(map<string,int>::const_iterator p = _ints.begin(); p != _ints.end(); p++) {
+ for(std::map<std::string,int>::const_iterator p = _ints.begin(); p != _ints.end(); p++) {
buffer << convertString(p->first) << " " << p->second << " ";
}
buffer << _reals.size() << " ";
- for(map<string,double>::const_iterator p =_reals.begin(); p != _reals.end(); p++) {
+ for(std::map<std::string,double>::const_iterator p =_reals.begin(); p != _reals.end(); p++) {
sprintf(tmpBuffer, "%.64e", p->second);
buffer << convertString(p->first) << " " << tmpBuffer << " ";
}
buffer << _bools.size() << " ";
- for(map<string,bool>::const_iterator p = _bools.begin(); p != _bools.end(); p++) {
+ for(std::map<std::string,bool>::const_iterator p = _bools.begin(); p != _bools.end(); p++) {
buffer << convertString(p->first) << " " << p->second << " ";
}
buffer << _strings.size() << " ";
- for(map<string,string>::const_iterator p = _strings.begin(); p != _strings.end(); p++) {
+ for(std::map<std::string,std::string>::const_iterator p = _strings.begin(); p != _strings.end(); p++) {
buffer << convertString(p->first) << " " << convertString(p->second) << " ";
}
buffer << _realarrays.size() << " ";
- for(map< string,vector<double> >::const_iterator p = _realarrays.begin(); p != _realarrays.end(); p++) {
- vector<double> v(p->second);
+ for(std::map< std::string,std::vector<double> >::const_iterator p = _realarrays.begin(); p != _realarrays.end(); p++) {
+ std::vector<double> v(p->second);
sprintf(tmpBuffer, " %s %d ", convertString(p->first).c_str(), v.size());
buffer << tmpBuffer;
for(int i = 0; i<v.size(); i++) {
}
buffer << _intarrays.size() << " ";
- for(map< string,vector<int> >::const_iterator p = _intarrays.begin(); p != _intarrays.end(); p++) {
- vector<int> v(p->second);
+ for(std::map< std::string,std::vector<int> >::const_iterator p = _intarrays.begin(); p != _intarrays.end(); p++) {
+ std::vector<int> v(p->second);
sprintf(tmpBuffer, " %s %d ", convertString(p->first).c_str(), v.size());
buffer << tmpBuffer;
for(int i = 0; i<v.size(); i++) {
}
buffer << _strarrays.size() << " ";
- for(map< string,vector<string> >::const_iterator p = _strarrays.begin(); p != _strarrays.end(); p++) {
- vector<string> v(p->second);
+ for(std::map< std::string,std::vector<std::string> >::const_iterator p = _strarrays.begin(); p != _strarrays.end(); p++) {
+ std::vector<std::string> v(p->second);
sprintf(tmpBuffer, " %s %d ", convertString(p->first).c_str(), v.size());
buffer << tmpBuffer;
for(int i = 0; i<v.size(); i++) {
delete tmpBuffer;
- TCollection_AsciiString AS((char*)buffer.rdbuf()->str());
+ std::string AS = buffer.str();
return AS;
}
* Purpose : Restores the attribute from the string
*/
//=======================================================================
-void SALOMEDSImpl_AttributeParameter::Load(const TCollection_AsciiString& theValue)
+void SALOMEDSImpl_AttributeParameter::Load(const std::string& theValue)
{
Backup();
_realarrays.clear();
_intarrays.clear();
- istrstream buffer(theValue.ToCString(), strlen(theValue.ToCString()));
+ std::istringstream buffer(theValue.c_str());
int size, val, ival;
double val2;
- string s, id;
+ std::string s, id;
buffer >> size;
for(int i = 1; i<=size; i++) {
buffer >> size;
for(int i = 1; i<=size; i++) {
buffer >> id >> val;
- vector<double> v;
+ std::vector<double> v;
v.resize(val);
for(int j = 0; j<val; j++) {
buffer >> val2;
buffer >> size;
for(int i = 1; i<=size; i++) {
buffer >> id >> val;
- vector<int> v;
+ std::vector<int> v;
v.resize(val);
for(int j = 0; j<val; j++) {
buffer >> ival;
buffer >> size;
for(int i = 1; i<=size; i++) {
buffer >> id >> val;
- vector<string> v;
+ std::vector<std::string> v;
v.resize(val);
for(int j = 0; j<val; j++) {
buffer >> s;