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]
List of all members.

Public Types

 UNKNOWN
 BOOL
 UNSIGNEDINT
 INT
 FLOAT
 DOUBLE
 STRING
 EMDATA
 XYDATA
 INTARRAY
 FLOATARRAY
 STRINGARRAY
 TRANSFORM
 CTF
 FLOAT_POINTER
 INT_POINTER
 VOID_POINTER
 TRANSFORMARRAY
enum  ObjectType {
  UNKNOWN, BOOL, 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.
 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 vector< Transform > &tarray)
 EMObject (const EMObject &that)
 Copy constructor.
EMObjectoperator= (const EMObject &that)
 Assigment operator copies pointer locations (emdata, xydata, transform) - 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
 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
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.
bool operator!= (const EMObject &e1, const EMObject &e2)
 Friend declaration operator!= namespace EMAN2 operator!= accesses private variables.

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


Member Enumeration Documentation

enum EMAN::EMObject::ObjectType

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

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                         TRANSFORMARRAY
00147                 };


Constructor & Destructor Documentation

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

00134                    :
00135         d(0), type(UNKNOWN)
00136 {
00137 #ifdef MEMDEBUG
00138         allemobjlist.insert(this);
00139         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00140 #endif
00141 }

EMObject::EMObject ( bool  boolean  ) 

Definition at line 143 of file emobject.cpp.

00143                                :
00144         b(boolean), type(BOOL)
00145 {
00146 #ifdef MEMDEBUG
00147         allemobjlist.insert(this);
00148         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00149 #endif
00150 }

EMObject::EMObject ( int  num  ) 

Definition at line 152 of file emobject.cpp.

00152                           :
00153         n(num), type(INT)
00154 {
00155 #ifdef MEMDEBUG
00156         allemobjlist.insert(this);
00157         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00158 #endif
00159 }

EMObject::EMObject ( unsigned int  num  ) 

Definition at line 161 of file emobject.cpp.

00161                                    :
00162         ui(num), type(UNSIGNEDINT)
00163 {
00164 #ifdef MEMDEBUG
00165         allemobjlist.insert(this);
00166         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00167 #endif
00168 }

EMObject::EMObject ( float  ff  ) 

Definition at line 170 of file emobject.cpp.

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

00170                            :
00171         type(FLOAT)
00172 {
00173 
00174 #ifdef MEMDEBUG
00175         allemobjlist.insert(this);
00176         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00177 #endif
00178         if(Util::goodf(&ff)) {
00179                 f = ff;
00180         }
00181         else{
00182                 f = 0.0f;
00183         }
00184 }

EMObject::EMObject ( double  dd  ) 

Definition at line 186 of file emobject.cpp.

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

00186                             :
00187         type(DOUBLE)
00188 {
00189 
00190 #ifdef MEMDEBUG
00191         allemobjlist.insert(this);
00192         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00193 #endif
00194         if(Util::goodf(&dd)) {
00195                 d = dd;
00196         }
00197         else{
00198                 d = 0.0;
00199         }
00200 }

EMObject::EMObject ( const char *  s  ) 

Definition at line 202 of file emobject.cpp.

00202                                 :
00203         str(s), type(STRING)
00204 {
00205 #ifdef MEMDEBUG
00206         allemobjlist.insert(this);
00207         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00208 #endif
00209 }

EMObject::EMObject ( const string &  s  ) 

Definition at line 211 of file emobject.cpp.

00211                                    :
00212         str(s), type(STRING)
00213 {
00214 #ifdef MEMDEBUG
00215         allemobjlist.insert(this);
00216         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00217 #endif
00218 }

EMObject::EMObject ( float *  fp  ) 

Definition at line 220 of file emobject.cpp.

00220                            :
00221         fp(f), type(FLOAT_POINTER)
00222 {
00223 #ifdef MEMDEBUG
00224         allemobjlist.insert(this);
00225         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00226 #endif
00227 }

EMObject::EMObject ( int *  ip  ) 

Definition at line 229 of file emobject.cpp.

00229                          :
00230         ip(i), type(INT_POINTER)
00231 {
00232 #ifdef MEMDEBUG
00233         allemobjlist.insert(this);
00234         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00235 #endif
00236 }

EMObject::EMObject ( void *  vp  ) 

Definition at line 238 of file emobject.cpp.

00238                           :
00239         vp(v), type(VOID_POINTER)
00240 {
00241 #ifdef MEMDEBUG
00242         allemobjlist.insert(this);
00243         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00244 #endif
00245 }

EMObject::EMObject ( EMData em  ) 

Definition at line 247 of file emobject.cpp.

00247                                 :
00248         emdata(em), type(EMDATA)
00249 {
00250 #ifdef MEMDEBUG
00251         allemobjlist.insert(this);
00252         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00253 #endif
00254 }

EMObject::EMObject ( XYData xy  ) 

Definition at line 256 of file emobject.cpp.

00256                               :
00257         xydata(xy), type(XYDATA)
00258 {
00259 #ifdef MEMDEBUG
00260         allemobjlist.insert(this);
00261         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00262 #endif
00263 }

EMObject::EMObject ( Transform t  ) 

Definition at line 265 of file emobject.cpp.

00265                                :
00266         farray(t->get_matrix()), type(TRANSFORM)
00267 {
00268 #ifdef MEMDEBUG
00269         allemobjlist.insert(this);
00270         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00271 #endif
00272 }

EMObject::EMObject ( Ctf ctf  ) 

Definition at line 274 of file emobject.cpp.

00274                             :
00275         str(ctf->to_string()), type(CTF)
00276 {
00277 #ifdef MEMDEBUG
00278         allemobjlist.insert(this);
00279         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00280 #endif
00281 }

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

Definition at line 283 of file emobject.cpp.

00283                                           :
00284         iarray(v), type(INTARRAY)
00285 {
00286 #ifdef MEMDEBUG
00287         allemobjlist.insert(this);
00288         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00289 #endif
00290 }

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

Definition at line 292 of file emobject.cpp.

00292                                            :
00293         farray(v), type(FLOATARRAY)
00294 {
00295 #ifdef MEMDEBUG
00296         allemobjlist.insert(this);
00297         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00298 #endif
00299 }

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

Definition at line 301 of file emobject.cpp.

00301                                                 :
00302         strarray(sarray), type(STRINGARRAY)
00303 {
00304 #ifdef MEMDEBUG
00305         allemobjlist.insert(this);
00306         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00307 #endif
00308 }

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

Definition at line 310 of file emobject.cpp.

00310                                                    :
00311         transformarray(tarray), type(TRANSFORMARRAY)
00312 {
00313 #ifdef MEMDEBUG
00314         allemobjlist.insert(this);
00315         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00316 #endif
00317 }

EMObject::EMObject ( const EMObject that  ) 

Copy constructor.

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

Definition at line 902 of file emobject.cpp.

00903 {
00904         // init isn't necessary because that must have already called it!
00905         *this = that;
00906 #ifdef MEMDEBUG
00907         allemobjlist.insert(this);
00908         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00909 #endif
00910 }

EMObject::~EMObject (  ) 

Desctructor Does not free pointers.

Definition at line 127 of file emobject.cpp.

00127                     {
00128 #ifdef MEMDEBUG
00129         allemobjlist.erase(this);
00130         printf("  -(%6d) %p\n",(int)allemobjlist.size(),this);
00131 #endif
00132 }


Member Function Documentation

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

References BOOL, CTF, DOUBLE, EMDATA, FLOAT, FLOAT_POINTER, FLOATARRAY, INT, INT_POINTER, INTARRAY, LOGERR, NotExistingObjectException, STRING, STRINGARRAY, TRANSFORM, TRANSFORMARRAY, 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().

00724 {
00725 #ifdef _WIN32
00726         if (t == BOOL) {
00727                 return "BOOL";
00728         }else
00729         if ( t == INT){
00730                 return "INT";
00731         }else
00732         if ( t == UNSIGNEDINT){
00733                 return "UNSIGNEDINT";
00734         } else
00735         if ( t == FLOAT){
00736                 return "FLOAT";
00737         } else
00738         if ( t == DOUBLE){
00739                 return "DOUBLE";
00740         }else
00741         if ( t == STRING){
00742                 return "STRING";
00743         }else
00744         if ( t == EMDATA){
00745                 return "EMDATA";
00746         }
00747         else
00748         if ( t == XYDATA){
00749                 return "XYDATA";
00750         }else
00751         if ( t == INTARRAY){
00752                 return "INTARRAY";
00753         }else
00754         if ( t == FLOATARRAY){
00755                 return "FLOATARRAY";
00756         } else
00757         if ( t == STRINGARRAY){
00758                 return "STRINGARRAY";
00759         }else
00760         if ( t == TRANSFORM){
00761                 return "TRANSFORM";
00762         }else
00763         if ( t == TRANSFORMARRAY){
00764                 return "TRANSFORMARRAY";
00765         }
00766         if ( t == CTF){
00767                 return "CTF";
00768         }else
00769         if ( t == FLOAT_POINTER){
00770                 return "FLOAT_POINTER";
00771         }else
00772         if ( t == INT_POINTER){
00773                 return "INT_POINTER";
00774         }else
00775         if ( t == UNKNOWN){
00776                 return "UNKNOWN";
00777         } else
00778         if ( t == VOID_POINTER){
00779                 return "VOID_POINTER";
00780         }
00781         else {
00782                 LOGERR("No such EMObject defined");
00783                 throw NotExistingObjectException("EMObject", "unknown type");
00784         }
00785 
00786 #else
00787 
00788         if  ( type_registry.find(t) != type_registry.end() )
00789                 return type_registry[t];
00790         else
00791                 LOGERR("No such EMObject defined");
00792                 throw NotExistingObjectException("EMObject", "unknown type");
00793 #endif  //_WIN32
00794 }

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.

References type.

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

References get_object_type_name(), and type.

00230 { 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, TRANSFORMARRAY, 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                 mymap[TRANSFORMARRAY] = "TRANSFORMARRAY";
00107                 first_construction = false;
00108         }
00109         
00110         return mymap;
00111 }

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

References type, and UNKNOWN.

00645 {
00646         return (type == UNKNOWN);
00647 }

EMObject::operator bool (  )  const

Conversion operators.

Definition at line 319 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.

00320 {
00321         if (type == BOOL) {
00322                 return b;
00323         }
00324         else if (type == INT) {
00325                 return n != 0;
00326         }
00327         else if (type == UNSIGNEDINT) {
00328                 return ui != 0;
00329         }
00330         else if (type == FLOAT) {
00331                 return f != 0;
00332         }
00333         else if (type == DOUBLE) {
00334                 return d != 0;
00335         }
00336         else if (type == EMDATA) {
00337                 return emdata != 0;
00338         }
00339         else if (type == XYDATA) {
00340                 return xydata != 0;
00341         }
00342         else if (type == FLOAT_POINTER) {
00343                 return fp != 0;
00344         }
00345         else if (type == INT_POINTER) {
00346                 return ip != 0;
00347         }
00348         else if (type == VOID_POINTER) {
00349                 return vp != 0;
00350         }
00351 //      else if (type == TRANSFORM) {
00352 //              return transform != 0;
00353 //      }
00354         // It seemed unconventional to return a boolean for the stl objects
00355         else {
00356                 if (type != UNKNOWN) {
00357                         throw TypeException("Cannot convert to bool this data type ",
00358                                                                 get_object_type_name(type));
00359                 }
00360         }
00361         return 0;
00362 }

EMObject::operator const char * (  )  const

Definition at line 498 of file emobject.cpp.

References CTF, d, DOUBLE, f, FLOAT, get_object_type_name(), INT, n, str, STRING, type, TypeException, ui, UNKNOWN, and UNSIGNEDINT.

00499 {
00500         if (type != STRING && type != CTF) {
00501                 stringstream ss;
00502                 string return_string;
00503                 if ( type == INT )
00504                 {
00505                         ss << n;
00506                         ss >> return_string;
00507                         return return_string.c_str();
00508                 }
00509                 if ( type == UNSIGNEDINT )
00510                 {
00511                         ss << ui;
00512                         ss >> return_string;
00513                         return return_string.c_str();
00514                 }
00515                 else
00516                 if ( type == FLOAT )
00517                 {
00518                         ss << f;
00519                         ss >> return_string;
00520                         return return_string.c_str();
00521                 }
00522                 else
00523                 if ( type == DOUBLE )
00524                 {
00525                         ss << d;
00526                         ss >> return_string;
00527                         return return_string.c_str();
00528                 }
00529                 else if (type != UNKNOWN) {
00530                         throw TypeException("Cannot convert to string from this data type",
00531                                                                 get_object_type_name(type));
00532                 }
00533 
00534                 return "";
00535         }
00536         return str.c_str();
00537 }

EMObject::operator Ctf * (  )  const

Definition at line 576 of file emobject.cpp.

References EMAN::Ctf::from_string(), and str.

00577 {
00578 /*      if(type != CTF) {
00579                 if(type != CTF) {
00580                         throw TypeException("Cannot convert to TRANSFORM* from this data type",
00581                                                                 get_object_type_name(type));
00582                 }
00583         }*/
00584         Ctf * ctf = 0;
00585         if(str[0] == 'O') {
00586                 ctf = new EMAN1Ctf();
00587                 ctf->from_string(str);
00588         }
00589         else if(str[0] == 'E') {
00590                 ctf = new EMAN2Ctf();
00591                 ctf->from_string(str);
00592         }
00593         return ctf;
00594 }

EMObject::operator double (  )  const

Definition at line 431 of file emobject.cpp.

References b, BOOL, d, DOUBLE, f, FLOAT, get_object_type_name(), INT, n, type, TypeException, ui, UNKNOWN, and UNSIGNEDINT.

00432 {
00433         if (type == BOOL) {
00434         return b?1.0:0.0;
00435         }
00436         else if (type == DOUBLE) {
00437                 return d;
00438         }
00439         else if (type == INT) {
00440                 return (double) n;
00441         }
00442         else if (type == UNSIGNEDINT) {
00443                 return (double) ui;
00444         }
00445         else if (type == FLOAT) {
00446                 return (double) f;
00447         }
00448         else {
00449                 if (type != UNKNOWN) {
00450                         throw TypeException("Cannot convert to double from this data type",
00451                                                                 get_object_type_name(type));
00452                 }
00453         }
00454         return 0;
00455 }

EMObject::operator EMData * (  )  const

Definition at line 539 of file emobject.cpp.

References emdata, EMDATA, get_object_type_name(), type, TypeException, and UNKNOWN.

00540 {
00541         if (type != EMDATA) {
00542                 if (type != UNKNOWN) {
00543                         throw TypeException("Cannot convert to EMData* from this data type",
00544                                    get_object_type_name(type));
00545                 }
00546                 return 0;
00547         }
00548         return emdata;
00549 }

EMObject::operator float (  )  const

Definition at line 404 of file emobject.cpp.

References b, BOOL, d, DOUBLE, f, FLOAT, get_object_type_name(), INT, n, type, TypeException, ui, UNKNOWN, and UNSIGNEDINT.

00405 {
00406         if (type == BOOL) {
00407                 return b?1.0f:0.0f;
00408         }
00409         else if (type == FLOAT) {
00410                 return f;
00411         }
00412         else if (type == INT) {
00413                 return (float) n;
00414         }
00415         else if (type == UNSIGNEDINT) {
00416                 return (float) ui;
00417         }
00418         else if (type == DOUBLE) {
00419                 return (float) d;
00420         }
00421         else {
00422                 if (type != UNKNOWN) {
00423                         throw TypeException("Cannot convert to float from this data type",
00424                                                                 get_object_type_name(type));
00425                 }
00426         }
00427 
00428         return 0;
00429 }

EMObject::operator float * (  )  const

Definition at line 472 of file emobject.cpp.

References FLOAT_POINTER, fp, get_object_type_name(), type, TypeException, and UNKNOWN.

00473 {
00474         if (type != FLOAT_POINTER)
00475         {
00476                 if (type != UNKNOWN)
00477                         throw TypeException("Cannot convert to float pointer from this data type",
00478                                                                 get_object_type_name(type));
00479 
00480                 return 0;
00481         }
00482 
00483         return fp;
00484 }

EMObject::operator int (  )  const

Definition at line 364 of file emobject.cpp.

References b, BOOL, d, DOUBLE, f, FLOAT, get_object_type_name(), INT, n, type, TypeException, ui, UNKNOWN, and UNSIGNEDINT.

00365 {
00366         if (type == INT) {
00367                 return n;
00368         }
00369         else if (type == UNSIGNEDINT) {
00370                 return (int) ui;
00371         }
00372         else if (type == FLOAT) {
00373                 return (int) f;
00374         }
00375         else if (type == DOUBLE) {
00376                 return (int) d;
00377         }
00378         else if (type == BOOL) {
00379                 return b?1:0;
00380         }
00381         else {
00382                 if (type != UNKNOWN) {
00383                         throw TypeException("Cannot convert to int this data type ",
00384                                                                 get_object_type_name(type));
00385                 }
00386         }
00387         return 0;
00388 }

EMObject::operator int * (  )  const

Definition at line 457 of file emobject.cpp.

References get_object_type_name(), INT_POINTER, ip, type, TypeException, and UNKNOWN.

00458 {
00459         if (type != INT_POINTER)
00460         {
00461                 if (type != UNKNOWN)
00462                         throw TypeException("Cannot convert to float pointer from this data type",
00463                                                                 get_object_type_name(type));
00464 
00465                 return 0;
00466         }
00467 
00468         return ip;
00469 }

EMObject::operator Transform * (  )  const

Definition at line 563 of file emobject.cpp.

References farray, get_object_type_name(), EMAN::Transform::set_matrix(), TRANSFORM, type, TypeException, and UNKNOWN.

00564 {
00565         if(type != TRANSFORM) {
00566                 if(type != UNKNOWN) {
00567                         throw TypeException("Cannot convert to TRANSFORM* from this data type",
00568                                                                 get_object_type_name(type));
00569                 }
00570         }
00571         Transform * transform = new Transform();
00572         transform->set_matrix(farray);
00573         return transform;
00574 }

EMObject::operator unsigned int (  )  const

Definition at line 390 of file emobject.cpp.

References get_object_type_name(), type, TypeException, ui, UNKNOWN, and UNSIGNEDINT.

00391 {
00392         if (type == UNSIGNEDINT) {
00393                 return (unsigned int) ui;
00394         }
00395         else {
00396                 if (type != UNKNOWN) {
00397                         throw TypeException("Cannot convert to int this data type ",
00398                                                                 get_object_type_name(type));
00399                 }
00400         }
00401         return 0;
00402 }

EMAN::EMObject::operator vector (  )  const

EMAN::EMObject::operator vector (  )  const

EMAN::EMObject::operator vector (  )  const

EMObject::operator vector< Transform > (  )  const

Definition at line 596 of file emobject.cpp.

References get_object_type_name(), iarray, INTARRAY, type, TypeException, and UNKNOWN.

00597 {
00598     if( type != INTARRAY )
00599     {
00600         if( type != UNKNOWN ) {
00601                 throw TypeException("Cannot convert to vector<int> from this data type", get_object_type_name(type) );
00602                 }
00603                 return vector<int>();
00604     }
00605     return iarray;
00606 }

EMObject::operator void * (  )  const

Definition at line 487 of file emobject.cpp.

References emdata, EMDATA, FLOAT_POINTER, fp, get_object_type_name(), INT_POINTER, ip, type, TypeException, VOID_POINTER, xydata, and XYDATA.

00488 {
00489         if (type == VOID_POINTER) return vp;
00490         else if (type == FLOAT_POINTER) return (void *)fp;
00491         else if (type == INT_POINTER) return (void *)ip;
00492         else if (type == EMDATA) return (void *) emdata;
00493         else if (type == XYDATA) return (void *) xydata;
00494 //      else if (type == TRANSFORM) return (void *) transform;
00495         else throw TypeException("Cannot convert to void pointer from this data type", get_object_type_name(type));
00496 }

EMObject::operator XYData * (  )  const

Definition at line 551 of file emobject.cpp.

References get_object_type_name(), type, TypeException, UNKNOWN, xydata, and XYDATA.

00552 {
00553         if (type != XYDATA) {
00554                 if (type != UNKNOWN) {
00555                         throw TypeException("Cannot convert to XYData* from this data type",
00556                                    get_object_type_name(type));
00557                 }
00558                 return 0;
00559         }
00560         return xydata;
00561 }

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 916 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, transformarray, TRANSFORMARRAY, type, ui, UNKNOWN, UNSIGNEDINT, VOID_POINTER, vp, xydata, and XYDATA.

00917 {
00918 
00919 // This test breaks assignment when either the current or assigned values are (float)nan
00920 // it's also somewhat inherently stupid, since testing for equivalence may cost as much
00921 // as assignment.
00922 //      if ( *this != that )
00923         {
00924                 // First store the type of the input, At first I forgot to do this and it was a very
00925                 // difficult bug to track down
00926                 type = that.type;
00927 
00928 //              if ( type != this_type ) throw
00929 
00930 
00931                 switch (type)
00932                 {
00933                 case BOOL:
00934                         b = that.b;
00935                 break;
00936                 case INT:
00937                         n = that.n;
00938                 break;
00939                 case UNSIGNEDINT:
00940                         ui = that.ui;
00941                 break;
00942                 case FLOAT:
00943                         f = that.f;
00944                 break;
00945                 case DOUBLE:
00946                         d = that.d;
00947                 break;
00948                 case CTF:
00949                 case STRING:
00950                         str = that.str;
00951                 break;
00952                 case FLOAT_POINTER:
00953                         // Warning - Pointer address copy.
00954                         fp = that.fp;
00955                 break;
00956                 case INT_POINTER:
00957                 // Warning - Pointer address copy.
00958                         ip = that.ip;
00959                 break;
00960                 case VOID_POINTER:
00961                         // Warning - Pointer address copy.
00962                         vp = that.vp;
00963                 break;
00964                 case EMDATA:
00965                         // Warning - Pointer address copy.
00966                         emdata = that.emdata;
00967                 break;
00968                 case XYDATA:
00969                         // Warning - Pointer address copy.
00970                         xydata = that.xydata;
00971                 break;
00972                 case TRANSFORM:
00973                 case FLOATARRAY:
00974                         farray = that.farray;
00975                 break;
00976                 case INTARRAY:
00977                         iarray = that.iarray;
00978                 break;
00979                 case STRINGARRAY:
00980                         strarray = that.strarray;
00981                 break;
00982                 case TRANSFORMARRAY:
00983                         transformarray = that.transformarray;
00984                 break;
00985                 case UNKNOWN:
00986                         // This is possible, nothing should happen
00987                         // The EMObject's default constructor has been called and
00988                         // as yet has no type - doing nothing is exactly as the
00989                         // the assignment operator should work.
00990                 break;
00991                 default:
00992                         LOGERR("No such EMObject defined");
00993                         throw NotExistingObjectException("EMObject", "unknown type");
00994                 break;
00995                 }
00996         }
00997 //      else
00998 //      {
00999 //              cerr << "Warning - attempt to assign EMObject onto itself. No action taken" << endl;
01000 //              cerr << "My type is " << get_object_type_name(type) << endl;
01001 //      }
01002 
01003         return *this;
01004 }

void EMObject::printInfo (  )  const [private]

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

Definition at line 115 of file emobject.cpp.

References to_str(), type, and type_registry.

00116 {
00117         cout << "The address of my type is " << &type << endl;
00118         cout << " Now printing the enumerated values in type_registry " << endl;
00119         for( map< ObjectType, string>::const_iterator it = type_registry.begin(); it != type_registry.end(); ++it )
00120         {
00121                 cout << it->first << " " << it->second << endl;
00122         }
00123         cout << "My type is " << to_str(type) << " and its enumerated value is " << type << endl;
00124         cout << "The address of the static type registry is " << &type_registry <<", it should be same for all EMObjects" << endl;
00125 }

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 654 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, TRANSFORMARRAY, ui, UNKNOWN, UNSIGNEDINT, VOID_POINTER, and XYDATA.

00655 {
00656         if (argtype == STRING) {
00657                 return str;
00658         }
00659         else {
00660                 char tmp_str[32];
00661                 if (argtype == BOOL) {
00662                         if (b)
00663                                 sprintf(tmp_str, "true");
00664                         else
00665                                 sprintf(tmp_str, "false");
00666                 }
00667                 else if (argtype == INT) {
00668                         sprintf(tmp_str, "%d", n);
00669                 }
00670                 else if (argtype == UNSIGNEDINT) {
00671                         sprintf(tmp_str, "%d", ui);
00672                 }
00673                 else if (argtype == FLOAT) {
00674                         sprintf(tmp_str, "%f", f);
00675                 }
00676                 else if (argtype == DOUBLE) {
00677                         sprintf(tmp_str, "%f", d);
00678                 }
00679                 else if (argtype == EMDATA) {
00680                         sprintf(tmp_str, "EMDATA");
00681                 }
00682                 else if (argtype == FLOAT_POINTER) {
00683                         sprintf(tmp_str, "FLOAT_POINTER");
00684                 }
00685                 else if (argtype == INT) {
00686                         sprintf(tmp_str, "INT_POINTER");
00687                 }
00688                 else if (argtype == VOID_POINTER) {
00689                         sprintf(tmp_str, "VOID_POINTER");
00690                 }
00691                 else if (argtype == XYDATA) {
00692                         sprintf(tmp_str, "XYDATA");
00693                 }
00694                 else if (argtype == INTARRAY) {
00695                         sprintf(tmp_str, "INTARRAY");
00696                 }
00697                 else if (argtype == FLOATARRAY) {
00698                         sprintf(tmp_str, "FLOATARRAY");
00699                 }
00700                 else if (argtype == STRINGARRAY) {
00701                         sprintf(tmp_str, "STRINGARRAY");
00702                 }
00703                 else if (argtype == TRANSFORM) {
00704                         sprintf(tmp_str, "TRANSFORM");
00705                 }
00706                 else if (argtype == TRANSFORMARRAY) {
00707                         sprintf(tmp_str, "TRANSFORMARRAY");
00708                 }
00709                 else if (argtype == CTF) {
00710                         sprintf(tmp_str, "CTF");
00711                 }
00712                 else if (argtype == UNKNOWN) {
00713                         sprintf(tmp_str, "UNKNOWN");
00714                 }
00715                 else {
00716                         LOGERR("No such EMObject defined");
00717                         throw NotExistingObjectException("EMObject", "unknown type");
00718                 }
00719                 return string(tmp_str);
00720         }
00721 }

string EMObject::to_str (  )  const

Calls to_str( this->type).

Definition at line 649 of file emobject.cpp.

References type.

Referenced by printInfo().

00650 {
00651         return to_str(type);
00652 }


Friends And Related Function Documentation

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

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

Definition at line 896 of file emobject.cpp.

00897 {
00898         return !(e1 == e2);
00899 }

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

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

Definition at line 796 of file emobject.cpp.

00797 {
00798 
00799         if (e1.type != e2.type) {
00800                 return false;
00801         }
00802 
00803         switch (e1.type) {
00804         case  EMObject::BOOL:
00805                 return (e1.b == e2.b);
00806         break;
00807         case  EMObject::INT:
00808                 return (e1.n == e2.n);
00809         break;
00810         case  EMObject::UNSIGNEDINT:
00811                 return (e1.ui == e2.ui);
00812         break;
00813         case  EMObject::FLOAT:
00814                 return (e1.f == e2.f);
00815         break;
00816         case  EMObject::DOUBLE:
00817                 return (e1.d == e2.d);
00818         break;
00819         case EMObject::CTF:
00820         case  EMObject::STRING:
00821                 return (e1.str == e2.str);
00822         break;
00823         case  EMObject::FLOAT_POINTER:
00824                 return (e1.fp == e2.fp);
00825         break;
00826         case  EMObject::INT_POINTER:
00827                 return (e1.ip == e2.ip);
00828         break;
00829         case  EMObject::VOID_POINTER:
00830                 return (e1.vp == e2.vp);
00831         break;
00832         case  EMObject::EMDATA:
00833                 return (e1.emdata == e2.emdata);
00834         break;
00835         case  EMObject::XYDATA:
00836                 return (e1.xydata == e2.xydata);
00837         break;
00838         case  EMObject::TRANSFORM:
00839         case  EMObject::FLOATARRAY:
00840                 if (e1.farray.size() == e2.farray.size()) {
00841                         for (size_t i = 0; i < e1.farray.size(); i++) {
00842                                 if (e1.farray[i] != e2.farray[i]) {
00843                                         return false;
00844                                 }
00845                         }
00846                         return true;
00847                 }
00848                 else {
00849                         return false;
00850                 }
00851         break;
00852         case  EMObject::INTARRAY:
00853                 if (e1.iarray.size() == e2.iarray.size()) {
00854                         for (size_t i = 0; i < e1.iarray.size(); i++) {
00855                                 if (e1.iarray[i] != e2.iarray[i]) {
00856                                         return false;
00857                                 }
00858                         }
00859                         return true;
00860                 }
00861         break;
00862         case  EMObject::STRINGARRAY:
00863                 if (e1.strarray.size() == e2.strarray.size()) {
00864                         for (size_t i = 0; i < e1.strarray.size(); i++) {
00865                                 if (e1.strarray[i] != e2.strarray[i]) {
00866                                         return false;
00867                                 }
00868                         }
00869                         return true;
00870                 }
00871                 else {
00872                         return false;
00873                 }
00874         break;
00875         case EMObject::TRANSFORMARRAY:
00876                 if (e1.transformarray.size() == e2.transformarray.size()) {
00877                         for (size_t i = 0; i < e1.transformarray.size(); i++) {
00878                                 if (e1.transformarray[i] != e2.transformarray[i]) {
00879                                         return false;
00880                                 }
00881                         }
00882                 }
00883         break;
00884         case  EMObject::UNKNOWN:
00885                 // UNKNOWN really means "no type" and if two objects both have
00886                 // type UNKNOWN they really are the same
00887                 return (e1.type == e2.type);
00888         break;
00889         default:
00890                 return false;
00891         break;
00892         }
00893         return false;
00894 }


Member Data Documentation

union { ... } [private]

bool EMAN::EMObject::b [private]

Definition at line 258 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 262 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 266 of file emobject.h.

Referenced by operator bool(), operator EMData *(), operator void *(), operator=(), and EMAN::operator==().

float EMAN::EMObject::f [private]

Definition at line 261 of file emobject.h.

Referenced by EMAN::FRCCmp::cmp(), EMAN::PhaseCmp::cmp(), EMObject(), EMAN::EMData::insert_rect_slice_ctf(), EMAN::EMData::insert_rect_slice_ctf_applied(), EMAN::nn4_rectReconstructor::insert_slice(), 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(), and to_str().

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

Definition at line 272 of file emobject.h.

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

float* EMAN::EMObject::fp [private]

Definition at line 263 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 271 of file emobject.h.

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

int* EMAN::EMObject::ip [private]

Definition at line 264 of file emobject.h.

Referenced by operator bool(), operator int *(), operator void *(), operator=(), and EMAN::operator==().

int EMAN::EMObject::n [private]

Definition at line 259 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 270 of file emobject.h.

Referenced by operator const char *(), operator Ctf *(), operator=(), EMAN::operator==(), and to_str().

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

Definition at line 273 of file emobject.h.

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

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

Definition at line 274 of file emobject.h.

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

ObjectType EMAN::EMObject::type [private]

Definition at line 275 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]

Definition at line 284 of file emobject.h.

Referenced by get_object_type_name(), and printInfo().

unsigned int EMAN::EMObject::ui [private]

Definition at line 260 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]

Definition at line 265 of file emobject.h.

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

XYData* EMAN::EMObject::xydata [private]

Definition at line 267 of file emobject.h.

Referenced by operator bool(), operator void *(), operator XYData *(), operator=(), and EMAN::operator==().


The documentation for this class was generated from the following files:
Generated on Thu Nov 17 12:45:29 2011 for EMAN2 by  doxygen 1.4.7