Panda3D
|
00001 // Filename: namable.h 00002 // Created by: drose (15Jan99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef NAMABLE_H 00016 #define NAMABLE_H 00017 00018 #include "pandabase.h" 00019 00020 #include "typedObject.h" 00021 #include <string> 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Class : Namable 00025 // Description : A base class for all things which can have a name. 00026 // The name is either empty or nonempty, but it is never 00027 // NULL. 00028 //////////////////////////////////////////////////////////////////// 00029 class EXPCL_PANDAEXPRESS Namable : public MemoryBase { 00030 PUBLISHED: 00031 INLINE Namable(const string &initial_name = ""); 00032 INLINE Namable(const Namable ©); 00033 INLINE Namable &operator = (const Namable &other); 00034 00035 INLINE void set_name(const string &name); 00036 INLINE void clear_name(); 00037 INLINE bool has_name() const; 00038 INLINE const string &get_name() const; 00039 00040 // In the absence of any definition to the contrary, outputting a 00041 // Namable will write out its name. 00042 INLINE void output(ostream &out) const; 00043 00044 private: 00045 string _name; 00046 00047 public: 00048 static TypeHandle get_class_type() { 00049 return _type_handle; 00050 } 00051 static void init_type() { 00052 register_type(_type_handle, "Namable"); 00053 } 00054 00055 private: 00056 static TypeHandle _type_handle; 00057 }; 00058 00059 INLINE ostream &operator << (ostream &out, const Namable &n); 00060 00061 //////////////////////////////////////////////////////////////////// 00062 // Class : NamableOrderByName 00063 // Description : An STL function object for sorting an array of 00064 // pointers to Namables into order by name. Returns 00065 // true if the objects are in sorted order, false 00066 // otherwise. 00067 //////////////////////////////////////////////////////////////////// 00068 class NamableOrderByName { 00069 public: 00070 INLINE bool operator ()(const Namable *n1, const Namable *n2) const; 00071 }; 00072 00073 #include "namable.I" 00074 00075 #endif 00076 00077