EMAN2
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
EMAN::EMObject Class Reference

EMObject is a wrapper class for types including int, float, double, etc as defined in ObjectType. More...

#include <emobject.h>

Collaboration diagram for EMAN::EMObject:
Collaboration graph
[legend]

Public Types

enum  ObjectType {
  UNKNOWN , BOOL , SHORT , UNSIGNEDINT ,
  INT , FLOAT , DOUBLE , STRING ,
  EMDATA , XYDATA , INTARRAY , FLOATARRAY ,
  STRINGARRAY , TRANSFORM , CTF , FLOAT_POINTER ,
  INT_POINTER , VOID_POINTER , TRANSFORMARRAY
}
 

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. More...
 
 EMObject (bool boolean)
 
 EMObject (short)
 
 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 vector< Transform > &tarray)
 
 EMObject (const EMObject &that)
 Copy constructor. More...
 
EMObjectoperator= (const EMObject &that)
 Assigment operator copies pointer locations (emdata, xydata, transform) - does not take ownership deep copies all non pointer objects. More...
 
 ~EMObject ()
 Desctructor Does not free pointers. More...
 
 operator bool () const
 Conversion operators. More...
 
 operator short () const
 
 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< int > () const
 
 operator vector< float > () const
 
 operator vector< string > () const
 
 operator vector< Transform > () 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. More...
 
string to_str () const
 Calls to_str( this->type) More...
 
ObjectType get_type () const
 Get the ObjectType This is an enumerated type first declared in the class EMObjectTypes. More...
 
string get_type_string () const
 Get the ObjectType as a string This is an enumerated type first declared in the class EMObjectTypes. More...
 
void force_CTF ()
 
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. More...
 

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. More...
 

Private Member Functions

void printInfo () const
 A debug function that prints as much information as possibe to cout. More...
 

Static Private Member Functions

static map< ObjectType, string > init ()
 

Private Attributes

union {
   bool   b
 
   short   si
 
   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
 
vector< Transformtransformarray
 
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. More...
 
bool operator!= (const EMObject &e1, const EMObject &e2)
 Friend declaration operator!= namespace EMAN2 operator!= accesses private variables. More...
 

Detailed Description

EMObject is a wrapper class for types including int, float, double, etc as defined in ObjectType.

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 122 of file emobject.h.

Member Enumeration Documentation

◆ ObjectType

Enumerator
UNKNOWN 
BOOL 
SHORT 
UNSIGNEDINT 
INT 
FLOAT 
DOUBLE 
STRING 
EMDATA 
XYDATA 
INTARRAY 
FLOATARRAY 
STRINGARRAY 
TRANSFORM 
CTF 
FLOAT_POINTER 
INT_POINTER 
VOID_POINTER 
TRANSFORMARRAY 

Definition at line 125 of file emobject.h.

Constructor & Destructor Documentation

◆ EMObject() [1/21]

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 131 of file emobject.cpp.

131 :
132 d(0), type(UNKNOWN)
133{
134#ifdef MEMDEBUG
135 allemobjlist.insert(this);
136 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this);
137#endif
138}
ObjectType type
Definition: emobject.h:278

◆ EMObject() [2/21]

EMObject::EMObject ( bool  boolean)

Definition at line 140 of file emobject.cpp.

140 :
141 b(boolean), type(BOOL)
142{
143#ifdef MEMDEBUG
144 allemobjlist.insert(this);
145 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this);
146#endif
147}

◆ EMObject() [3/21]

EMObject::EMObject ( short  sint)

Definition at line 149 of file emobject.cpp.

149 :
150 si(sint), type(SHORT)
151{
152#ifdef MEMDEBUG
153 allemobjlist.insert(this);
154 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this);
155#endif
156}

◆ EMObject() [4/21]

EMObject::EMObject ( int  num)

Definition at line 158 of file emobject.cpp.

158 :
159 n(num), type(INT)
160{
161#ifdef MEMDEBUG
162 allemobjlist.insert(this);
163 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this);
164#endif
165}

◆ EMObject() [5/21]

EMObject::EMObject ( unsigned int  num)

Definition at line 167 of file emobject.cpp.

167 :
168 ui(num), type(UNSIGNEDINT)
169{
170#ifdef MEMDEBUG
171 allemobjlist.insert(this);
172 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this);
173#endif
174}
unsigned int ui
Definition: emobject.h:263

◆ EMObject() [6/21]

EMObject::EMObject ( float  ff)

Definition at line 176 of file emobject.cpp.

176 :
177 type(FLOAT)
178{
179
180#ifdef MEMDEBUG
181 allemobjlist.insert(this);
182 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this);
183#endif
184 if(Util::goodf(&ff)) {
185 f = ff;
186 }
187 else{
188 f = 0.0f;
189 }
190}
static int goodf(const float *p_f)
Check whether a number is a good float.
Definition: util.h:1112

References f, and EMAN::Util::goodf().

◆ EMObject() [7/21]

EMObject::EMObject ( double  dd)

Definition at line 192 of file emobject.cpp.

192 :
193 type(DOUBLE)
194{
195
196#ifdef MEMDEBUG
197 allemobjlist.insert(this);
198 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this);
199#endif
200 if(Util::goodf(&dd)) {
201 d = dd;
202 }
203 else{
204 d = 0.0;
205 }
206}

References d, and EMAN::Util::goodf().

◆ EMObject() [8/21]

EMObject::EMObject ( const char *  s)

Definition at line 208 of file emobject.cpp.

208 :
209 str(s), type(STRING)
210{
211#ifdef MEMDEBUG
212 allemobjlist.insert(this);
213 printf(" +(%6d) %p c*\n",(int)allemobjlist.size(),this);
214#endif
215}
string str
Definition: emobject.h:273

◆ EMObject() [9/21]

EMObject::EMObject ( const string &  s)

Definition at line 217 of file emobject.cpp.

217 :
218 str(s), type(STRING)
219{
220#ifdef MEMDEBUG
221 allemobjlist.insert(this);
222 printf(" +(%6d) %p s\n",(int)allemobjlist.size(),this);
223#endif
224}

◆ EMObject() [10/21]

EMObject::EMObject ( float *  fp)

Definition at line 226 of file emobject.cpp.

226 :
228{
229#ifdef MEMDEBUG
230 allemobjlist.insert(this);
231 printf(" +(%6d) %p f*\n",(int)allemobjlist.size(),this);
232#endif
233}
float * fp
Definition: emobject.h:266

◆ EMObject() [11/21]

EMObject::EMObject ( int *  ip)

Definition at line 235 of file emobject.cpp.

235 :
236 ip(i), type(INT_POINTER)
237{
238#ifdef MEMDEBUG
239 allemobjlist.insert(this);
240 printf(" +(%6d) %p i*\n",(int)allemobjlist.size(),this);
241#endif
242}

◆ EMObject() [12/21]

EMObject::EMObject ( void *  vp)

Definition at line 244 of file emobject.cpp.

244 :
245 vp(v), type(VOID_POINTER)
246{
247#ifdef MEMDEBUG
248 allemobjlist.insert(this);
249 printf(" +(%6d) %p v*\n",(int)allemobjlist.size(),this);
250#endif
251}

◆ EMObject() [13/21]

EMObject::EMObject ( EMData em)

Definition at line 253 of file emobject.cpp.

253 :
254 emdata(em), type(EMDATA)
255{
256#ifdef MEMDEBUG
257 allemobjlist.insert(this);
258 printf(" +(%6d) %p emd\n",(int)allemobjlist.size(),this);
259#endif
260}
EMData * emdata
Definition: emobject.h:269

◆ EMObject() [14/21]

EMObject::EMObject ( XYData xy)

Definition at line 262 of file emobject.cpp.

262 :
263 xydata(xy), type(XYDATA)
264{
265#ifdef MEMDEBUG
266 allemobjlist.insert(this);
267 printf(" +(%6d) %p xyd\n",(int)allemobjlist.size(),this);
268#endif
269}
XYData * xydata
Definition: emobject.h:270

◆ EMObject() [15/21]

EMObject::EMObject ( Transform t)

Definition at line 271 of file emobject.cpp.

271 :
273{
274#ifdef MEMDEBUG
275 allemobjlist.insert(this);
276 printf(" +(%6d) %p xf\n",(int)allemobjlist.size(),this);
277#endif
278}
vector< float > farray
Definition: emobject.h:275
vector< float > get_matrix() const
Get the transformation matrix using a vector.
Definition: transform.cpp:181

◆ EMObject() [16/21]

EMObject::EMObject ( Ctf ctf)

Definition at line 280 of file emobject.cpp.

280 :
281 str(ctf->to_string()), type(CTF)
282{
283#ifdef MEMDEBUG
284 allemobjlist.insert(this);
285 printf(" +(%6d) %p ctf\n",(int)allemobjlist.size(),this);
286#endif
287}
virtual string to_string() const =0

◆ EMObject() [17/21]

EMObject::EMObject ( const vector< int > &  v)

Definition at line 289 of file emobject.cpp.

289 :
290 iarray(v), type(INTARRAY)
291{
292#ifdef MEMDEBUG
293 allemobjlist.insert(this);
294 printf(" +(%6d) %p ia\n",(int)allemobjlist.size(),this);
295#endif
296}
vector< int > iarray
Definition: emobject.h:274

◆ EMObject() [18/21]

EMObject::EMObject ( const vector< float > &  v)

Definition at line 298 of file emobject.cpp.

298 :
300{
301#ifdef MEMDEBUG
302 allemobjlist.insert(this);
303 printf(" +(%6d) %p fa\n",(int)allemobjlist.size(),this);
304#endif
305}

◆ EMObject() [19/21]

EMObject::EMObject ( const vector< string > &  sarray)

Definition at line 307 of file emobject.cpp.

307 :
308 strarray(sarray), type(STRINGARRAY)
309{
310#ifdef MEMDEBUG
311 allemobjlist.insert(this);
312 printf(" +(%6d) %p sa\n",(int)allemobjlist.size(),this);
313#endif
314}
vector< string > strarray
Definition: emobject.h:276

◆ EMObject() [20/21]

EMObject::EMObject ( const vector< Transform > &  tarray)

Definition at line 316 of file emobject.cpp.

316 :
318{
319#ifdef MEMDEBUG
320 allemobjlist.insert(this);
321 printf(" +(%6d) %p xfa\n",(int)allemobjlist.size(),this);
322#endif
323}
vector< Transform > transformarray
Definition: emobject.h:277

◆ EMObject() [21/21]

EMObject::EMObject ( const EMObject that)

Copy constructor.

copies pointer locations - does not take ownership deep copies all non pointer objects

Definition at line 879 of file emobject.cpp.

880{
881 // init isn't necessary because that must have already called it!
882 *this = that;
883#ifdef MEMDEBUG
884 allemobjlist.insert(this);
885 printf(" +(%6d) %p\n",(int)allemobjlist.size(),this);
886#endif
887}

◆ ~EMObject()

EMObject::~EMObject ( )

Desctructor Does not free pointers.

Definition at line 124 of file emobject.cpp.

124 {
125#ifdef MEMDEBUG
126 allemobjlist.erase(this);
127 printf(" -(%6d) %p\n",(int)allemobjlist.size(),this);
128#endif
129}

Member Function Documentation

◆ force_CTF()

void EMAN::EMObject::force_CTF ( )
inline

Definition at line 233 of file emobject.h.

233{ type=CTF; }

References CTF, and type.

◆ get_object_type_name()

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 761 of file emobject.cpp.

762{
763 if ( type_registry.find(t) != type_registry.end() )
764 return type_registry[t];
765 else
766 LOGERR("No such EMObject defined");
767 throw NotExistingObjectException("EMObject", "unknown type");
768}
static map< ObjectType, string > type_registry
Definition: emobject.h:287
#define NotExistingObjectException(objname, desc)
Definition: exception.h:130
#define LOGERR
Definition: log.h:51

References LOGERR, NotExistingObjectException, and type_registry.

Referenced by get_type_string(), and EMAN::TypeDict::put().

◆ get_type()

ObjectType EMAN::EMObject::get_type ( ) const
inline

Get the ObjectType This is an enumerated type first declared in the class EMObjectTypes.

Definition at line 224 of file emobject.h.

224{ return type; }

References type.

Referenced by EMAN::Transform::set_params(), and EMAN::Transform::set_params_inverse().

◆ get_type_string()

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 230 of file emobject.h.

230{ return get_object_type_name(type); }
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.
Definition: emobject.cpp:761

References get_object_type_name(), and type.

◆ init()

map< EMObject::ObjectType, string > EMObject::init ( )
staticprivate

Definition at line 78 of file emobject.cpp.

79{
80 map< EMObject::ObjectType, string> mymap;
81 static bool first_construction = true;
82 if ( first_construction )
83 {
84 // Initialize the the type registry once and for all
85 mymap[BOOL] = "BOOL";
86 mymap[SHORT] = "SHORT";
87 mymap[INT] = "INT";
88 mymap[UNSIGNEDINT] = "UNSIGNEDINT";
89 mymap[FLOAT] = "FLOAT";
90 mymap[DOUBLE] = "DOUBLE";
91 mymap[STRING] = "STRING";
92 mymap[EMDATA] = "EMDATA";
93 mymap[XYDATA] = "XYDATA";
94 mymap[INTARRAY] = "INTARRAY";
95 mymap[FLOATARRAY] = "FLOATARRAY";
96 mymap[STRINGARRAY] = "STRINGARRAY";
97 mymap[TRANSFORM] = "TRANSFORM";
98 mymap[CTF] = "CTF";
99 mymap[FLOAT_POINTER] = "FLOAT_POINTER";
100 mymap[INT_POINTER] = "INT_POINTER";
101 mymap[UNKNOWN] = "UNKNOWN";
102 mymap[VOID_POINTER] = "VOID_POINTER";
103 mymap[TRANSFORMARRAY] = "TRANSFORMARRAY";
104 first_construction = false;
105 }
106
107 return mymap;
108}

References BOOL, CTF, DOUBLE, EMDATA, FLOAT, FLOAT_POINTER, FLOATARRAY, INT, INT_POINTER, INTARRAY, SHORT, STRING, STRINGARRAY, TRANSFORM, TRANSFORMARRAY, UNKNOWN, UNSIGNEDINT, VOID_POINTER, and XYDATA.

◆ is_null()

bool EMObject::is_null ( ) const

Checks to see if the EMObject is interpretable This basically equates to checking to see if the type is UNKNOWN.

Definition at line 679 of file emobject.cpp.

680{
681 return (type == UNKNOWN);
682}

References type, and UNKNOWN.

Referenced by EMAN::EMUtil::dump_dict().

◆ operator bool()

EMObject::operator bool ( ) const

Conversion operators.

Definition at line 325 of file emobject.cpp.

326{
327 if (type == BOOL) {
328 return b;
329 }
330 else if (type == SHORT) {
331 return si != 0;
332 }
333 else if (type == INT) {
334 return n != 0;
335 }
336 else if (type == UNSIGNEDINT) {
337 return ui != 0;
338 }
339 else if (type == FLOAT) {
340 return f != 0;
341 }
342 else if (type == DOUBLE) {
343 return d != 0;
344 }
345 else if (type == EMDATA) {
346 return emdata != 0;
347 }
348 else if (type == XYDATA) {
349 return xydata != 0;
350 }
351 else if (type == FLOAT_POINTER) {
352 return fp != 0;
353 }
354 else if (type == INT_POINTER) {
355 return ip != 0;
356 }
357 else if (type == VOID_POINTER) {
358 return vp != 0;
359 }
360// else if (type == TRANSFORM) {
361// return transform != 0;
362// }
363 // It seemed unconventional to return a boolean for the stl objects
364 else {
365 if (type != UNKNOWN) {
366 throw TypeException("Cannot convert to bool this data type ",
368 }
369 }
370 return 0;
371}
vector< pair< float, int > > vp
#define TypeException(desc, type)
Definition: exception.h:261

References TypeException.

◆ operator const char *()

EMObject::operator const char * ( ) const

Definition at line 533 of file emobject.cpp.

534{
535 if (type != STRING && type != CTF) {
536 stringstream ss;
537 string return_string;
538 if ( type == INT )
539 {
540 ss << n;
541 ss >> return_string;
542 return return_string.c_str();
543 }
544 if ( type == UNSIGNEDINT )
545 {
546 ss << ui;
547 ss >> return_string;
548 return return_string.c_str();
549 }
550 else
551 if ( type == FLOAT )
552 {
553 ss << f;
554 ss >> return_string;
555 return return_string.c_str();
556 }
557 else
558 if ( type == DOUBLE )
559 {
560 ss << d;
561 ss >> return_string;
562 return return_string.c_str();
563 }
564 else if (type != UNKNOWN) {
565 throw TypeException("Cannot convert to string from this data type",
567 }
568
569 return "";
570 }
571 return str.c_str();
572}

References TypeException.

◆ operator Ctf *()

EMObject::operator Ctf * ( ) const

Definition at line 611 of file emobject.cpp.

612{
613/* if(type != CTF) {
614 if(type != CTF) {
615 throw TypeException("Cannot convert to TRANSFORM* from this data type",
616 get_object_type_name(type));
617 }
618 }*/
619 Ctf * ctf = 0;
620 if(str[0] == 'O') {
621 ctf = new EMAN1Ctf();
622 ctf->from_string(str);
623 }
624 else if(str[0] == 'E') {
625 ctf = new EMAN2Ctf();
626 ctf->from_string(str);
627 }
628 return ctf;
629}
Ctf is the base class for all CTF model.
Definition: ctf.h:60
virtual int from_string(const string &ctf)=0
EMAN1Ctf is the CTF model used in EMAN1.
Definition: ctf.h:120
EMAN2Ctf is the default CTF model used in EMAN2.
Definition: ctf.h:237

References EMAN::Ctf::from_string().

◆ operator double()

EMObject::operator double ( ) const

Definition at line 463 of file emobject.cpp.

464{
465 if (type == BOOL) {
466 return b?1.0:0.0;
467 }
468 else if (type == DOUBLE) {
469 return d;
470 }
471 else if (type == SHORT) {
472 return si;
473 }
474 else if (type == INT) {
475 return (double) n;
476 }
477 else if (type == UNSIGNEDINT) {
478 return (double) ui;
479 }
480 else if (type == FLOAT) {
481 return (double) f;
482 }
483 else {
484 if (type != UNKNOWN) {
485 throw TypeException("Cannot convert to double from this data type",
487 }
488 }
489 return 0;
490}

References TypeException.

◆ operator EMData *()

EMObject::operator EMData * ( ) const

Definition at line 574 of file emobject.cpp.

575{
576 if (type != EMDATA) {
577 if (type != UNKNOWN) {
578 throw TypeException("Cannot convert to EMData* from this data type",
580 }
581 return 0;
582 }
583 return emdata;
584}

References TypeException.

◆ operator float()

EMObject::operator float ( ) const

Definition at line 430 of file emobject.cpp.

431{
432 if (type == BOOL) {
433 return b?1.0f:0.0f;
434 }
435 else if (type == FLOAT) {
436 return f;
437 }
438 else if (type == SHORT) {
439 return si;
440 }
441 else if (type == INT) {
442 return (float) n;
443 }
444 else if (type == UNSIGNEDINT) {
445 return (float) ui;
446 }
447 else if (type == DOUBLE) {
448 return (float) d;
449 }
450 else if (type == STRING) {
451 return (float)atof(str.c_str());
452 }
453 else {
454 if (type != UNKNOWN) {
455 throw TypeException("Cannot convert to float from this data type",
457 }
458 }
459
460 return 0;
461}

References TypeException.

◆ operator float *()

EMObject::operator float * ( ) const

Definition at line 507 of file emobject.cpp.

508{
509 if (type != FLOAT_POINTER)
510 {
511 if (type != UNKNOWN)
512 throw TypeException("Cannot convert to float pointer from this data type",
514
515 return 0;
516 }
517
518 return fp;
519}

References TypeException.

◆ operator int()

EMObject::operator int ( ) const

Definition at line 387 of file emobject.cpp.

388{
389 if (type == INT) {
390 return n;
391 }
392 else if (type == SHORT) {
393 return si;
394 }
395 else if (type == UNSIGNEDINT) {
396 return (int) ui;
397 }
398 else if (type == FLOAT) {
399 return (int) f;
400 }
401 else if (type == DOUBLE) {
402 return (int) d;
403 }
404 else if (type == BOOL) {
405 return b?1:0;
406 }
407 else {
408 if (type != UNKNOWN) {
409 throw TypeException("Cannot convert to int this data type ",
411 }
412 }
413 return 0;
414}

References TypeException.

◆ operator int *()

EMObject::operator int * ( ) const

Definition at line 492 of file emobject.cpp.

493{
494 if (type != INT_POINTER)
495 {
496 if (type != UNKNOWN)
497 throw TypeException("Cannot convert to float pointer from this data type",
499
500 return 0;
501 }
502
503 return ip;
504}

References TypeException.

◆ operator short()

EMObject::operator short ( ) const

Definition at line 373 of file emobject.cpp.

374{
375 if (type == SHORT) {
376 return si;
377 }
378 else {
379 if (type != UNKNOWN) {
380 throw TypeException("Cannot convert to int this data type ",
382 }
383 }
384 return 0;
385}

References TypeException.

◆ operator Transform *()

EMObject::operator Transform * ( ) const

Definition at line 598 of file emobject.cpp.

599{
600 if(type != TRANSFORM) {
601 if(type != UNKNOWN) {
602 throw TypeException("Cannot convert to TRANSFORM* from this data type",
604 }
605 }
606 Transform * transform = new Transform();
607 transform->set_matrix(farray);
608 return transform;
609}
A Transform object is a somewhat specialized object designed specifically for EMAN2/Sparx storage of ...
Definition: transform.h:75
void set_matrix(const vector< float > &v)
Set the transformation matrix using a vector.
Definition: transform.cpp:147

References EMAN::Transform::set_matrix(), and TypeException.

◆ operator unsigned int()

EMObject::operator unsigned int ( ) const

Definition at line 416 of file emobject.cpp.

417{
418 if (type == UNSIGNEDINT) {
419 return (unsigned int) ui;
420 }
421 else {
422 if (type != UNKNOWN) {
423 throw TypeException("Cannot convert to int this data type ",
425 }
426 }
427 return 0;
428}

References TypeException.

◆ operator vector< float >()

EMObject::operator vector< float > ( ) const

Definition at line 643 of file emobject.cpp.

644{
645 if (type != FLOATARRAY) {
646 if (type != UNKNOWN) {
647 throw TypeException("Cannot convert to vector<float> from this data type",
649 }
650 return vector < float >();
651 }
652 return farray;
653}

References TypeException.

◆ operator vector< int >()

EMObject::operator vector< int > ( ) const

Definition at line 631 of file emobject.cpp.

632{
633 if( type != INTARRAY )
634 {
635 if( type != UNKNOWN ) {
636 throw TypeException("Cannot convert to vector<int> from this data type", get_object_type_name(type) );
637 }
638 return vector<int>();
639 }
640 return iarray;
641}

References TypeException.

◆ operator vector< string >()

EMObject::operator vector< string > ( ) const

Definition at line 655 of file emobject.cpp.

656{
657 if (type != STRINGARRAY) {
658 if (type != UNKNOWN) {
659 throw TypeException("Cannot convert to vector<string> from this data type",
661 }
662 return vector<string>();
663 }
664 return strarray;
665}

References TypeException.

◆ operator vector< Transform >()

EMObject::operator vector< Transform > ( ) const

Definition at line 667 of file emobject.cpp.

668{
669 if(type != TRANSFORMARRAY) {
670 if (type != UNKNOWN) {
671 throw TypeException("Cannot convert to vector<string> from this data type",
673 }
674 return vector<Transform>();
675 }
676 return transformarray;
677}

References TypeException.

◆ operator void *()

EMObject::operator void * ( ) const

Definition at line 522 of file emobject.cpp.

523{
524 if (type == VOID_POINTER) return vp;
525 else if (type == FLOAT_POINTER) return (void *)fp;
526 else if (type == INT_POINTER) return (void *)ip;
527 else if (type == EMDATA) return (void *) emdata;
528 else if (type == XYDATA) return (void *) xydata;
529// else if (type == TRANSFORM) return (void *) transform;
530 else throw TypeException("Cannot convert to void pointer from this data type", get_object_type_name(type));
531}

References TypeException.

◆ operator XYData *()

EMObject::operator XYData * ( ) const

Definition at line 586 of file emobject.cpp.

587{
588 if (type != XYDATA) {
589 if (type != UNKNOWN) {
590 throw TypeException("Cannot convert to XYData* from this data type",
592 }
593 return 0;
594 }
595 return xydata;
596}

References TypeException.

◆ operator=()

EMObject & EMObject::operator= ( const EMObject that)

Assigment operator copies pointer locations (emdata, xydata, transform) - does not take ownership deep copies all non pointer objects.

Definition at line 893 of file emobject.cpp.

894{
895
896// This test breaks assignment when either the current or assigned values are (float)nan
897// it's also somewhat inherently stupid, since testing for equivalence may cost as much
898// as assignment.
899// if ( *this != that )
900 {
901 // First store the type of the input, At first I forgot to do this and it was a very
902 // difficult bug to track down
903 type = that.type;
904
905// if ( type != this_type ) throw
906
907
908 switch (type)
909 {
910 case BOOL:
911 b = that.b;
912 break;
913 case SHORT:
914 si = that.si;
915 break;
916 case INT:
917 n = that.n;
918 break;
919 case UNSIGNEDINT:
920 ui = that.ui;
921 break;
922 case FLOAT:
923 f = that.f;
924 break;
925 case DOUBLE:
926 d = that.d;
927 break;
928 case CTF:
929 case STRING:
930 str = that.str;
931 break;
932 case FLOAT_POINTER:
933 // Warning - Pointer address copy.
934 fp = that.fp;
935 break;
936 case INT_POINTER:
937 // Warning - Pointer address copy.
938 ip = that.ip;
939 break;
940 case VOID_POINTER:
941 // Warning - Pointer address copy.
942 vp = that.vp;
943 break;
944 case EMDATA:
945 // Warning - Pointer address copy.
946 emdata = that.emdata;
947 break;
948 case XYDATA:
949 // Warning - Pointer address copy.
950 xydata = that.xydata;
951 break;
952 case TRANSFORM:
953 case FLOATARRAY:
954 farray = that.farray;
955 break;
956 case INTARRAY:
957 iarray = that.iarray;
958 break;
959 case STRINGARRAY:
960 strarray = that.strarray;
961 break;
962 case TRANSFORMARRAY:
964 break;
965 case UNKNOWN:
966 // This is possible, nothing should happen
967 // The EMObject's default constructor has been called and
968 // as yet has no type - doing nothing is exactly as the
969 // the assignment operator should work.
970 break;
971 default:
972 LOGERR("No such EMObject defined");
973 throw NotExistingObjectException("EMObject", "unknown type");
974 break;
975 }
976 }
977// else
978// {
979// cerr << "Warning - attempt to assign EMObject onto itself. No action taken" << endl;
980// cerr << "My type is " << get_object_type_name(type) << endl;
981// }
982
983 return *this;
984}

References b, BOOL, CTF, d, DOUBLE, EMDATA, emdata, f, farray, FLOAT, FLOAT_POINTER, FLOATARRAY, fp, iarray, INT, INT_POINTER, INTARRAY, ip, LOGERR, n, NotExistingObjectException, SHORT, si, str, strarray, STRING, STRINGARRAY, TRANSFORM, TRANSFORMARRAY, transformarray, type, ui, UNKNOWN, UNSIGNEDINT, VOID_POINTER, vp, XYDATA, and xydata.

◆ printInfo()

void EMObject::printInfo ( ) const
private

A debug function that prints as much information as possibe to cout.

Definition at line 112 of file emobject.cpp.

113{
114 cout << "The address of my type is " << &type << endl;
115 cout << " Now printing the enumerated values in type_registry " << endl;
116 for( map< ObjectType, string>::const_iterator it = type_registry.begin(); it != type_registry.end(); ++it )
117 {
118 cout << it->first << " " << it->second << endl;
119 }
120 cout << "My type is " << to_str(type) << " and its enumerated value is " << type << endl;
121 cout << "The address of the static type registry is " << &type_registry <<", it should be same for all EMObjects" << endl;
122}
string to_str() const
Calls to_str( this->type)
Definition: emobject.cpp:684

References to_str(), type, and type_registry.

◆ to_str() [1/2]

string EMObject::to_str ( ) const

Calls to_str( this->type)

Definition at line 684 of file emobject.cpp.

685{
686 return to_str(type);
687}

References to_str(), and type.

Referenced by EMAN::EMUtil::dump_dict(), printInfo(), and to_str().

◆ to_str() [2/2]

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 689 of file emobject.cpp.

690{
691 if (argtype == STRING) {
692 return str;
693 }
694 else {
695 char tmp_str[32];
696 if (argtype == BOOL) {
697 if (b)
698 sprintf(tmp_str, "true");
699 else
700 sprintf(tmp_str, "false");
701 }
702 else if (argtype == SHORT) {
703 sprintf(tmp_str, "%hd", si);
704 }
705 else if (argtype == INT) {
706 sprintf(tmp_str, "%d", n);
707 }
708 else if (argtype == UNSIGNEDINT) {
709 sprintf(tmp_str, "%d", ui);
710 }
711 else if (argtype == FLOAT) {
712 sprintf(tmp_str, "%f", f);
713 }
714 else if (argtype == DOUBLE) {
715 sprintf(tmp_str, "%f", d);
716 }
717 else if (argtype == EMDATA) {
718 sprintf(tmp_str, "EMDATA");
719 }
720 else if (argtype == FLOAT_POINTER) {
721 sprintf(tmp_str, "FLOAT_POINTER");
722 }
723 else if (argtype == INT_POINTER) {
724 sprintf(tmp_str, "INT_POINTER");
725 }
726 else if (argtype == VOID_POINTER) {
727 sprintf(tmp_str, "VOID_POINTER");
728 }
729 else if (argtype == XYDATA) {
730 sprintf(tmp_str, "XYDATA");
731 }
732 else if (argtype == INTARRAY) {
733 sprintf(tmp_str, "INTARRAY");
734 }
735 else if (argtype == FLOATARRAY) {
736 sprintf(tmp_str, "FLOATARRAY");
737 }
738 else if (argtype == STRINGARRAY) {
739 sprintf(tmp_str, "STRINGARRAY");
740 }
741 else if (argtype == TRANSFORM) {
742 sprintf(tmp_str, "TRANSFORM");
743 }
744 else if (argtype == TRANSFORMARRAY) {
745 sprintf(tmp_str, "TRANSFORMARRAY");
746 }
747 else if (argtype == CTF) {
748 sprintf(tmp_str, "CTF");
749 }
750 else if (argtype == UNKNOWN) {
751 sprintf(tmp_str, "UNKNOWN");
752 }
753 else {
754 LOGERR("No such EMObject defined");
755 throw NotExistingObjectException("EMObject", "unknown type");
756 }
757 return string(tmp_str);
758 }
759}

References b, BOOL, CTF, d, DOUBLE, EMDATA, f, FLOAT, FLOAT_POINTER, FLOATARRAY, INT, INT_POINTER, INTARRAY, LOGERR, n, NotExistingObjectException, SHORT, si, str, STRING, STRINGARRAY, TRANSFORM, TRANSFORMARRAY, ui, UNKNOWN, UNSIGNEDINT, VOID_POINTER, and XYDATA.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const EMObject e1,
const EMObject e2 
)
friend

Friend declaration operator!= namespace EMAN2 operator!= accesses private variables.

◆ operator==

bool operator== ( const EMObject e1,
const EMObject e2 
)
friend

Friend declaration operator== namespace EMAN2 operator== accesses private variables.

Member Data Documentation

◆ 

union { ... } EMAN::EMObject::@1

◆ b

bool EMAN::EMObject::b

Definition at line 260 of file emobject.h.

Referenced by operator=(), EMAN::operator==(), and to_str().

◆ d

double EMAN::EMObject::d

Definition at line 265 of file emobject.h.

Referenced by EMObject(), operator=(), EMAN::operator==(), and to_str().

◆ emdata

EMData* EMAN::EMObject::emdata

Definition at line 269 of file emobject.h.

Referenced by operator=(), and EMAN::operator==().

◆ f

float EMAN::EMObject::f

Definition at line 264 of file emobject.h.

Referenced by EMObject(), operator=(), EMAN::operator==(), and to_str().

◆ farray

vector<float> EMAN::EMObject::farray
private

Definition at line 275 of file emobject.h.

Referenced by operator=(), and EMAN::operator==().

◆ fp

float* EMAN::EMObject::fp

Definition at line 266 of file emobject.h.

Referenced by operator=(), and EMAN::operator==().

◆ iarray

vector<int> EMAN::EMObject::iarray
private

Definition at line 274 of file emobject.h.

Referenced by operator=(), and EMAN::operator==().

◆ ip

int* EMAN::EMObject::ip

Definition at line 267 of file emobject.h.

Referenced by operator=(), and EMAN::operator==().

◆ n

int EMAN::EMObject::n

Definition at line 262 of file emobject.h.

Referenced by operator=(), EMAN::operator==(), and to_str().

◆ si

short EMAN::EMObject::si

Definition at line 261 of file emobject.h.

Referenced by operator=(), EMAN::operator==(), and to_str().

◆ str

string EMAN::EMObject::str
private

Definition at line 273 of file emobject.h.

Referenced by operator=(), EMAN::operator==(), and to_str().

◆ strarray

vector<string> EMAN::EMObject::strarray
private

Definition at line 276 of file emobject.h.

Referenced by operator=(), and EMAN::operator==().

◆ transformarray

vector<Transform> EMAN::EMObject::transformarray
private

Definition at line 277 of file emobject.h.

Referenced by operator=(), and EMAN::operator==().

◆ type

ObjectType EMAN::EMObject::type
private

◆ type_registry

map< EMObject::ObjectType, string > EMObject::type_registry = init()
staticprivate

Definition at line 287 of file emobject.h.

Referenced by get_object_type_name(), and printInfo().

◆ ui

unsigned int EMAN::EMObject::ui

Definition at line 263 of file emobject.h.

Referenced by operator=(), EMAN::operator==(), and to_str().

◆ vp

void* EMAN::EMObject::vp

Definition at line 268 of file emobject.h.

Referenced by operator=(), and EMAN::operator==().

◆ xydata

XYData* EMAN::EMObject::xydata

Definition at line 270 of file emobject.h.

Referenced by operator=(), and EMAN::operator==().


The documentation for this class was generated from the following files: