00001 // Filename: namable.I 00002 // Created by: drose (16Feb00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function: Namable::Constructor 00021 // Access: Public 00022 // Description: 00023 //////////////////////////////////////////////////////////////////// 00024 INLINE Namable:: 00025 Namable(const string &initial_name) : 00026 _name(initial_name) 00027 { 00028 } 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Function: Namable::Copy Constructor 00032 // Access: Public 00033 // Description: 00034 //////////////////////////////////////////////////////////////////// 00035 INLINE Namable:: 00036 Namable(const Namable ©) : 00037 _name(copy._name) 00038 { 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function: Namable::Copy Assignment Operator 00043 // Access: Public 00044 // Description: 00045 //////////////////////////////////////////////////////////////////// 00046 INLINE Namable &Namable:: 00047 operator = (const Namable &other) { 00048 _name = other._name; 00049 return *this; 00050 } 00051 00052 //////////////////////////////////////////////////////////////////// 00053 // Function: Namable::set_name 00054 // Access: Public 00055 // Description: 00056 //////////////////////////////////////////////////////////////////// 00057 INLINE void Namable:: 00058 set_name(const string &name) { 00059 _name = name; 00060 } 00061 00062 //////////////////////////////////////////////////////////////////// 00063 // Function: Namable::clear_name 00064 // Access: Public 00065 // Description: Resets the Namable's name to empty. 00066 //////////////////////////////////////////////////////////////////// 00067 INLINE void Namable:: 00068 clear_name() { 00069 _name = ""; 00070 } 00071 00072 //////////////////////////////////////////////////////////////////// 00073 // Function: Namable::has_name 00074 // Access: Public 00075 // Description: Returns true if the Namable has a nonempty name set, 00076 // false if the name is empty. 00077 //////////////////////////////////////////////////////////////////// 00078 INLINE bool Namable:: 00079 has_name() const { 00080 return !_name.empty(); 00081 } 00082 00083 //////////////////////////////////////////////////////////////////// 00084 // Function: Namable::get_name 00085 // Access: Public 00086 // Description: 00087 //////////////////////////////////////////////////////////////////// 00088 INLINE const string &Namable:: 00089 get_name() const { 00090 return _name; 00091 } 00092 00093 //////////////////////////////////////////////////////////////////// 00094 // Function: Namable::output 00095 // Access: Public 00096 // Description: Outputs the Namable. This function simply writes the 00097 // name to the output stream; most Namable derivatives 00098 // will probably redefine this. 00099 //////////////////////////////////////////////////////////////////// 00100 INLINE void Namable:: 00101 output(ostream &out) const { 00102 out << get_name(); 00103 } 00104 00105 00106 INLINE ostream &operator << (ostream &out, const Namable &n) { 00107 n.output(out); 00108 return out; 00109 } 00110 00111 //////////////////////////////////////////////////////////////////// 00112 // Function: NamableOrderByName::Function operator 00113 // Access: Public 00114 // Description: 00115 //////////////////////////////////////////////////////////////////// 00116 INLINE bool NamableOrderByName:: 00117 operator ()(const Namable *n1, const Namable *n2) const { 00118 return (n1->get_name() < n2->get_name()); 00119 }