Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #if !defined(ALIZE_Object_cpp)
00056 #define ALIZE_Object_cpp
00057
00058 #if defined(_WIN32)
00059 #define _CRT_SECURE_NO_WARNINGS
00060 #endif
00061
00062 #include <cstdlib>
00063 #include <cstdio>
00064 #include "Object.h"
00065 #include "alizeString.h"
00066 #include "Exception.h"
00067
00068 using namespace alize;
00069
00070 #if !defined(NDEBUG)
00071 unsigned long Object::_creationCounter = 0;
00072 unsigned long Object::_destructionCounter = 0;
00073 unsigned long Object::_max = 0;
00074 #endif
00075
00076 bool Object::_initialized = false;
00077 const real_t Object::MIN_COV = 1e-200;
00078 const real_t Object::EPS_LK = 1e-200;
00079 const real_t Object::PI = 3.14159265358979323846;
00080 const real_t Object::PI2 = 3.14159265358979323846*2;
00081
00082 const K K::k;
00083 namespace alize
00084 {
00085 ALIZE_API const TopDistribsAction DETERMINE_TOP_DISTRIBS;
00086 ALIZE_API const TopDistribsAction USE_TOP_DISTRIBS;
00087 ALIZE_API const TopDistribsAction TOP_DISTRIBS_NO_ACTION;
00088 }
00089
00090 Object::Object()
00091 {
00092 if (!_initialized)
00093 {
00094 if (sizeof(char) != 1 ||
00095 sizeof(short) != 2 ||
00096 sizeof(int) != 4 ||
00097 sizeof(unsigned int) != 4 ||
00098
00099
00100 sizeof(float) != 4 ||
00101 sizeof(double) != 8 )
00102 exit(-1);
00103
00104 const_cast<TopDistribsAction&>(DETERMINE_TOP_DISTRIBS)._i = 0;
00105 const_cast<TopDistribsAction&>(USE_TOP_DISTRIBS)._i = 1;
00106 const_cast<TopDistribsAction&>(TOP_DISTRIBS_NO_ACTION)._i = 2;
00107 _initialized = true;
00108 }
00109
00110 #if !defined NDEBUG
00111 _creationCounter++;
00112 unsigned long diff = _creationCounter-_destructionCounter;
00113 if (diff > _max)
00114 _max = diff;
00115 #endif
00116 }
00117
00118 String Object::toString() const
00119 { return "[ " + getClassName() + " " + getAddress() + " ]"; }
00120
00121 String Object::getAddress() const
00122 {
00123 char str[50];
00124 ::sprintf(str, "%p", (void*)this);
00125 return str;
00126 }
00127
00128 bool Object::isSameObject(const Object& o) const
00129 { return this == &o; }
00130
00131 #if !defined NDEBUG
00132 unsigned long Object::getCreationCounter()
00133 { return _creationCounter; }
00134
00135 unsigned long Object::getDestructionCounter()
00136 { return _destructionCounter; throw Exception("", "", 1);}
00137
00138 unsigned long Object::getMax()
00139 { return _max; }
00140 #endif
00141
00142 void Object::assertIsInBounds(const char* fileName, int line,
00143 unsigned long i, unsigned long size)
00144 {
00145 if (i >= size)
00146 throw IndexOutOfBoundsException("", __FILE__, __LINE__, i, size);
00147 }
00148
00149 void Object::assertMemoryIsAllocated(const void* p, const char* f, int l)
00150 {
00151 if (p == NULL)
00152 throw OutOfMemoryException("", f, l);
00153 }
00154
00155 unsigned long Object::max(unsigned long a, unsigned long b)
00156 { return (a>=b?a:b); }
00157
00158 String Object::getParamTypeName(ParamType t)
00159 {
00160 if (t == PARAMTYPE_INTEGER)
00161 return "INTEGER";
00162 if (t == PARAMTYPE_FLOAT)
00163 return "FLOAT";
00164 if (t == PARAMTYPE_BOOLEAN)
00165 return "BOOLEAN";
00166 if (t == PARAMTYPE_STRING)
00167 return "STRING";
00168 if (t == PARAMTYPE_UNDEFINED)
00169 return "";
00170 throw Exception("", __FILE__, __LINE__);
00171 }
00172
00173 ParamType Object::getParamType(const String& s)
00174 {
00175 if (s == "INTEGER")
00176 return PARAMTYPE_INTEGER;
00177 if (s == "FLOAT")
00178 return PARAMTYPE_FLOAT;
00179 if (s == "BOOLEAN")
00180 return PARAMTYPE_BOOLEAN;
00181 if (s == "STRING")
00182 return PARAMTYPE_STRING;
00183 if (s == "")
00184 return PARAMTYPE_UNDEFINED;
00185 throw Exception("", __FILE__, __LINE__);
00186 }
00187
00188 MixtureServerFileWriterFormat Object::getMixtureServerFileWriterFormat(const String& name)
00189 {
00190 if (name == "XML")
00191 return MixtureServerFileWriterFormat_XML;
00192 if (name == "RAW")
00193 return MixtureServerFileWriterFormat_RAW;
00194 throw Exception("Unavailable mixture file format name '" + name + "'",
00195 __FILE__, __LINE__);
00196 return MixtureServerFileWriterFormat_RAW;
00197 }
00198
00199 String Object::getDistribTypeName(DistribType t)
00200 {
00201 if (t == DistribType_GD)
00202 return "GD";
00203 return "GF";
00204 }
00205
00206 DistribType Object::getDistribType(const String& name)
00207 {
00208 if (name == "GD")
00209 return DistribType_GD;
00210 if (name == "GF")
00211 return DistribType_GF;
00212 throw Exception("Unavailable distrib type name '" + name + "'",
00213 __FILE__, __LINE__);
00214 return DistribType_GD;
00215 }
00216
00217 FeatureFileReaderFormat Object::getFeatureFileReaderFormat(const String& name)
00218 {
00219 if (name == "SPRO3")
00220 return FeatureFileReaderFormat_SPRO3;
00221 if (name == "SPRO4")
00222 return FeatureFileReaderFormat_SPRO4;
00223 if (name == "RAW")
00224 return FeatureFileReaderFormat_RAW;
00225 if (name == "HTK")
00226 return FeatureFileReaderFormat_HTK;
00227 throw Exception("Unavailable feature file format name '" + name + "'",
00228 __FILE__, __LINE__);
00229 return FeatureFileReaderFormat_RAW;
00230 }
00231
00232 SPRO3DataKind Object::getSPro3DataKind(const String& name)
00233 {
00234 if (name == "OTHER")
00235 return SPRO3DataKind_OTHER;
00236 if (name == "FBANK")
00237 return SPRO3DataKind_FBANK;
00238 if (name == "FBCEPSTRA")
00239 return SPRO3DataKind_FBCEPSTRA;
00240 if (name == "LPCEPSTRA")
00241 return SPRO3DataKind_LPCEPSTRA;
00242 if (name == "LPCOEFF")
00243 return SPRO3DataKind_LPCOEFF;
00244 if (name == "PARCOR")
00245 return SPRO3DataKind_PARCOR;
00246 if (name == "LAR")
00247 return SPRO3DataKind_LAR;
00248 throw Exception("Unavailable data kind name '" + name + "'",
00249 __FILE__, __LINE__);
00250 return SPRO3DataKind_OTHER;
00251 }
00252
00253 SegServerFileReaderFormat Object::getSegServerFileReaderFormat(const String& name)
00254 {
00255 if (name == "XML")
00256 return SegServerFileReaderFormat_XML;
00257 if (name == ".seg")
00258 return SegServerFileReaderFormat_LIUM;
00259 if (name == "RAW")
00260 return SegServerFileReaderFormat_RAW;
00261 throw Exception("Unavailable segServer file format name '" + name + "'",
00262 __FILE__, __LINE__);
00263 return SegServerFileReaderFormat_LIUM;
00264 }
00265
00266 SegServerFileWriterFormat Object::getSegServerFileWriterFormat(const String& n)
00267 {
00268 if (n == "XML")
00269 return SegServerFileWriterFormat_XML;
00270 if (n == ".seg")
00271 return SegServerFileWriterFormat_LIUM;
00272 if (n == "RAW")
00273 return SegServerFileWriterFormat_RAW;
00274 if (n == "TRS")
00275 return SegServerFileWriterFormat_TRS;
00276 throw Exception("Unavailable segServer file format name '" + n + "'",
00277 __FILE__, __LINE__);
00278 return SegServerFileWriterFormat_XML;
00279 }
00280
00281 MixtureFileWriterFormat Object::getMixtureFileWriterFormat(const String& name)
00282 {
00283 if (name == "XML")
00284 return MixtureFileWriterFormat_XML;
00285 if (name == "RAW")
00286 return MixtureFileWriterFormat_RAW;
00287 if (name == "ETAT")
00288 return MixtureFileWriterFormat_ETAT;
00289 throw Exception("Unavailable mixture file format name '" + name + "'",
00290 __FILE__, __LINE__);
00291 return MixtureFileWriterFormat_RAW;
00292 }
00293
00294 FeatureFileWriterFormat Object::getFeatureFileWriterFormat(const String& name)
00295 {
00296 if (name == "SPRO3")
00297 return FeatureFileWriterFormat_SPRO3;
00298 if (name == "SPRO4")
00299 return FeatureFileWriterFormat_SPRO4;
00300 if (name == "RAW")
00301 return FeatureFileWriterFormat_RAW;
00302 throw Exception("Unavailable feature file format name '" + name + "'",
00303 __FILE__, __LINE__);
00304 return FeatureFileWriterFormat_RAW;
00305 }
00306
00307 MixtureFileReaderFormat Object::getMixtureFileReaderFormat(const String& name)
00308 {
00309 if (name == "AMIRAL")
00310 return MixtureFileReaderFormat_AMIRAL;
00311 if (name == "XML")
00312 return MixtureFileReaderFormat_XML;
00313 if (name == "RAW")
00314 return MixtureFileReaderFormat_RAW;
00315 throw Exception("Unavailable mixture file format name '" + name + "'",
00316 __FILE__, __LINE__);
00317 return MixtureFileReaderFormat_RAW;
00318 }
00319
00320 Object::~Object()
00321 {
00322 #if !defined NDEBUG
00323 _destructionCounter++;
00324 unsigned long diff = _creationCounter-_destructionCounter;
00325 if (diff > _max)
00326 _max = diff;
00327 #endif
00328 }
00329
00330
00331
00332 #endif // !defined(ALIZE_Object_cpp)
00333