Panda3D
namable.I
1 // Filename: namable.I
2 // Created by: drose (16Feb00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 ////////////////////////////////////////////////////////////////////
16 // Function: Namable::Constructor
17 // Access: Public
18 // Description:
19 ////////////////////////////////////////////////////////////////////
20 INLINE Namable::
21 Namable(const string &initial_name) :
22  _name(initial_name)
23 {
24 }
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: Namable::Copy Constructor
28 // Access: Public
29 // Description:
30 ////////////////////////////////////////////////////////////////////
31 INLINE Namable::
32 Namable(const Namable &copy) :
33  _name(copy._name)
34 {
35 }
36 
37 ////////////////////////////////////////////////////////////////////
38 // Function: Namable::Copy Assignment Operator
39 // Access: Public
40 // Description:
41 ////////////////////////////////////////////////////////////////////
42 INLINE Namable &Namable::
43 operator = (const Namable &other) {
44  _name = other._name;
45  return *this;
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: Namable::set_name
50 // Access: Public
51 // Description:
52 ////////////////////////////////////////////////////////////////////
53 INLINE void Namable::
54 set_name(const string &name) {
55  _name = name;
56 }
57 
58 ////////////////////////////////////////////////////////////////////
59 // Function: Namable::clear_name
60 // Access: Public
61 // Description: Resets the Namable's name to empty.
62 ////////////////////////////////////////////////////////////////////
63 INLINE void Namable::
65  _name = "";
66 }
67 
68 ////////////////////////////////////////////////////////////////////
69 // Function: Namable::has_name
70 // Access: Public
71 // Description: Returns true if the Namable has a nonempty name set,
72 // false if the name is empty.
73 ////////////////////////////////////////////////////////////////////
74 INLINE bool Namable::
75 has_name() const {
76  return !_name.empty();
77 }
78 
79 ////////////////////////////////////////////////////////////////////
80 // Function: Namable::get_name
81 // Access: Public
82 // Description:
83 ////////////////////////////////////////////////////////////////////
84 INLINE const string &Namable::
85 get_name() const {
86  return _name;
87 }
88 
89 ////////////////////////////////////////////////////////////////////
90 // Function: Namable::output
91 // Access: Public
92 // Description: Outputs the Namable. This function simply writes the
93 // name to the output stream; most Namable derivatives
94 // will probably redefine this.
95 ////////////////////////////////////////////////////////////////////
96 INLINE void Namable::
97 output(ostream &out) const {
98  out << get_name();
99 }
100 
101 
102 INLINE ostream &operator << (ostream &out, const Namable &n) {
103  n.output(out);
104  return out;
105 }
106 
107 ////////////////////////////////////////////////////////////////////
108 // Function: NamableOrderByName::Function operator
109 // Access: Public
110 // Description:
111 ////////////////////////////////////////////////////////////////////
112 INLINE bool NamableOrderByName::
113 operator ()(const Namable *n1, const Namable *n2) const {
114  return (n1->get_name() < n2->get_name());
115 }
void output(ostream &out) const
Outputs the Namable.
Definition: namable.I:97
void clear_name()
Resets the Namable&#39;s name to empty.
Definition: namable.I:64
A base class for all things which can have a name.
Definition: namable.h:29
bool has_name() const
Returns true if the Namable has a nonempty name set, false if the name is empty.
Definition: namable.I:75