EMAN2
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends
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

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


Member Enumeration Documentation

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


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

                   :
        d(0), type(UNKNOWN)
{
#ifdef MEMDEBUG
        allemobjlist.insert(this);
        printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
#endif
}
EMObject::EMObject ( bool  boolean)

Definition at line 144 of file emobject.cpp.

                               :
        b(boolean), type(BOOL)
{
#ifdef MEMDEBUG
        allemobjlist.insert(this);
        printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
#endif
}
EMObject::EMObject ( short  sint)

Definition at line 153 of file emobject.cpp.

                             :
        si(sint), type(SHORT)
{
#ifdef MEMDEBUG
        allemobjlist.insert(this);
        printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
#endif
}
EMObject::EMObject ( int  num)

Definition at line 162 of file emobject.cpp.

                          :
        n(num), type(INT)
{
#ifdef MEMDEBUG
        allemobjlist.insert(this);
        printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
#endif
}
EMObject::EMObject ( unsigned int  num)

Definition at line 171 of file emobject.cpp.

                                   :
        ui(num), type(UNSIGNEDINT)
{
#ifdef MEMDEBUG
        allemobjlist.insert(this);
        printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
#endif
}
EMObject::EMObject ( float  ff)

Definition at line 180 of file emobject.cpp.

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

                           :
        type(FLOAT)
{

#ifdef MEMDEBUG
        allemobjlist.insert(this);
        printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
#endif
        if(Util::goodf(&ff)) {
                f = ff;
        }
        else{
                f = 0.0f;
        }
}
EMObject::EMObject ( double  dd)

Definition at line 196 of file emobject.cpp.

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

                            :
        type(DOUBLE)
{

#ifdef MEMDEBUG
        allemobjlist.insert(this);
        printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
#endif
        if(Util::goodf(&dd)) {
                d = dd;
        }
        else{
                d = 0.0;
        }
}
EMObject::EMObject ( const char *  s)

Definition at line 212 of file emobject.cpp.

                                :
        str(s), type(STRING)
{
#ifdef MEMDEBUG
        allemobjlist.insert(this);
        printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
#endif
}
EMObject::EMObject ( const string &  s)

Definition at line 221 of file emobject.cpp.

                                   :
        str(s), type(STRING)
{
#ifdef MEMDEBUG
        allemobjlist.insert(this);
        printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
#endif
}
EMObject::EMObject ( float *  fp)

Definition at line 230 of file emobject.cpp.

                           :
        fp(f), type(FLOAT_POINTER)
{
#ifdef MEMDEBUG
        allemobjlist.insert(this);
        printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
#endif
}
EMObject::EMObject ( int *  ip)

Definition at line 239 of file emobject.cpp.

                         :
        ip(i), type(INT_POINTER)
{
#ifdef MEMDEBUG
        allemobjlist.insert(this);
        printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
#endif
}
EMObject::EMObject ( void *  vp)

Definition at line 248 of file emobject.cpp.

                          :
        vp(v), type(VOID_POINTER)
{
#ifdef MEMDEBUG
        allemobjlist.insert(this);
        printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
#endif
}
EMObject::EMObject ( EMData em)

Definition at line 257 of file emobject.cpp.

                                :
        emdata(em), type(EMDATA)
{
#ifdef MEMDEBUG
        allemobjlist.insert(this);
        printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
#endif
}
EMObject::EMObject ( XYData xy)

Definition at line 266 of file emobject.cpp.

                              :
        xydata(xy), type(XYDATA)
{
#ifdef MEMDEBUG
        allemobjlist.insert(this);
        printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
#endif
}
EMObject::EMObject ( Transform t)

Definition at line 275 of file emobject.cpp.

                               :
        farray(t->get_matrix()), type(TRANSFORM)
{
#ifdef MEMDEBUG
        allemobjlist.insert(this);
        printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
#endif
}
EMObject::EMObject ( Ctf ctf)

Definition at line 284 of file emobject.cpp.

                            :
        str(ctf->to_string()), type(CTF)
{
#ifdef MEMDEBUG
        allemobjlist.insert(this);
        printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
#endif
}
EMObject::EMObject ( const vector< int > &  v)

Definition at line 293 of file emobject.cpp.

                                          :
        iarray(v), type(INTARRAY)
{
#ifdef MEMDEBUG
        allemobjlist.insert(this);
        printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
#endif
}
EMObject::EMObject ( const vector< float > &  v)

Definition at line 302 of file emobject.cpp.

                                           :
        farray(v), type(FLOATARRAY)
{
#ifdef MEMDEBUG
        allemobjlist.insert(this);
        printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
#endif
}
EMObject::EMObject ( const vector< string > &  sarray)

Definition at line 311 of file emobject.cpp.

                                                :
        strarray(sarray), type(STRINGARRAY)
{
#ifdef MEMDEBUG
        allemobjlist.insert(this);
        printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
#endif
}
EMObject::EMObject ( const vector< Transform > &  tarray)

Definition at line 320 of file emobject.cpp.

                                                   :
        transformarray(tarray), type(TRANSFORMARRAY)
{
#ifdef MEMDEBUG
        allemobjlist.insert(this);
        printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
#endif
}
EMObject::EMObject ( const EMObject that)

Copy constructor.

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

Definition at line 950 of file emobject.cpp.

{
        // init isn't necessary because that must have already called it!
        *this = that;
#ifdef MEMDEBUG
        allemobjlist.insert(this);
        printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
#endif
}
EMObject::~EMObject ( )

Desctructor Does not free pointers.

Definition at line 128 of file emobject.cpp.

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

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

References BOOL, CTF, DOUBLE, EMDATA, FLOAT, FLOAT_POINTER, FLOATARRAY, INT, INT_POINTER, INTARRAY, LOGERR, NotExistingObjectException, SHORT, 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 short(), operator Transform *(), operator unsigned int(), operator vector< float >(), operator vector< int >(), operator vector< string >(), operator vector< Transform >(), operator void *(), operator XYData *(), and EMAN::TypeDict::put().

{
#ifdef _WIN32
        if (t == BOOL) {
                return "BOOL";
        }else
        if ( t == SHORT) {
                return "SHORT";
        }else
        if ( t == INT){
                return "INT";
        }else
        if ( t == UNSIGNEDINT){
                return "UNSIGNEDINT";
        } else
        if ( t == FLOAT){
                return "FLOAT";
        } else
        if ( t == DOUBLE){
                return "DOUBLE";
        }else
        if ( t == STRING){
                return "STRING";
        }else
        if ( t == EMDATA){
                return "EMDATA";
        }
        else
        if ( t == XYDATA){
                return "XYDATA";
        }else
        if ( t == INTARRAY){
                return "INTARRAY";
        }else
        if ( t == FLOATARRAY){
                return "FLOATARRAY";
        } else
        if ( t == STRINGARRAY){
                return "STRINGARRAY";
        }else
        if ( t == TRANSFORM){
                return "TRANSFORM";
        }else
        if ( t == TRANSFORMARRAY){
                return "TRANSFORMARRAY";
        }
        if ( t == CTF){
                return "CTF";
        }else
        if ( t == FLOAT_POINTER){
                return "FLOAT_POINTER";
        }else
        if ( t == INT_POINTER){
                return "INT_POINTER";
        }else
        if ( t == UNKNOWN){
                return "UNKNOWN";
        } else
        if ( t == VOID_POINTER){
                return "VOID_POINTER";
        }
        else {
                LOGERR("No such EMObject defined");
                throw NotExistingObjectException("EMObject", "unknown type");
        }

#else

        if  ( type_registry.find(t) != type_registry.end() )
                return type_registry[t];
        else
                LOGERR("No such EMObject defined");
                throw NotExistingObjectException("EMObject", "unknown type");
#endif  //_WIN32
}
ObjectType EMAN::EMObject::get_type ( ) const [inline]

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

Definition at line 228 of file emobject.h.

References type.

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

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

References get_object_type_name(), and 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, SHORT, STRING, STRINGARRAY, TRANSFORM, TRANSFORMARRAY, UNKNOWN, UNSIGNEDINT, VOID_POINTER, and XYDATA.

{
        map< EMObject::ObjectType, string> mymap;
        static bool first_construction = true;
        if ( first_construction )
        {
                // Initialize the the type registry once and for all
                mymap[BOOL] = "BOOL";
                mymap[SHORT] = "SHORT";
                mymap[INT] = "INT";
                mymap[UNSIGNEDINT] = "UNSIGNEDINT";
                mymap[FLOAT] = "FLOAT";
                mymap[DOUBLE] = "DOUBLE";
                mymap[STRING] = "STRING";
                mymap[EMDATA] = "EMDATA";
                mymap[XYDATA] = "XYDATA";
                mymap[INTARRAY] = "INTARRAY";
                mymap[FLOATARRAY] = "FLOATARRAY";
                mymap[STRINGARRAY] = "STRINGARRAY";
                mymap[TRANSFORM] = "TRANFORM";
                mymap[CTF] = "CTF";
                mymap[FLOAT_POINTER] = "FLOAT_POINTER";
                mymap[INT_POINTER] = "INT_POINTER";
                mymap[UNKNOWN] = "UNKNOWN";
                mymap[VOID_POINTER] = "VOID_POINTER";
                mymap[TRANSFORMARRAY] = "TRANSFORMARRAY";
                first_construction = false;
        }

        return mymap;
}
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 683 of file emobject.cpp.

References type, and UNKNOWN.

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

{
        return (type == UNKNOWN);
}
EMObject::operator bool ( ) const

Conversion operators.

Definition at line 329 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, SHORT, si, type, TypeException, ui, UNKNOWN, UNSIGNEDINT, VOID_POINTER, xydata, and XYDATA.

{
        if (type == BOOL) {
                return b;
        }
        else if (type == SHORT) {
                return si != 0;
        }
        else if (type == INT) {
                return n != 0;
        }
        else if (type == UNSIGNEDINT) {
                return ui != 0;
        }
        else if (type == FLOAT) {
                return f != 0;
        }
        else if (type == DOUBLE) {
                return d != 0;
        }
        else if (type == EMDATA) {
                return emdata != 0;
        }
        else if (type == XYDATA) {
                return xydata != 0;
        }
        else if (type == FLOAT_POINTER) {
                return fp != 0;
        }
        else if (type == INT_POINTER) {
                return ip != 0;
        }
        else if (type == VOID_POINTER) {
                return vp != 0;
        }
//      else if (type == TRANSFORM) {
//              return transform != 0;
//      }
        // It seemed unconventional to return a boolean for the stl objects
        else {
                if (type != UNKNOWN) {
                        throw TypeException("Cannot convert to bool this data type ",
                                                                get_object_type_name(type));
                }
        }
        return 0;
}
EMObject::operator const char * ( ) const

Definition at line 537 of file emobject.cpp.

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

{
        if (type != STRING && type != CTF) {
                stringstream ss;
                string return_string;
                if ( type == INT )
                {
                        ss << n;
                        ss >> return_string;
                        return return_string.c_str();
                }
                if ( type == UNSIGNEDINT )
                {
                        ss << ui;
                        ss >> return_string;
                        return return_string.c_str();
                }
                else
                if ( type == FLOAT )
                {
                        ss << f;
                        ss >> return_string;
                        return return_string.c_str();
                }
                else
                if ( type == DOUBLE )
                {
                        ss << d;
                        ss >> return_string;
                        return return_string.c_str();
                }
                else if (type != UNKNOWN) {
                        throw TypeException("Cannot convert to string from this data type",
                                                                get_object_type_name(type));
                }

                return "";
        }
        return str.c_str();
}
EMObject::operator Ctf * ( ) const

Definition at line 615 of file emobject.cpp.

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

{
/*      if(type != CTF) {
                if(type != CTF) {
                        throw TypeException("Cannot convert to TRANSFORM* from this data type",
                                                                get_object_type_name(type));
                }
        }*/
        Ctf * ctf = 0;
        if(str[0] == 'O') {
                ctf = new EMAN1Ctf();
                ctf->from_string(str);
        }
        else if(str[0] == 'E') {
                ctf = new EMAN2Ctf();
                ctf->from_string(str);
        }
        return ctf;
}
EMObject::operator double ( ) const

Definition at line 467 of file emobject.cpp.

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

{
        if (type == BOOL) {
        return b?1.0:0.0;
        }
        else if (type == DOUBLE) {
                return d;
        }
        else if (type == SHORT) {
                return si;
        }
        else if (type == INT) {
                return (double) n;
        }
        else if (type == UNSIGNEDINT) {
                return (double) ui;
        }
        else if (type == FLOAT) {
                return (double) f;
        }
        else {
                if (type != UNKNOWN) {
                        throw TypeException("Cannot convert to double from this data type",
                                                                get_object_type_name(type));
                }
        }
        return 0;
}
EMObject::operator EMData * ( ) const

Definition at line 578 of file emobject.cpp.

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

{
        if (type != EMDATA) {
                if (type != UNKNOWN) {
                        throw TypeException("Cannot convert to EMData* from this data type",
                                   get_object_type_name(type));
                }
                return 0;
        }
        return emdata;
}
EMObject::operator float ( ) const

Definition at line 434 of file emobject.cpp.

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

{
        if (type == BOOL) {
                return b?1.0f:0.0f;
        }
        else if (type == FLOAT) {
                return f;
        }
        else if (type == SHORT) {
                return si;
        }
        else if (type == INT) {
                return (float) n;
        }
        else if (type == UNSIGNEDINT) {
                return (float) ui;
        }
        else if (type == DOUBLE) {
                return (float) d;
        }
        else if (type == STRING) {
                return (float)atof(str.c_str());
        }
        else {
                if (type != UNKNOWN) {
                        throw TypeException("Cannot convert to float from this data type",
                                                                get_object_type_name(type));
                }
        }

        return 0;
}
EMObject::operator float * ( ) const

Definition at line 511 of file emobject.cpp.

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

{
        if (type != FLOAT_POINTER)
        {
                if (type != UNKNOWN)
                        throw TypeException("Cannot convert to float pointer from this data type",
                                                                get_object_type_name(type));

                return 0;
        }

        return fp;
}
EMObject::operator int ( ) const

Definition at line 391 of file emobject.cpp.

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

{
        if (type == INT) {
                return n;
        }
        else if (type == SHORT) {
                return si;
        }
        else if (type == UNSIGNEDINT) {
                return (int) ui;
        }
        else if (type == FLOAT) {
                return (int) f;
        }
        else if (type == DOUBLE) {
                return (int) d;
        }
        else if (type == BOOL) {
                return b?1:0;
        }
        else {
                if (type != UNKNOWN) {
                        throw TypeException("Cannot convert to int this data type ",
                                                                get_object_type_name(type));
                }
        }
        return 0;
}
EMObject::operator int * ( ) const

Definition at line 496 of file emobject.cpp.

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

{
        if (type != INT_POINTER)
        {
                if (type != UNKNOWN)
                        throw TypeException("Cannot convert to float pointer from this data type",
                                                                get_object_type_name(type));

                return 0;
        }

        return ip;
}
EMObject::operator short ( ) const

Definition at line 377 of file emobject.cpp.

References get_object_type_name(), SHORT, si, type, TypeException, and UNKNOWN.

{
        if (type == SHORT) {
                return si;
        }
        else {
        if (type != UNKNOWN) {
                                throw TypeException("Cannot convert to int this data type ",
                                                                        get_object_type_name(type));
                        }
        }
        return 0;
}
EMObject::operator Transform * ( ) const

Definition at line 602 of file emobject.cpp.

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

{
        if(type != TRANSFORM) {
                if(type != UNKNOWN) {
                        throw TypeException("Cannot convert to TRANSFORM* from this data type",
                                                                get_object_type_name(type));
                }
        }
        Transform * transform = new Transform();
        transform->set_matrix(farray);
        return transform;
}
EMObject::operator unsigned int ( ) const

Definition at line 420 of file emobject.cpp.

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

{
        if (type == UNSIGNEDINT) {
                return (unsigned int) ui;
        }
        else {
                if (type != UNKNOWN) {
                        throw TypeException("Cannot convert to int this data type ",
                                                                get_object_type_name(type));
                }
        }
        return 0;
}
EMObject::operator vector< float > ( ) const

Definition at line 647 of file emobject.cpp.

References farray, FLOATARRAY, get_object_type_name(), type, TypeException, and UNKNOWN.

{
        if (type != FLOATARRAY) {
                if (type != UNKNOWN) {
                        throw TypeException("Cannot convert to vector<float> from this data type",
                                                                get_object_type_name(type));
                }
                return vector < float >();
        }
        return farray;
}
EMObject::operator vector< int > ( ) const

Definition at line 635 of file emobject.cpp.

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

{
    if( type != INTARRAY )
    {
        if( type != UNKNOWN ) {
                throw TypeException("Cannot convert to vector<int> from this data type", get_object_type_name(type) );
                }
                return vector<int>();
    }
    return iarray;
}
EMObject::operator vector< string > ( ) const

Definition at line 659 of file emobject.cpp.

References get_object_type_name(), strarray, STRINGARRAY, type, TypeException, and UNKNOWN.

{
        if (type != STRINGARRAY) {
                if (type != UNKNOWN) {
                        throw TypeException("Cannot convert to vector<string> from this data type",
                                                                get_object_type_name(type));
                }
                return vector<string>();
        }
        return strarray;
}
EMObject::operator vector< Transform > ( ) const

Definition at line 671 of file emobject.cpp.

References get_object_type_name(), transformarray, TRANSFORMARRAY, type, TypeException, and UNKNOWN.

{
        if(type != TRANSFORMARRAY) {
                if (type != UNKNOWN) {
                        throw TypeException("Cannot convert to vector<string> from this data type",
                                                                get_object_type_name(type));
                }
                return vector<Transform>();
        }
        return transformarray;
}
EMObject::operator void * ( ) const

Definition at line 526 of file emobject.cpp.

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

{
        if (type == VOID_POINTER) return vp;
        else if (type == FLOAT_POINTER) return (void *)fp;
        else if (type == INT_POINTER) return (void *)ip;
        else if (type == EMDATA) return (void *) emdata;
        else if (type == XYDATA) return (void *) xydata;
//      else if (type == TRANSFORM) return (void *) transform;
        else throw TypeException("Cannot convert to void pointer from this data type", get_object_type_name(type));
}
EMObject::operator XYData * ( ) const

Definition at line 590 of file emobject.cpp.

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

{
        if (type != XYDATA) {
                if (type != UNKNOWN) {
                        throw TypeException("Cannot convert to XYData* from this data type",
                                   get_object_type_name(type));
                }
                return 0;
        }
        return xydata;
}
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 964 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, SHORT, si, str, strarray, STRING, STRINGARRAY, TRANSFORM, transformarray, TRANSFORMARRAY, type, ui, UNKNOWN, UNSIGNEDINT, VOID_POINTER, vp, xydata, and XYDATA.

{

// This test breaks assignment when either the current or assigned values are (float)nan
// it's also somewhat inherently stupid, since testing for equivalence may cost as much
// as assignment.
//      if ( *this != that )
        {
                // First store the type of the input, At first I forgot to do this and it was a very
                // difficult bug to track down
                type = that.type;

//              if ( type != this_type ) throw


                switch (type)
                {
                case BOOL:
                        b = that.b;
                break;
                case SHORT:
                        si = that.si;
                break;
                case INT:
                        n = that.n;
                break;
                case UNSIGNEDINT:
                        ui = that.ui;
                break;
                case FLOAT:
                        f = that.f;
                break;
                case DOUBLE:
                        d = that.d;
                break;
                case CTF:
                case STRING:
                        str = that.str;
                break;
                case FLOAT_POINTER:
                        // Warning - Pointer address copy.
                        fp = that.fp;
                break;
                case INT_POINTER:
                // Warning - Pointer address copy.
                        ip = that.ip;
                break;
                case VOID_POINTER:
                        // Warning - Pointer address copy.
                        vp = that.vp;
                break;
                case EMDATA:
                        // Warning - Pointer address copy.
                        emdata = that.emdata;
                break;
                case XYDATA:
                        // Warning - Pointer address copy.
                        xydata = that.xydata;
                break;
                case TRANSFORM:
                case FLOATARRAY:
                        farray = that.farray;
                break;
                case INTARRAY:
                        iarray = that.iarray;
                break;
                case STRINGARRAY:
                        strarray = that.strarray;
                break;
                case TRANSFORMARRAY:
                        transformarray = that.transformarray;
                break;
                case UNKNOWN:
                        // This is possible, nothing should happen
                        // The EMObject's default constructor has been called and
                        // as yet has no type - doing nothing is exactly as the
                        // the assignment operator should work.
                break;
                default:
                        LOGERR("No such EMObject defined");
                        throw NotExistingObjectException("EMObject", "unknown type");
                break;
                }
        }
//      else
//      {
//              cerr << "Warning - attempt to assign EMObject onto itself. No action taken" << endl;
//              cerr << "My type is " << get_object_type_name(type) << endl;
//      }

        return *this;
}
void EMObject::printInfo ( ) const [private]

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

Definition at line 116 of file emobject.cpp.

References to_str(), type, and type_registry.

{
        cout << "The address of my type is " << &type << endl;
        cout << " Now printing the enumerated values in type_registry " << endl;
        for( map< ObjectType, string>::const_iterator it = type_registry.begin(); it != type_registry.end(); ++it )
        {
                cout << it->first << " " << it->second << endl;
        }
        cout << "My type is " << to_str(type) << " and its enumerated value is " << type << endl;
        cout << "The address of the static type registry is " << &type_registry <<", it should be same for all EMObjects" << endl;
}
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 693 of file emobject.cpp.

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

{
        if (argtype == STRING) {
                return str;
        }
        else {
                char tmp_str[32];
                if (argtype == BOOL) {
                        if (b)
                                sprintf(tmp_str, "true");
                        else
                                sprintf(tmp_str, "false");
                }
                else if (argtype == SHORT) {
                        sprintf(tmp_str, "%hd", si);
                }
                else if (argtype == INT) {
                        sprintf(tmp_str, "%d", n);
                }
                else if (argtype == UNSIGNEDINT) {
                        sprintf(tmp_str, "%d", ui);
                }
                else if (argtype == FLOAT) {
                        sprintf(tmp_str, "%f", f);
                }
                else if (argtype == DOUBLE) {
                        sprintf(tmp_str, "%f", d);
                }
                else if (argtype == EMDATA) {
                        sprintf(tmp_str, "EMDATA");
                }
                else if (argtype == FLOAT_POINTER) {
                        sprintf(tmp_str, "FLOAT_POINTER");
                }
                else if (argtype == INT) {
                        sprintf(tmp_str, "INT_POINTER");
                }
                else if (argtype == VOID_POINTER) {
                        sprintf(tmp_str, "VOID_POINTER");
                }
                else if (argtype == XYDATA) {
                        sprintf(tmp_str, "XYDATA");
                }
                else if (argtype == INTARRAY) {
                        sprintf(tmp_str, "INTARRAY");
                }
                else if (argtype == FLOATARRAY) {
                        sprintf(tmp_str, "FLOATARRAY");
                }
                else if (argtype == STRINGARRAY) {
                        sprintf(tmp_str, "STRINGARRAY");
                }
                else if (argtype == TRANSFORM) {
                        sprintf(tmp_str, "TRANSFORM");
                }
                else if (argtype == TRANSFORMARRAY) {
                        sprintf(tmp_str, "TRANSFORMARRAY");
                }
                else if (argtype == CTF) {
                        sprintf(tmp_str, "CTF");
                }
                else if (argtype == UNKNOWN) {
                        sprintf(tmp_str, "UNKNOWN");
                }
                else {
                        LOGERR("No such EMObject defined");
                        throw NotExistingObjectException("EMObject", "unknown type");
                }
                return string(tmp_str);
        }
}
string EMObject::to_str ( ) const

Calls to_str( this->type)

Definition at line 688 of file emobject.cpp.

References type.

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

{
        return to_str(type);
}

Friends And Related Function Documentation

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

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

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

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


Member Data Documentation

union { ... } [private]
vector<float> EMAN::EMObject::farray [private]
vector<int> EMAN::EMObject::iarray [private]

Definition at line 276 of file emobject.h.

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

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

Definition at line 278 of file emobject.h.

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

Definition at line 279 of file emobject.h.

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

map< EMObject::ObjectType, string > EMObject::type_registry = init() [static, private]

Definition at line 289 of file emobject.h.

Referenced by get_object_type_name(), and printInfo().

unsigned int EMAN::EMObject::ui

Definition at line 270 of file emobject.h.

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


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