00001 // -*- C++ -*- 00002 /*************************************************************************** 00003 * 00004 * The IPPL Framework 00005 * 00006 * 00007 * Visit http://people.web.psi.ch/adelmann/ for more details 00008 * 00009 ***************************************************************************/ 00010 00011 #ifndef ACLVIS_INTERP_NAMED_OBJ_H 00012 #define ACLVIS_INTERP_NAMED_OBJ_H 00013 00014 /*************************************************************************** 00015 * 00016 * NamedObj is a simple base class for objects which desire to have a name; 00017 * it provides one method 'name()' which returns the name of the object. 00018 * 00019 ***************************************************************************/ 00020 00021 // include files 00022 #include <string.h> 00023 00024 00025 class InterpNamedObj { 00026 00027 public: 00028 InterpNamedObj(const char *nm = 0) { 00029 MyName = 0; 00030 setName(nm); 00031 } 00032 00033 ~InterpNamedObj() { 00034 delete [] MyName; 00035 } 00036 00037 // return the current name 00038 char *name() const { return MyName; } 00039 00040 // change the name 00041 char *setName(const char *nm = 0) { 00042 // delete the old name if necessary 00043 if (MyName != 0) 00044 delete [] MyName; 00045 00046 // make a copy of the given name 00047 if (nm != 0) { 00048 MyName = new char[strlen(nm) + 1]; 00049 strcpy(MyName, nm); 00050 } else { 00051 MyName = new char[1]; 00052 *MyName = '\0'; 00053 } 00054 00055 return MyName; 00056 } 00057 00058 private: 00059 char *MyName; 00060 }; 00061 00062 #endif // ACLVIS_INTERP_NAMED_OBJ_H 00063 00064 /*************************************************************************** 00065 * $RCSfile: InterpNamedObj.h,v $ $Author: adelmann $ 00066 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:34 $ 00067 * IPPL_VERSION_ID: $Id: InterpNamedObj.h,v 1.1.1.1 2003/01/23 07:40:34 adelmann Exp $ 00068 ***************************************************************************/