cgma
CastTo.hpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Copyright Notice
00003 //
00004 // Copyright (c) 1996 
00005 // by Malcolm J. Panthaki, DBA, and the University of New Mexico.
00006 //-------------------------------------------------------------------------
00007 
00008 //-------------------------------------------------------------------------
00009 // Filename      : CastTo.hpp
00010 //
00011 // Purpose       : Provides a macro to convert an object from one type to
00012 //                 any other type, provided the cast is deemed safe.
00013 //
00014 // Special Notes : Uses the get_address(NewType) function to determine whether
00015 //                 a cast is safe or not and then to return the appropriate
00016 //                 address. 
00017 //
00018 // Creator       : Raikanta Sahu
00019 //
00020 // Creation Date : 10/09/96
00021 //
00022 // Owner         : Malcolm J. Panthaki
00023 //-------------------------------------------------------------------------
00024 
00025 #ifndef CAST_TO_HPP
00026 #define CAST_TO_HPP
00027 
00028 // Macro to cast a pointer to one class to a pointer to another class.
00029 // Constraint: The first class must support a function get_address() and the
00030 // second class must have an enum entry corresponding to it who's syntax
00031 // is "classTwo"_TYPE.
00032 //
00033 // NOTE: Multiple inheritance and virtual inheritance are accounted for
00034 //       appropriately in the get_address functions.
00035 //
00036 // NOTE: If a NULL pointer is given to CAST_TO, it always returns NULL.
00037 //
00038 // NOTE: If the get_address function returns a NULL, then a NULL is returned.
00039 
00040 #define CAST_TO(classOnePtr, classTwo) \
00041    dynamic_cast<classTwo*>(classOnePtr)
00042 
00043 #define STATIC_CAST_TO(classOnePtr, classTwo) \
00044    static_cast<classTwo*>(classOnePtr)
00045 
00046 #define CAST_LIST_TO_PARENT(classOneList, classTwoList) \
00047    { \
00048       (classOneList).reset(); \
00049       (classTwoList).clean_out(); \
00050       (classTwoList).reserve((classOneList).size()); \
00051       for (int CAST_LIST_IT = (classOneList).size(); CAST_LIST_IT > 0; CAST_LIST_IT--) \
00052         (classTwoList).append((classOneList).get_and_step()); \
00053    }
00054  
00055 #define CAST_LIST(classOneList, classTwoList, classTwo) \
00056    { \
00057       classTwo *CAST_LIST_PTR_TWO; \
00058       (classTwoList).clean_out(); \
00059       int CAST_LIST_IT_END = (classOneList).size(); \
00060       for (int CAST_LIST_IT=0; CAST_LIST_IT<CAST_LIST_IT_END; CAST_LIST_IT++) { \
00061   CAST_LIST_PTR_TWO = dynamic_cast<classTwo*>( (classOneList)[CAST_LIST_IT] ); \
00062         if (CAST_LIST_PTR_TWO != NULL) (classTwoList).append(CAST_LIST_PTR_TWO); \
00063       } \
00064    }
00065 
00066 #define STATIC_CAST_LIST(classOneList, classTwoList, classTwo) \
00067    { \
00068       classTwo *CAST_LIST_PTR_TWO; \
00069       (classTwoList).clean_out(); \
00070       int CAST_LIST_IT_END = (classOneList).size(); \
00071       for (int CAST_LIST_IT=0; CAST_LIST_IT<CAST_LIST_IT_END; CAST_LIST_IT++) { \
00072   CAST_LIST_PTR_TWO = static_cast<classTwo*>( (classOneList)[CAST_LIST_IT] ); \
00073         if (CAST_LIST_PTR_TWO != NULL) (classTwoList).append(CAST_LIST_PTR_TWO); \
00074       } \
00075    }
00076 
00077 #define CAST_LIST_TO_IDS(classOneList, idList ) \
00078    { \
00079       (classOneList).reset(); \
00080       (idList).clean_out(); \
00081       for (int i = (classOneList).size(); i > 0; i--) { \
00082         (idList).append((classOneList).get_and_step()->id()); \
00083       } \
00084    }
00085 
00086 #define CONST_CAST_LIST(classOneList, classTwoList, classTwo) \
00087    { \
00088       classTwo *CAST_LIST_PTR_TWO; \
00089       (classTwoList).clean_out(); \
00090       for (int CAST_LIST_IT = 0; CAST_LIST_IT < (classOneList).size(); CAST_LIST_IT++) { \
00091         CAST_LIST_PTR_TWO = dynamic_cast<classTwo*>( (classOneList).next(CAST_LIST_IT) ); \
00092         if (CAST_LIST_PTR_TWO != NULL) (classTwoList).append(CAST_LIST_PTR_TWO); \
00093       } \
00094    }
00095 #endif
00096 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines