-// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2019 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
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
std::string convertString(const std::string& S)
{
int length = S.size();
- const char *s = S.c_str();
- char *c = new char[3], *buffer = new char[length*3+1];
+ if ( length == 0 )
+ return "0";
+ char c[3], *buffer = new char[length*3+1];
buffer[length*3] = (char)0;
for(int i = 0, pos = 0; i<length; i++, pos+=3) {
- int val = (int)s[i];
+ int val = (int)S[i];
buffer[pos] = '%';
sprintf(c, "%.2x", val);
buffer[pos+1] = c[0];
}
std::string RS(buffer);
- delete [] c;
delete [] buffer;
return RS;
}
std::string restoreString(const std::string& S)
{
int length = S.size();
- char *c = new char[3], *buffer = new char[length/3+1];
+ if ( length == 1 )
+ return "";
+ char c[3], *buffer = new char[length/3+1];
buffer[length/3] = (char)0;
- const char *s = S.c_str();
for(int i = 0, pos = 0; i<length; i+=3, pos++) {
- c[0] = s[i+1];
- c[1] = s[i+2];
+ c[0] = S[i+1];
+ c[1] = S[i+2];
c[2] = (char)0;
int val = strtol(c, NULL, 16);
buffer[pos] = (char)val;
}
std::string RS(buffer);
- delete [] c;
delete [] buffer;
return RS;
}
//=======================================================================
SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_AttributeParameter::GetFather()
{
- SALOMEDSImpl_AttributeParameter* aFather;
+ SALOMEDSImpl_AttributeParameter* aFather = 0;
DF_Label L = Label();
if(L.IsRoot()) return aFather;
//=======================================================================
/*!
* Function : IsRoot
- * Purpose : Returns True is the attribute is highest in an hierachy
+ * Purpose : Returns True is the attribute is highest in an hierarchy
*/
//=======================================================================
bool SALOMEDSImpl_AttributeParameter::IsRoot()
case PT_STRING: {
if(_strings.size()) {
anArray.resize(_strings.size());
- for(std::map<std::string,std::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++, i++)
anArray[i] = p->first;
}
break;
case PT_REALARRAY: {
if(_realarrays.size()) {
anArray.resize(_realarrays.size());
- for(std::map< std::string, std::vector<double> >::const_iterator p = _realarrays.begin(); p!= _realarrays.end(); p++)
+ for(std::map< std::string, std::vector<double> >::const_iterator p = _realarrays.begin(); p!= _realarrays.end(); p++, i++)
anArray[i] = p->first;
}
break;
case PT_INTARRAY: {
if(_intarrays.size()) {
anArray.resize(_intarrays.size());
- for(std::map< std::string, std::vector<int> >::const_iterator p = _intarrays.begin(); p!= _intarrays.end(); p++)
+ for(std::map< std::string, std::vector<int> >::const_iterator p = _intarrays.begin(); p!= _intarrays.end(); p++, i++)
anArray[i] = p->first;
}
break;
case PT_STRARRAY: {
if(_strarrays.size()) {
anArray.resize(_strarrays.size());
- for(std::map< std::string, std::vector<std::string> >::const_iterator p = _strarrays.begin(); p!= _strarrays.end(); p++)
+ for(std::map< std::string, std::vector<std::string> >::const_iterator p = _strarrays.begin(); p!= _strarrays.end(); p++, i++)
anArray[i] = p->first;
}
break;
char *tmpBuffer = new char[255];
buffer << _ints.size() << " ";
-
for(std::map<std::string,int>::const_iterator p = _ints.begin(); p != _ints.end(); p++) {
buffer << convertString(p->first) << " " << p->second << " ";
}
buffer << _bools.size() << " ";
for(std::map<std::string,bool>::const_iterator p = _bools.begin(); p != _bools.end(); p++) {
- buffer << convertString(p->first) << " " << p->second << " ";
+ buffer << convertString(p->first) << " " << p->second << " ";
}
buffer << _strings.size() << " ";
buffer << _realarrays.size() << " ";
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());
+ sprintf(tmpBuffer, " %s %d ", convertString(p->first).c_str(), (int)v.size());
buffer << tmpBuffer;
- for(int i = 0; i<v.size(); i++) {
+ for(size_t i = 0; i<v.size(); i++) {
sprintf(tmpBuffer, " %.64e ", v[i]);
buffer << tmpBuffer;
}
buffer << _intarrays.size() << " ";
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());
+ sprintf(tmpBuffer, " %s %d ", convertString(p->first).c_str(), (int)v.size());
buffer << tmpBuffer;
- for(int i = 0; i<v.size(); i++) {
+ for(size_t i = 0; i<v.size(); i++) {
sprintf(tmpBuffer, " %d ", v[i]);
buffer << tmpBuffer;
}
buffer << _strarrays.size() << " ";
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());
+ sprintf(tmpBuffer, " %s %d ", convertString(p->first).c_str(), (int)v.size());
buffer << tmpBuffer;
- for(int i = 0; i<v.size(); i++) {
+ for(size_t i = 0; i<v.size(); i++) {
buffer << " " << convertString(v[i]) << " ";
}
}
- delete tmpBuffer;
+ delete [] tmpBuffer;
std::string AS = buffer.str();
- return AS;
+ return AS;
}
//=======================================================================
* Purpose : Restores the attribute from the string
*/
//=======================================================================
-void SALOMEDSImpl_AttributeParameter::Load(const std::string& theValue)
-{
+void SALOMEDSImpl_AttributeParameter::Load(const std::string& theValue)
+{
Backup();
_ints.clear();