-// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
// of the character (2 characters)
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];
+ size_t length = S.size();
+ 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];
+ for(int i = 0, pos = 0; i<(int)length; i++, pos+=3) { //TODO: mismatch signed/unsigned
+ 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;
}
//Restors a string converted by the function convertString
std::string restoreString(const std::string& S)
{
- int length = S.size();
- char *c = new char[3], *buffer = new char[length/3+1];
+ size_t length = S.size();
+ 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];
+ for(int i = 0, pos = 0; i<(int)length; i+=3, pos++) { //TODO: mismatch signed/unsigned
+ 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()
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();