#include <emobject.h>
Collaboration diagram for EMAN::EMObject:
Public Types | |
UNKNOWN | |
BOOL | |
UNSIGNEDINT | |
INT | |
FLOAT | |
DOUBLE | |
STRING | |
EMDATA | |
XYDATA | |
INTARRAY | |
FLOATARRAY | |
STRINGARRAY | |
TRANSFORM | |
CTF | |
FLOAT_POINTER | |
INT_POINTER | |
VOID_POINTER | |
enum | ObjectType { UNKNOWN, BOOL, UNSIGNEDINT, INT, FLOAT, DOUBLE, STRING, EMDATA, XYDATA, INTARRAY, FLOATARRAY, STRINGARRAY, TRANSFORM, CTF, FLOAT_POINTER, INT_POINTER, VOID_POINTER } |
Public Member Functions | |
EMObject () | |
Constructors for each type More types could be added, but all of the accompanying functions would have to be altered to ensure correct functioning. | |
EMObject (bool boolean) | |
EMObject (int num) | |
EMObject (unsigned int num) | |
EMObject (float ff) | |
EMObject (double dd) | |
EMObject (const char *s) | |
EMObject (const string &s) | |
EMObject (float *fp) | |
EMObject (int *ip) | |
EMObject (void *vp) | |
EMObject (EMData *em) | |
EMObject (XYData *xy) | |
EMObject (Transform *t) | |
EMObject (Ctf *ctf) | |
EMObject (const vector< int > &v) | |
EMObject (const vector< float > &v) | |
EMObject (const vector< string > &sarray) | |
EMObject (const EMObject &that) | |
Copy constructor. | |
EMObject & | operator= (const EMObject &that) |
Assigment operator copies pointer locations (emdata, xydata, transform3d) - does not take ownership deep copies all non pointer objects. | |
~EMObject () | |
Desctructor Does not free pointers. | |
operator bool () const | |
Conversion operators. | |
operator int () const | |
operator unsigned int () const | |
operator float () const | |
operator double () const | |
operator const char * () const | |
operator float * () const | |
operator int * () const | |
operator void * () const | |
operator EMData * () const | |
operator XYData * () const | |
operator Transform * () const | |
operator Ctf * () const | |
operator vector () const | |
operator vector () const | |
operator vector () const | |
bool | is_null () const |
Checks to see if the EMObject is interpretable This basically equates to checking to see if the type is UNKNOWN. | |
string | to_str () const |
Calls to_str( this->type). | |
ObjectType | get_type () const |
Get the ObjectType This is an enumerated type first declared in the class EMObjectTypes. | |
string | get_type_string () const |
Get the ObjectType as a string This is an enumerated type first declared in the class EMObjectTypes. | |
string | to_str (ObjectType type) const |
Write the EMObject's value to a string Literally copies into a string, except for the case where the type is boolen where it writes true of false, as opposed to 1 or 0. | |
Static Public Member Functions | |
static string | get_object_type_name (ObjectType t) |
Get an ObjectType as a string statically Can be accessed without the instantiation of a class object. | |
Private Member Functions | |
void | printInfo () const |
A debug function that prints as much information as possibe to cout. | |
Static Private Member Functions | |
static map< ObjectType, string > | init () |
Private Attributes | |
union { | |
bool b | |
int n | |
unsigned int ui | |
float f | |
double d | |
float * fp | |
int * ip | |
void * vp | |
EMData * emdata | |
XYData * xydata | |
}; | |
string | str |
vector< int > | iarray |
vector< float > | farray |
vector< string > | strarray |
ObjectType | type |
Static Private Attributes | |
static map< ObjectType, string > | type_registry = init() |
Friends | |
bool | operator== (const EMObject &e1, const EMObject &e2) |
Friend declaration operator== namespace EMAN2 operator== accesses private variables. | |
bool | operator!= (const EMObject &e1, const EMObject &e2) |
Friend declaration operator!= namespace EMAN2 operator!= accesses private variables. |
Each type is typically used as follows ('int' is the example):
int a = 12; EMObject o(a); EMObject o2 = a; // implicit converter from int to EMObject. int a1 = o; // implicit converter from EMObject to int.
EMObjects may store pointers but they currently do not assume ownership - that is, the memory associated with a pointer is never freed by an EMObject.
This type of class design is sometimes referred to as the Variant pattern.
See the testing code in rt/emdata/test_emobject.cpp for prewritten testing code
Definition at line 125 of file emobject.h.
UNKNOWN | |
BOOL | |
UNSIGNEDINT | |
INT | |
FLOAT | |
DOUBLE | |
STRING | |
EMDATA | |
XYDATA | |
INTARRAY | |
FLOATARRAY | |
STRINGARRAY | |
TRANSFORM | |
CTF | |
FLOAT_POINTER | |
INT_POINTER | |
VOID_POINTER |
Definition at line 128 of file emobject.h.
00128 { 00129 UNKNOWN, 00130 BOOL, 00131 UNSIGNEDINT, 00132 INT, 00133 FLOAT, 00134 DOUBLE, 00135 STRING, 00136 EMDATA, 00137 XYDATA, 00138 INTARRAY, 00139 FLOATARRAY, 00140 STRINGARRAY, 00141 TRANSFORM, 00142 CTF, 00143 FLOAT_POINTER, 00144 INT_POINTER, 00145 VOID_POINTER 00146 };
EMObject::EMObject | ( | ) |
Constructors for each type More types could be added, but all of the accompanying functions would have to be altered to ensure correct functioning.
Definition at line 133 of file emobject.cpp.
00133 : 00134 d(0), type(UNKNOWN) 00135 { 00136 #ifdef MEMDEBUG 00137 allemobjlist.insert(this); 00138 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this); 00139 #endif 00140 }
EMObject::EMObject | ( | bool | boolean | ) |
Definition at line 142 of file emobject.cpp.
00142 : 00143 b(boolean), type(BOOL) 00144 { 00145 #ifdef MEMDEBUG 00146 allemobjlist.insert(this); 00147 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this); 00148 #endif 00149 }
EMObject::EMObject | ( | int | num | ) |
Definition at line 151 of file emobject.cpp.
00151 : 00152 n(num), type(INT) 00153 { 00154 #ifdef MEMDEBUG 00155 allemobjlist.insert(this); 00156 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this); 00157 #endif 00158 }
EMObject::EMObject | ( | unsigned int | num | ) |
Definition at line 160 of file emobject.cpp.
00160 : 00161 ui(num), type(UNSIGNEDINT) 00162 { 00163 #ifdef MEMDEBUG 00164 allemobjlist.insert(this); 00165 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this); 00166 #endif 00167 }
EMObject::EMObject | ( | float | ff | ) |
Definition at line 169 of file emobject.cpp.
References f, and EMAN::Util::goodf().
00169 : 00170 type(FLOAT) 00171 { 00172 00173 #ifdef MEMDEBUG 00174 allemobjlist.insert(this); 00175 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this); 00176 #endif 00177 if(Util::goodf(&ff)) { 00178 f = ff; 00179 } 00180 else{ 00181 f = 0.0f; 00182 } 00183 }
EMObject::EMObject | ( | double | dd | ) |
Definition at line 185 of file emobject.cpp.
References d, and EMAN::Util::goodf().
00185 : 00186 type(DOUBLE) 00187 { 00188 00189 #ifdef MEMDEBUG 00190 allemobjlist.insert(this); 00191 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this); 00192 #endif 00193 if(Util::goodf(&dd)) { 00194 d = dd; 00195 } 00196 else{ 00197 d = 0.0; 00198 } 00199 }
EMObject::EMObject | ( | const char * | s | ) |
Definition at line 201 of file emobject.cpp.
00201 : 00202 str(s), type(STRING) 00203 { 00204 #ifdef MEMDEBUG 00205 allemobjlist.insert(this); 00206 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this); 00207 #endif 00208 }
EMObject::EMObject | ( | const string & | s | ) |
Definition at line 210 of file emobject.cpp.
00210 : 00211 str(s), type(STRING) 00212 { 00213 #ifdef MEMDEBUG 00214 allemobjlist.insert(this); 00215 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this); 00216 #endif 00217 }
EMObject::EMObject | ( | float * | fp | ) |
Definition at line 219 of file emobject.cpp.
00219 : 00220 fp(f), type(FLOAT_POINTER) 00221 { 00222 #ifdef MEMDEBUG 00223 allemobjlist.insert(this); 00224 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this); 00225 #endif 00226 }
EMObject::EMObject | ( | int * | ip | ) |
Definition at line 228 of file emobject.cpp.
00228 : 00229 ip(i), type(INT_POINTER) 00230 { 00231 #ifdef MEMDEBUG 00232 allemobjlist.insert(this); 00233 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this); 00234 #endif 00235 }
EMObject::EMObject | ( | void * | vp | ) |
Definition at line 237 of file emobject.cpp.
00237 : 00238 vp(v), type(VOID_POINTER) 00239 { 00240 #ifdef MEMDEBUG 00241 allemobjlist.insert(this); 00242 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this); 00243 #endif 00244 }
EMObject::EMObject | ( | EMData * | em | ) |
Definition at line 246 of file emobject.cpp.
00246 : 00247 emdata(em), type(EMDATA) 00248 { 00249 #ifdef MEMDEBUG 00250 allemobjlist.insert(this); 00251 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this); 00252 #endif 00253 }
EMObject::EMObject | ( | XYData * | xy | ) |
Definition at line 255 of file emobject.cpp.
00255 : 00256 xydata(xy), type(XYDATA) 00257 { 00258 #ifdef MEMDEBUG 00259 allemobjlist.insert(this); 00260 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this); 00261 #endif 00262 }
EMObject::EMObject | ( | Transform * | t | ) |
EMObject::EMObject | ( | Ctf * | ctf | ) |
EMObject::EMObject | ( | const vector< int > & | v | ) |
EMObject::EMObject | ( | const vector< float > & | v | ) |
Definition at line 291 of file emobject.cpp.
00291 : 00292 farray(v), type(FLOATARRAY) 00293 { 00294 #ifdef MEMDEBUG 00295 allemobjlist.insert(this); 00296 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this); 00297 #endif 00298 }
EMObject::EMObject | ( | const vector< string > & | sarray | ) |
Definition at line 300 of file emobject.cpp.
00300 : 00301 strarray(sarray), type(STRINGARRAY) 00302 { 00303 #ifdef MEMDEBUG 00304 allemobjlist.insert(this); 00305 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this); 00306 #endif 00307 }
EMObject::EMObject | ( | const EMObject & | that | ) |
Copy constructor.
copies pointer locations - does not take ownership deep copies all non pointer objects
Definition at line 865 of file emobject.cpp.
00866 { 00867 // init isn't necessary because that must have already called it! 00868 *this = that; 00869 #ifdef MEMDEBUG 00870 allemobjlist.insert(this); 00871 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this); 00872 #endif 00873 }
EMObject::~EMObject | ( | ) |
Desctructor Does not free pointers.
Definition at line 126 of file emobject.cpp.
00126 { 00127 #ifdef MEMDEBUG 00128 allemobjlist.erase(this); 00129 printf(" -(%6d) %p\n",(int)allemobjlist.size(),this); 00130 #endif 00131 }
string EMObject::get_object_type_name | ( | ObjectType | t | ) | [static] |
Get an ObjectType as a string statically Can be accessed without the instantiation of a class object.
Definition at line 698 of file emobject.cpp.
References BOOL, CTF, DOUBLE, EMDATA, FLOAT, FLOAT_POINTER, FLOATARRAY, INT, INT_POINTER, INTARRAY, LOGERR, NotExistingObjectException, STRING, STRINGARRAY, TRANSFORM, type_registry, UNKNOWN, UNSIGNEDINT, VOID_POINTER, and XYDATA.
Referenced by get_type_string(), operator bool(), operator const char *(), operator double(), operator EMData *(), operator float(), operator float *(), operator int(), operator int *(), operator Transform *(), operator unsigned int(), operator vector(), operator void *(), operator XYData *(), and EMAN::TypeDict::put().
00699 { 00700 #ifdef _WIN32 00701 if (t == BOOL) { 00702 return "BOOL"; 00703 }else 00704 if ( t == INT){ 00705 return "INT"; 00706 }else 00707 if ( t == UNSIGNEDINT){ 00708 return "UNSIGNEDINT"; 00709 } else 00710 if ( t == FLOAT){ 00711 return "FLOAT"; 00712 } else 00713 if ( t == DOUBLE){ 00714 return "DOUBLE"; 00715 }else 00716 if ( t == STRING){ 00717 return "STRING"; 00718 }else 00719 if ( t == EMDATA){ 00720 return "EMDATA"; 00721 } 00722 else 00723 if ( t == XYDATA){ 00724 return "XYDATA"; 00725 }else 00726 if ( t == INTARRAY){ 00727 return "INTARRAY"; 00728 }else 00729 if ( t == FLOATARRAY){ 00730 return "FLOATARRAY"; 00731 } else 00732 if ( t == STRINGARRAY){ 00733 return "STRINGARRAY"; 00734 }else 00735 if ( t == TRANSFORM){ 00736 return "TRANSFORM"; 00737 }else 00738 if ( t == CTF){ 00739 return "CTF"; 00740 }else 00741 if ( t == FLOAT_POINTER){ 00742 return "FLOAT_POINTER"; 00743 }else 00744 if ( t == INT_POINTER){ 00745 return "INT_POINTER"; 00746 }else 00747 if ( t == UNKNOWN){ 00748 return "UNKNOWN"; 00749 } else 00750 if ( t == VOID_POINTER){ 00751 return "VOID_POINTER"; 00752 } 00753 else { 00754 LOGERR("No such EMObject defined"); 00755 throw NotExistingObjectException("EMObject", "unknown type"); 00756 } 00757 00758 #else 00759 00760 if ( type_registry.find(t) != type_registry.end() ) 00761 return type_registry[t]; 00762 else 00763 LOGERR("No such EMObject defined"); 00764 throw NotExistingObjectException("EMObject", "unknown type"); 00765 #endif //_WIN32 00766 }
ObjectType EMAN::EMObject::get_type | ( | ) | const [inline] |
Get the ObjectType This is an enumerated type first declared in the class EMObjectTypes.
Definition at line 221 of file emobject.h.
References type.
00221 { return type; }
string EMAN::EMObject::get_type_string | ( | ) | const [inline] |
Get the ObjectType as a string This is an enumerated type first declared in the class EMObjectTypes.
Definition at line 227 of file emobject.h.
References get_object_type_name(), and type.
00227 { return get_object_type_name(type); }
map< EMObject::ObjectType, string > EMObject::init | ( | ) | [static, private] |
Definition at line 82 of file emobject.cpp.
References BOOL, CTF, DOUBLE, EMDATA, FLOAT, FLOAT_POINTER, FLOATARRAY, INT, INT_POINTER, INTARRAY, STRING, STRINGARRAY, TRANSFORM, UNKNOWN, UNSIGNEDINT, VOID_POINTER, and XYDATA.
00083 { 00084 map< EMObject::ObjectType, string> mymap; 00085 static bool first_construction = true; 00086 if ( first_construction ) 00087 { 00088 // Initialize the the type registry once and for all 00089 mymap[BOOL] = "BOOL"; 00090 mymap[INT] = "INT"; 00091 mymap[UNSIGNEDINT] = "UNSIGNEDINT"; 00092 mymap[FLOAT] = "FLOAT"; 00093 mymap[DOUBLE] = "DOUBLE"; 00094 mymap[STRING] = "STRING"; 00095 mymap[EMDATA] = "EMDATA"; 00096 mymap[XYDATA] = "XYDATA"; 00097 mymap[INTARRAY] = "INTARRAY"; 00098 mymap[FLOATARRAY] = "FLOATARRAY"; 00099 mymap[STRINGARRAY] = "STRINGARRAY"; 00100 mymap[TRANSFORM] = "TRANFORM"; 00101 mymap[CTF] = "CTF"; 00102 mymap[FLOAT_POINTER] = "FLOAT_POINTER"; 00103 mymap[INT_POINTER] = "INT_POINTER"; 00104 mymap[UNKNOWN] = "UNKNOWN"; 00105 mymap[VOID_POINTER] = "VOID_POINTER"; 00106 first_construction = false; 00107 } 00108 00109 return mymap; 00110 }
bool EMObject::is_null | ( | ) | const |
EMObject::operator bool | ( | ) | const |
Conversion operators.
Definition at line 309 of file emobject.cpp.
References b, BOOL, d, DOUBLE, emdata, EMDATA, f, FLOAT, FLOAT_POINTER, fp, get_object_type_name(), INT, INT_POINTER, ip, n, type, TypeException, ui, UNKNOWN, UNSIGNEDINT, VOID_POINTER, xydata, and XYDATA.
00310 { 00311 if (type == BOOL) { 00312 return b; 00313 } 00314 else if (type == INT) { 00315 return n != 0; 00316 } 00317 else if (type == UNSIGNEDINT) { 00318 return ui != 0; 00319 } 00320 else if (type == FLOAT) { 00321 return f != 0; 00322 } 00323 else if (type == DOUBLE) { 00324 return d != 0; 00325 } 00326 else if (type == EMDATA) { 00327 return emdata != 0; 00328 } 00329 else if (type == XYDATA) { 00330 return xydata != 0; 00331 } 00332 else if (type == FLOAT_POINTER) { 00333 return fp != 0; 00334 } 00335 else if (type == INT_POINTER) { 00336 return ip != 0; 00337 } 00338 else if (type == VOID_POINTER) { 00339 return vp != 0; 00340 } 00341 // else if (type == TRANSFORM) { 00342 // return transform != 0; 00343 // } 00344 // It seemed unconventional to return a boolean for the stl objects 00345 else { 00346 if (type != UNKNOWN) { 00347 throw TypeException("Cannot convert to bool this data type ", 00348 get_object_type_name(type)); 00349 } 00350 } 00351 return 0; 00352 }
EMObject::operator const char * | ( | ) | const |
Definition at line 488 of file emobject.cpp.
References CTF, d, DOUBLE, f, FLOAT, get_object_type_name(), INT, n, str, STRING, type, TypeException, ui, UNKNOWN, and UNSIGNEDINT.
00489 { 00490 if (type != STRING && type != CTF) { 00491 stringstream ss; 00492 string return_string; 00493 if ( type == INT ) 00494 { 00495 ss << n; 00496 ss >> return_string; 00497 return return_string.c_str(); 00498 } 00499 if ( type == UNSIGNEDINT ) 00500 { 00501 ss << ui; 00502 ss >> return_string; 00503 return return_string.c_str(); 00504 } 00505 else 00506 if ( type == FLOAT ) 00507 { 00508 ss << f; 00509 ss >> return_string; 00510 return return_string.c_str(); 00511 } 00512 else 00513 if ( type == DOUBLE ) 00514 { 00515 ss << d; 00516 ss >> return_string; 00517 return return_string.c_str(); 00518 } 00519 else if (type != UNKNOWN) { 00520 throw TypeException("Cannot convert to string from this data type", 00521 get_object_type_name(type)); 00522 } 00523 00524 return ""; 00525 } 00526 return str.c_str(); 00527 }
EMObject::operator Ctf * | ( | ) | const |
Definition at line 566 of file emobject.cpp.
References EMAN::Ctf::from_string(), and str.
00567 { 00568 /* if(type != CTF) { 00569 if(type != CTF) { 00570 throw TypeException("Cannot convert to TRANSFORM* from this data type", 00571 get_object_type_name(type)); 00572 } 00573 }*/ 00574 Ctf * ctf = 0; 00575 if(str[0] == 'O') { 00576 ctf = new EMAN1Ctf(); 00577 ctf->from_string(str); 00578 } 00579 else if(str[0] == 'E') { 00580 ctf = new EMAN2Ctf(); 00581 ctf->from_string(str); 00582 } 00583 return ctf; 00584 }
EMObject::operator double | ( | ) | const |
Definition at line 421 of file emobject.cpp.
References b, BOOL, d, DOUBLE, f, FLOAT, get_object_type_name(), INT, n, type, TypeException, ui, UNKNOWN, and UNSIGNEDINT.
00422 { 00423 if (type == BOOL) { 00424 return b?1.0:0.0; 00425 } 00426 else if (type == DOUBLE) { 00427 return d; 00428 } 00429 else if (type == INT) { 00430 return (double) n; 00431 } 00432 else if (type == UNSIGNEDINT) { 00433 return (double) ui; 00434 } 00435 else if (type == FLOAT) { 00436 return (double) f; 00437 } 00438 else { 00439 if (type != UNKNOWN) { 00440 throw TypeException("Cannot convert to double from this data type", 00441 get_object_type_name(type)); 00442 } 00443 } 00444 return 0; 00445 }
EMObject::operator EMData * | ( | ) | const |
Definition at line 529 of file emobject.cpp.
References emdata, EMDATA, get_object_type_name(), type, TypeException, and UNKNOWN.
00530 { 00531 if (type != EMDATA) { 00532 if (type != UNKNOWN) { 00533 throw TypeException("Cannot convert to EMData* from this data type", 00534 get_object_type_name(type)); 00535 } 00536 return 0; 00537 } 00538 return emdata; 00539 }
EMObject::operator float | ( | ) | const |
Definition at line 394 of file emobject.cpp.
References b, BOOL, d, DOUBLE, f, FLOAT, get_object_type_name(), INT, n, type, TypeException, ui, UNKNOWN, and UNSIGNEDINT.
00395 { 00396 if (type == BOOL) { 00397 return b?1.0f:0.0f; 00398 } 00399 else if (type == FLOAT) { 00400 return f; 00401 } 00402 else if (type == INT) { 00403 return (float) n; 00404 } 00405 else if (type == UNSIGNEDINT) { 00406 return (float) ui; 00407 } 00408 else if (type == DOUBLE) { 00409 return (float) d; 00410 } 00411 else { 00412 if (type != UNKNOWN) { 00413 throw TypeException("Cannot convert to float from this data type", 00414 get_object_type_name(type)); 00415 } 00416 } 00417 00418 return 0; 00419 }
EMObject::operator float * | ( | ) | const |
Definition at line 462 of file emobject.cpp.
References FLOAT_POINTER, fp, get_object_type_name(), type, TypeException, and UNKNOWN.
00463 { 00464 if (type != FLOAT_POINTER) 00465 { 00466 if (type != UNKNOWN) 00467 throw TypeException("Cannot convert to float pointer from this data type", 00468 get_object_type_name(type)); 00469 00470 return 0; 00471 } 00472 00473 return fp; 00474 }
EMObject::operator int | ( | ) | const |
Definition at line 354 of file emobject.cpp.
References b, BOOL, d, DOUBLE, f, FLOAT, get_object_type_name(), INT, n, type, TypeException, ui, UNKNOWN, and UNSIGNEDINT.
00355 { 00356 if (type == INT) { 00357 return n; 00358 } 00359 else if (type == UNSIGNEDINT) { 00360 return (int) ui; 00361 } 00362 else if (type == FLOAT) { 00363 return (int) f; 00364 } 00365 else if (type == DOUBLE) { 00366 return (int) d; 00367 } 00368 else if (type == BOOL) { 00369 return b?1:0; 00370 } 00371 else { 00372 if (type != UNKNOWN) { 00373 throw TypeException("Cannot convert to int this data type ", 00374 get_object_type_name(type)); 00375 } 00376 } 00377 return 0; 00378 }
EMObject::operator int * | ( | ) | const |
Definition at line 447 of file emobject.cpp.
References get_object_type_name(), INT_POINTER, ip, type, TypeException, and UNKNOWN.
00448 { 00449 if (type != INT_POINTER) 00450 { 00451 if (type != UNKNOWN) 00452 throw TypeException("Cannot convert to float pointer from this data type", 00453 get_object_type_name(type)); 00454 00455 return 0; 00456 } 00457 00458 return ip; 00459 }
EMObject::operator Transform * | ( | ) | const |
Definition at line 553 of file emobject.cpp.
References farray, get_object_type_name(), EMAN::Transform::set_matrix(), TRANSFORM, type, TypeException, and UNKNOWN.
00554 { 00555 if(type != TRANSFORM) { 00556 if(type != UNKNOWN) { 00557 throw TypeException("Cannot convert to TRANSFORM* from this data type", 00558 get_object_type_name(type)); 00559 } 00560 } 00561 Transform * transform = new Transform(); 00562 transform->set_matrix(farray); 00563 return transform; 00564 }
EMObject::operator unsigned int | ( | ) | const |
Definition at line 380 of file emobject.cpp.
References get_object_type_name(), type, TypeException, ui, UNKNOWN, and UNSIGNEDINT.
00381 { 00382 if (type == UNSIGNEDINT) { 00383 return (unsigned int) ui; 00384 } 00385 else { 00386 if (type != UNKNOWN) { 00387 throw TypeException("Cannot convert to int this data type ", 00388 get_object_type_name(type)); 00389 } 00390 } 00391 return 0; 00392 }
EMAN::EMObject::operator vector | ( | ) | const |
EMAN::EMObject::operator vector | ( | ) | const |
EMObject::operator vector< string > | ( | ) | const |
Definition at line 586 of file emobject.cpp.
References get_object_type_name(), iarray, INTARRAY, type, TypeException, and UNKNOWN.
00587 { 00588 if( type != INTARRAY ) 00589 { 00590 if( type != UNKNOWN ) { 00591 throw TypeException("Cannot convert to vector<int> from this data type", get_object_type_name(type) ); 00592 } 00593 return vector<int>(); 00594 } 00595 return iarray; 00596 }
EMObject::operator void * | ( | ) | const |
Definition at line 477 of file emobject.cpp.
References emdata, EMDATA, FLOAT_POINTER, fp, get_object_type_name(), INT_POINTER, ip, type, TypeException, VOID_POINTER, xydata, and XYDATA.
00478 { 00479 if (type == VOID_POINTER) return vp; 00480 else if (type == FLOAT_POINTER) return (void *)fp; 00481 else if (type == INT_POINTER) return (void *)ip; 00482 else if (type == EMDATA) return (void *) emdata; 00483 else if (type == XYDATA) return (void *) xydata; 00484 // else if (type == TRANSFORM) return (void *) transform; 00485 else throw TypeException("Cannot convert to void pointer from this data type", get_object_type_name(type)); 00486 }
EMObject::operator XYData * | ( | ) | const |
Definition at line 541 of file emobject.cpp.
References get_object_type_name(), type, TypeException, UNKNOWN, xydata, and XYDATA.
00542 { 00543 if (type != XYDATA) { 00544 if (type != UNKNOWN) { 00545 throw TypeException("Cannot convert to XYData* from this data type", 00546 get_object_type_name(type)); 00547 } 00548 return 0; 00549 } 00550 return xydata; 00551 }
Assigment operator copies pointer locations (emdata, xydata, transform3d) - does not take ownership deep copies all non pointer objects.
Definition at line 879 of file emobject.cpp.
References b, BOOL, CTF, d, DOUBLE, emdata, EMDATA, f, farray, FLOAT, FLOAT_POINTER, FLOATARRAY, fp, iarray, INT, INT_POINTER, INTARRAY, ip, LOGERR, n, NotExistingObjectException, str, strarray, STRING, STRINGARRAY, TRANSFORM, type, ui, UNKNOWN, UNSIGNEDINT, VOID_POINTER, vp, xydata, and XYDATA.
00880 { 00881 00882 // This test breaks assignment when either the current or assigned values are (float)nan 00883 // it's also somewhat inherently stupid, since testing for equivalence may cost as much 00884 // as assignment. 00885 // if ( *this != that ) 00886 { 00887 // First store the type of the input, At first I forgot to do this and it was a very 00888 // difficult bug to track down 00889 type = that.type; 00890 00891 // if ( type != this_type ) throw 00892 00893 00894 switch (type) 00895 { 00896 case BOOL: 00897 b = that.b; 00898 break; 00899 case INT: 00900 n = that.n; 00901 break; 00902 case UNSIGNEDINT: 00903 ui = that.ui; 00904 break; 00905 case FLOAT: 00906 f = that.f; 00907 break; 00908 case DOUBLE: 00909 d = that.d; 00910 break; 00911 case CTF: 00912 case STRING: 00913 str = that.str; 00914 break; 00915 case FLOAT_POINTER: 00916 // Warning - Pointer address copy. 00917 fp = that.fp; 00918 break; 00919 case INT_POINTER: 00920 // Warning - Pointer address copy. 00921 ip = that.ip; 00922 break; 00923 case VOID_POINTER: 00924 // Warning - Pointer address copy. 00925 vp = that.vp; 00926 break; 00927 case EMDATA: 00928 // Warning - Pointer address copy. 00929 emdata = that.emdata; 00930 break; 00931 case XYDATA: 00932 // Warning - Pointer address copy. 00933 xydata = that.xydata; 00934 break; 00935 case TRANSFORM: 00936 case FLOATARRAY: 00937 farray = that.farray; 00938 break; 00939 case INTARRAY: 00940 iarray = that.iarray; 00941 break; 00942 case STRINGARRAY: 00943 strarray = that.strarray; 00944 break; 00945 case UNKNOWN: 00946 // This is possible, nothing should happen 00947 // The EMObject's default constructor has been called and 00948 // as yet has no type - doing nothing is exactly as the 00949 // the assignment operator should work. 00950 break; 00951 default: 00952 LOGERR("No such EMObject defined"); 00953 throw NotExistingObjectException("EMObject", "unknown type"); 00954 break; 00955 } 00956 } 00957 // else 00958 // { 00959 // cerr << "Warning - attempt to assign EMObject onto itself. No action taken" << endl; 00960 // cerr << "My type is " << get_object_type_name(type) << endl; 00961 // } 00962 00963 return *this; 00964 }
void EMObject::printInfo | ( | ) | const [private] |
A debug function that prints as much information as possibe to cout.
Definition at line 114 of file emobject.cpp.
References to_str(), type, and type_registry.
00115 { 00116 cout << "The address of my type is " << &type << endl; 00117 cout << " Now printing the enumerated values in type_registry " << endl; 00118 for( map< ObjectType, string>::const_iterator it = type_registry.begin(); it != type_registry.end(); ++it ) 00119 { 00120 cout << it->first << " " << it->second << endl; 00121 } 00122 cout << "My type is " << to_str(type) << " and its enumerated value is " << type << endl; 00123 cout << "The address of the static type registry is " << &type_registry <<", it should be same for all EMObjects" << endl; 00124 }
string EMObject::to_str | ( | ObjectType | type | ) | const |
Write the EMObject's value to a string Literally copies into a string, except for the case where the type is boolen where it writes true of false, as opposed to 1 or 0.
Definition at line 632 of file emobject.cpp.
References b, BOOL, CTF, d, DOUBLE, EMDATA, f, FLOAT, FLOAT_POINTER, FLOATARRAY, INT, INTARRAY, LOGERR, n, NotExistingObjectException, str, STRING, STRINGARRAY, TRANSFORM, ui, UNKNOWN, UNSIGNEDINT, VOID_POINTER, and XYDATA.
00633 { 00634 if (argtype == STRING) { 00635 return str; 00636 } 00637 else { 00638 char tmp_str[32]; 00639 if (argtype == BOOL) { 00640 if (b) 00641 sprintf(tmp_str, "true"); 00642 else 00643 sprintf(tmp_str, "false"); 00644 } 00645 else if (argtype == INT) { 00646 sprintf(tmp_str, "%d", n); 00647 } 00648 else if (argtype == UNSIGNEDINT) { 00649 sprintf(tmp_str, "%d", ui); 00650 } 00651 else if (argtype == FLOAT) { 00652 sprintf(tmp_str, "%f", f); 00653 } 00654 else if (argtype == DOUBLE) { 00655 sprintf(tmp_str, "%f", d); 00656 } 00657 else if (argtype == EMDATA) { 00658 sprintf(tmp_str, "EMDATA"); 00659 } 00660 else if (argtype == FLOAT_POINTER) { 00661 sprintf(tmp_str, "FLOAT_POINTER"); 00662 } 00663 else if (argtype == INT) { 00664 sprintf(tmp_str, "INT_POINTER"); 00665 } 00666 else if (argtype == VOID_POINTER) { 00667 sprintf(tmp_str, "VOID_POINTER"); 00668 } 00669 else if (argtype == XYDATA) { 00670 sprintf(tmp_str, "XYDATA"); 00671 } 00672 else if (argtype == INTARRAY) { 00673 sprintf(tmp_str, "INTARRAY"); 00674 } 00675 else if (argtype == FLOATARRAY) { 00676 sprintf(tmp_str, "FLOATARRAY"); 00677 } 00678 else if (argtype == STRINGARRAY) { 00679 sprintf(tmp_str, "STRINGARRAY"); 00680 } 00681 else if (argtype == TRANSFORM) { 00682 sprintf(tmp_str, "TRANSFORMD"); 00683 } 00684 else if (argtype == CTF) { 00685 sprintf(tmp_str, "CTF"); 00686 } 00687 else if (argtype == UNKNOWN) { 00688 sprintf(tmp_str, "UNKNOWN"); 00689 } 00690 else { 00691 LOGERR("No such EMObject defined"); 00692 throw NotExistingObjectException("EMObject", "unknown type"); 00693 } 00694 return string(tmp_str); 00695 } 00696 }
string EMObject::to_str | ( | ) | const |
Calls to_str( this->type).
Definition at line 627 of file emobject.cpp.
References type.
Referenced by printInfo().
Friend declaration operator!= namespace EMAN2 operator!= accesses private variables.
Definition at line 859 of file emobject.cpp.
Friend declaration operator== namespace EMAN2 operator== accesses private variables.
Definition at line 768 of file emobject.cpp.
00769 { 00770 00771 if (e1.type != e2.type) { 00772 return false; 00773 } 00774 00775 switch (e1.type) { 00776 case EMObject::BOOL: 00777 return (e1.b == e2.b); 00778 break; 00779 case EMObject::INT: 00780 return (e1.n == e2.n); 00781 break; 00782 case EMObject::UNSIGNEDINT: 00783 return (e1.ui == e2.ui); 00784 break; 00785 case EMObject::FLOAT: 00786 return (e1.f == e2.f); 00787 break; 00788 case EMObject::DOUBLE: 00789 return (e1.d == e2.d); 00790 break; 00791 case EMObject::CTF: 00792 case EMObject::STRING: 00793 return (e1.str == e2.str); 00794 break; 00795 case EMObject::FLOAT_POINTER: 00796 return (e1.fp == e2.fp); 00797 break; 00798 case EMObject::INT_POINTER: 00799 return (e1.ip == e2.ip); 00800 break; 00801 case EMObject::VOID_POINTER: 00802 return (e1.vp == e2.vp); 00803 break; 00804 case EMObject::EMDATA: 00805 return (e1.emdata == e2.emdata); 00806 break; 00807 case EMObject::XYDATA: 00808 return (e1.xydata == e2.xydata); 00809 break; 00810 case EMObject::TRANSFORM: 00811 case EMObject::FLOATARRAY: 00812 if (e1.farray.size() == e2.farray.size()) { 00813 for (size_t i = 0; i < e1.farray.size(); i++) { 00814 if (e1.farray[i] != e2.farray[i]) { 00815 return false; 00816 } 00817 } 00818 return true; 00819 } 00820 else { 00821 return false; 00822 } 00823 break; 00824 case EMObject::INTARRAY: 00825 if (e1.iarray.size() == e2.iarray.size()) { 00826 for (size_t i = 0; i < e1.iarray.size(); i++) { 00827 if (e1.iarray[i] != e2.iarray[i]) { 00828 return false; 00829 } 00830 } 00831 return true; 00832 } 00833 break; 00834 case EMObject::STRINGARRAY: 00835 if (e1.strarray.size() == e2.strarray.size()) { 00836 for (size_t i = 0; i < e1.strarray.size(); i++) { 00837 if (e1.strarray[i] != e2.strarray[i]) { 00838 return false; 00839 } 00840 } 00841 return true; 00842 } 00843 else { 00844 return false; 00845 } 00846 break; 00847 case EMObject::UNKNOWN: 00848 // UNKNOWN really means "no type" and if two objects both have 00849 // type UNKNOWN they really are the same 00850 return (e1.type == e2.type); 00851 break; 00852 default: 00853 return false; 00854 break; 00855 } 00856 return false; 00857 }
union { ... } [private] |
bool EMAN::EMObject::b [private] |
Definition at line 255 of file emobject.h.
Referenced by operator bool(), operator double(), operator float(), operator int(), operator=(), EMAN::operator==(), and to_str().
double EMAN::EMObject::d [private] |
Definition at line 259 of file emobject.h.
Referenced by EMObject(), operator bool(), operator const char *(), operator double(), operator float(), operator int(), operator=(), EMAN::operator==(), and to_str().
EMData* EMAN::EMObject::emdata [private] |
Definition at line 263 of file emobject.h.
Referenced by operator bool(), operator EMData *(), operator void *(), operator=(), and EMAN::operator==().
float EMAN::EMObject::f [private] |
Definition at line 258 of file emobject.h.
Referenced by EMAN::FRCCmp::cmp(), EMAN::PhaseCmp::cmp(), EMObject(), EMAN::nn4Reconstructor::insert_slice(), EMAN::PointArray::match_points(), operator bool(), operator const char *(), operator double(), operator float(), operator int(), operator=(), EMAN::operator==(), EMAN::Util::pad(), EMAN::ToMassCenterProcessor::process_inplace(), EMAN::EMData::rotate_translate(), and to_str().
vector< float > EMAN::EMObject::farray [private] |
Definition at line 269 of file emobject.h.
Referenced by operator Transform *(), operator=(), and EMAN::operator==().
float* EMAN::EMObject::fp [private] |
Definition at line 260 of file emobject.h.
Referenced by operator bool(), operator float *(), operator void *(), operator=(), and EMAN::operator==().
vector< int > EMAN::EMObject::iarray [private] |
Definition at line 268 of file emobject.h.
Referenced by operator vector(), operator=(), and EMAN::operator==().
int* EMAN::EMObject::ip [private] |
Definition at line 261 of file emobject.h.
Referenced by operator bool(), operator int *(), operator void *(), operator=(), and EMAN::operator==().
int EMAN::EMObject::n [private] |
Definition at line 256 of file emobject.h.
Referenced by operator bool(), operator const char *(), operator double(), operator float(), operator int(), operator=(), EMAN::operator==(), and to_str().
string EMAN::EMObject::str [private] |
Definition at line 267 of file emobject.h.
Referenced by operator const char *(), operator Ctf *(), operator=(), EMAN::operator==(), and to_str().
vector< string> EMAN::EMObject::strarray [private] |
ObjectType EMAN::EMObject::type [private] |
Definition at line 271 of file emobject.h.
Referenced by get_type(), get_type_string(), is_null(), operator bool(), operator const char *(), operator double(), operator EMData *(), operator float(), operator float *(), operator int(), operator int *(), operator Transform *(), operator unsigned int(), operator vector(), operator void *(), operator XYData *(), operator=(), EMAN::operator==(), printInfo(), and to_str().
map< EMObject::ObjectType, string > EMObject::type_registry = init() [static, private] |
unsigned int EMAN::EMObject::ui [private] |
Definition at line 257 of file emobject.h.
Referenced by operator bool(), operator const char *(), operator double(), operator float(), operator int(), operator unsigned int(), operator=(), EMAN::operator==(), and to_str().
void* EMAN::EMObject::vp [private] |
XYData* EMAN::EMObject::xydata [private] |
Definition at line 264 of file emobject.h.
Referenced by operator bool(), operator void *(), operator XYData *(), operator=(), and EMAN::operator==().