00001 00002 // exotkParameter_Enumeration.cxx 00004 // Copyright (C) 2001 Stephane Routelous 00005 // 00006 // This file is part of exoTK. 00007 // 00008 // exoTK is free software; you can redistribute it and/or modify 00009 // it under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation; either version 2 of the License, or 00011 // (at your option) any later version. 00012 // 00013 // exoTK is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with exoTK; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 00029 #include <exotkParameter_Enumeration.hxx> 00030 #include <stdlib.h> 00031 #ifndef _Standard_TypeDef_HeaderFile 00032 #include <Standard_Integer.hxx> 00033 #endif 00034 #ifndef _exotkUtils_HeaderFile 00035 #include <exotkUtils.hxx> 00036 #endif 00037 00038 // 00039 IMPLEMENT_STANDARD_HANDLE(exotkParameter_Enumeration,exotkParameter_Root) 00040 IMPLEMENT_STANDARD_RTTI(exotkParameter_Enumeration,exotkParameter_Root) 00041 // 00042 // Foreach ancestors, we add a IMPLEMENT_STANDARD_SUPERTYPE and 00043 // a IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY macro. 00044 // We must respect the order: from the direct ancestor class 00045 // to the base class. 00046 // 00047 00048 IMPLEMENT_STANDARD_TYPE(exotkParameter_Enumeration) 00049 IMPLEMENT_STANDARD_SUPERTYPE(exotkParameter_Root) 00050 IMPLEMENT_STANDARD_SUPERTYPE(MMgt_TShared) 00051 IMPLEMENT_STANDARD_SUPERTYPE(Standard_Transient) 00052 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY() 00053 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(exotkParameter_Root) 00054 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(MMgt_TShared) 00055 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(Standard_Transient) 00056 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_END() 00057 IMPLEMENT_STANDARD_TYPE_END(exotkParameter_Enumeration) 00058 00059 00060 //================================================================================== 00061 // Function name : exotkParameter_Enumeration::exotkParameter_Enumeration 00062 //================================================================================== 00063 // Written by : Stephane Routelous - 08/03/2001 01:02:06 00064 // Description : 00065 // Return type : 00066 //================================================================================== 00067 // Argument : const Standard_Integer aValue 00068 exotkParameter_Enumeration::exotkParameter_Enumeration(const Standard_Integer aValue) 00069 :myValue(aValue) 00070 { 00071 myType = exotkParameter_Type_Enumeration; 00072 } 00073 00074 00075 //================================================================================== 00076 // Function name : exotkParameter_Enumeration::~exotkParameter_Enumeration 00077 //================================================================================== 00078 // Written by : Stephane Routelous - 08/03/2001 01:02:08 00079 // Description : 00080 // Return type : 00081 //================================================================================== 00082 exotkParameter_Enumeration::~exotkParameter_Enumeration() 00083 { 00084 00085 } 00086 00087 //================================================================================== 00088 // Function name : exotkParameter_Enumeration::DeepCopy 00089 //================================================================================== 00090 // Written by : Stephane Routelous - 16/04/2001 21:49:12 00091 // Description : 00092 // Return type : void 00093 //================================================================================== 00094 // Argument : const Handle_exotkParameter_Root &aParameterToCopy 00095 void exotkParameter_Enumeration::DeepCopy(const Handle_exotkParameter_Root &aParameterToCopy) 00096 { 00097 exotkParameter_Root::DeepCopy(aParameterToCopy); 00098 if ( aParameterToCopy->IsKind(STANDARD_TYPE(exotkParameter_Enumeration)) ) 00099 { 00100 Handle_exotkParameter_Enumeration theEnumToCopy = Handle_exotkParameter_Enumeration::DownCast(aParameterToCopy); 00101 myValue = theEnumToCopy->Value(); 00102 00103 //copy the enumeration members 00104 myMapIntegerAsciiString.Clear(); 00105 for ( theEnumToCopy->EnumInit() ; theEnumToCopy->EnumMore() ; theEnumToCopy->EnumNext()) 00106 { 00107 myMapIntegerAsciiString.Bind(theEnumToCopy->EnumCurrentIndex(),theEnumToCopy->EnumCurrentName()); 00108 } 00109 } 00110 } 00111 00112 00113 //================================================================================== 00114 // Function name : exotkParameter_Enumeration::SetValue 00115 //================================================================================== 00116 // Written by : Stephane Routelous - 08/03/2001 01:02:11 00117 // Description : 00118 // Return type : Standard_Boolean 00119 //================================================================================== 00120 // Argument : const Standard_Integer aValue 00121 Standard_Boolean exotkParameter_Enumeration::SetValue(const Standard_Integer aValue) 00122 { 00123 00124 if ( myMapIntegerAsciiString.IsBound1(aValue) ) 00125 { 00126 myValue = aValue; 00127 return Standard_True; 00128 } 00129 else 00130 return Standard_False; 00131 } 00132 00133 //================================================================================== 00134 // Function name : exotkParameter_Enumeration::Value 00135 //================================================================================== 00136 // Written by : Stephane Routelous - 08/03/2001 01:02:13 00137 // Description : 00138 // Return type : Standard_Integer 00139 //================================================================================== 00140 Standard_Integer exotkParameter_Enumeration::Value() const 00141 { 00142 return myValue; 00143 } 00144 00145 //================================================================================== 00146 // Function name : exotkParameter_Enumeration::SetParameterAsString 00147 //================================================================================== 00148 // Written by : Stephane Routelous - 08/03/2001 01:02:17 00149 // Description : 00150 // Return type : Standard_Boolean 00151 //================================================================================== 00152 // Argument : const TCollection_AsciiString& aParameter 00153 Standard_Boolean exotkParameter_Enumeration::SetParameterAsString(const TCollection_AsciiString& aParameter) 00154 { 00155 Standard_Boolean theIsSuccess = Standard_False; 00156 Standard_Integer theIntegerValue; 00157 //try with an integer value 00158 if ( exotkUtils::AsciiStringToInteger(aParameter,theIntegerValue) ) 00159 { 00160 theIsSuccess = SetValue(theIntegerValue); 00161 } 00162 else 00163 { 00164 TCollection_AsciiString theParameterAsString = aParameter; 00165 theParameterAsString.LowerCase(); 00166 //it is not an integer value ; try with the name 00167 exotkParameter_DoubleMapIteratorOfDoubleMapIntegerAsciiString theIter; 00168 Standard_Boolean theNameIsFound = Standard_False; 00169 for ( theIter.Initialize(myMapIntegerAsciiString);theIter.More() && (!theNameIsFound );theIter.Next() ) 00170 { 00171 TCollection_AsciiString theNameLowerCase = theIter.Key2(); 00172 theNameLowerCase.LowerCase(); 00173 if ( theParameterAsString == theNameLowerCase ) 00174 { 00175 theIsSuccess = SetValue(theIter.Key1()); 00176 theNameIsFound = Standard_True; 00177 } 00178 } 00179 } 00180 return theIsSuccess; 00181 } 00182 00183 //================================================================================== 00184 // Function name : exotkParameter_Enumeration::ParameterAsString 00185 //================================================================================== 00186 // Written by : Stephane Routelous - 08/03/2001 01:02:18 00187 // Description : 00188 // Return type : TCollection_AsciiString 00189 //================================================================================== 00190 TCollection_AsciiString exotkParameter_Enumeration::ParameterAsString() const 00191 { 00192 TCollection_AsciiString theParameterAsString ; 00193 if ( myMapIntegerAsciiString.IsBound1(myValue) ) 00194 { 00195 theParameterAsString = myMapIntegerAsciiString.Find1(myValue); 00196 } 00197 else 00198 { 00199 theParameterAsString = TCollection_AsciiString(myValue); 00200 } 00201 return theParameterAsString; 00202 } 00203 00204 00205 //================================================================================== 00206 // Function name : exotkParameter_Enumeration::AddEnumerationMember 00207 //================================================================================== 00208 // Written by : Stephane Routelous - 08/03/2001 01:02:24 00209 // Description : 00210 // Return type : Standard_Boolean 00211 //================================================================================== 00212 // Argument : const Standard_Integer anIndex 00213 // Argument : const TCollection_AsciiString &aName 00214 Standard_Boolean exotkParameter_Enumeration::AddEnumerationMember(const Standard_Integer anIndex, const TCollection_AsciiString &aName) 00215 { 00216 if ( !myMapIntegerAsciiString.IsBound1(anIndex) ) 00217 { 00218 if ( !myMapIntegerAsciiString.IsBound2(aName) ) 00219 { 00220 myMapIntegerAsciiString.Bind(anIndex,aName); 00221 return Standard_True; 00222 } 00223 } 00224 return Standard_False; 00225 } 00226 00227 //================================================================================== 00228 // Function name : exotkParameter_Enumeration::EnumerationMember 00229 //================================================================================== 00230 // Written by : Stephane Routelous - 08/03/2001 01:02:26 00231 // Description : 00232 // Return type : Standard_Boolean 00233 //================================================================================== 00234 // Argument : const Standard_Integer anIndex 00235 // Argument : TCollection_AsciiString& aName 00236 Standard_Boolean exotkParameter_Enumeration::EnumerationMember(const Standard_Integer anIndex,TCollection_AsciiString& aName) const 00237 { 00238 if ( myMapIntegerAsciiString.IsBound1(anIndex) ) 00239 { 00240 aName = myMapIntegerAsciiString.Find1(anIndex); 00241 return Standard_True; 00242 } 00243 return Standard_False; 00244 } 00245 00246 //================================================================================== 00247 // Function name : exotkParameter_Enumeration::Dump 00248 //================================================================================== 00249 // Written by : Stephane Routelous - 08/03/2001 01:02:31 00250 // Description : 00251 // Return type : Standard_OStream& 00252 //================================================================================== 00253 // Argument : Standard_OStream& anOS 00254 Standard_OStream& exotkParameter_Enumeration::Dump(Standard_OStream& anOS) const 00255 { 00256 exotkParameter_Root::Dump(anOS); 00257 exotkParameter_DoubleMapIteratorOfDoubleMapIntegerAsciiString theIter; 00258 for ( theIter.Initialize(myMapIntegerAsciiString);theIter.More();theIter.Next() ) 00259 { 00260 anOS << "\t index:" << theIter.Key1() << " Name=" << theIter.Key2().ToCString()<< endl; 00261 } 00262 return anOS; 00263 } 00264 00265 00266 //================================================================================== 00267 // Function name : exotkParameter_Enumeration::EnumInit 00268 //================================================================================== 00269 // Written by : Stephane Routelous - 16/04/2001 21:48:44 00270 // Description : 00271 // Return type : void 00272 //================================================================================== 00273 void exotkParameter_Enumeration::EnumInit() 00274 { 00275 myMapIterator.Initialize(myMapIntegerAsciiString); 00276 } 00277 00278 //================================================================================== 00279 // Function name : exotkParameter_Enumeration::EnumMore 00280 //================================================================================== 00281 // Written by : Stephane Routelous - 16/04/2001 21:48:47 00282 // Description : 00283 // Return type : Standard_Boolean 00284 //================================================================================== 00285 Standard_Boolean exotkParameter_Enumeration::EnumMore() 00286 { 00287 return myMapIterator.More(); 00288 } 00289 00290 //================================================================================== 00291 // Function name : exotkParameter_Enumeration::EnumNext 00292 //================================================================================== 00293 // Written by : Stephane Routelous - 16/04/2001 21:48:50 00294 // Description : 00295 // Return type : void 00296 //================================================================================== 00297 void exotkParameter_Enumeration::EnumNext() 00298 { 00299 myMapIterator.Next(); 00300 } 00301 00302 //================================================================================== 00303 // Function name : exotkParameter_Enumeration::EnumCurrentIndex 00304 //================================================================================== 00305 // Written by : Stephane Routelous - 16/04/2001 21:48:53 00306 // Description : 00307 // Return type : Standard_Integer 00308 //================================================================================== 00309 Standard_Integer exotkParameter_Enumeration::EnumCurrentIndex() 00310 { 00311 return myMapIterator.Key1(); 00312 } 00313 00314 //================================================================================== 00315 // Function name : exotkParameter_Enumeration::EnumCurrentName 00316 //================================================================================== 00317 // Written by : Stephane Routelous - 16/04/2001 21:48:56 00318 // Description : 00319 // Return type : TCollection_AsciiString 00320 //================================================================================== 00321 TCollection_AsciiString exotkParameter_Enumeration::EnumCurrentName() 00322 { 00323 return myMapIterator.Key2(); 00324 } 00325
1.2.12 written by Dimitri van Heesch,
© 1997-2001