torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Named.hpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 /// \file
17 /// \brief Header for the Named class.
18 
19 #ifndef TORC_PHYSICAL_NAMED_HPP
20 #define TORC_PHYSICAL_NAMED_HPP
21 
22 #include <string>
23 #include <boost/smart_ptr.hpp>
24 
25 namespace torc {
26 namespace physical {
27 
28  /// \brief Concept for any object that can be named.
29  /// \details No support is provided at this level for renaming, because many subclasses may
30  /// may require oversight from their parent to avoid name collisions.
31  /// \todo Add a setName() accessor to support renaming. For many design elements, this may
32  /// require permission from the parent, to avoid name collisions. We could make the
33  /// function virtual, but that would come at the cost of a vtable, and that's very
34  /// expensive for things like Config objects. In general, the renaming should probably be
35  /// managed by the Progeny<T> template.
36  class Named {
37  protected:
38  // types
39  /// \brief Imported type name.
41  // members
42  /// \brief The name of the object.
43  string mName;
44  public:
45  // constructors
46  /// \brief Constructor which must specify the object name.
47  /// \param inName The object name.
48  Named(const string& inName) : mName(inName) {}
49  // accessors
50  /// \brief Returns the object name.
51  const string& getName(void) const { return mName; }
52  // operators
53  /// \brief Equality operator.
54  bool operator ==(const Named& rhs) const { return mName == rhs.mName; }
55  };
56 
57  /// \brief Shared pointer encapsulation of a Named object.
58  typedef boost::shared_ptr<Named> NamedSharedPtr;
59 
60  /// \brief Comparator class to serve as a predicate when searching for names.
62  protected:
63  // types
64  /// \brief Imported type name.
66  // members
67  /// \brief The name to compare against.
68  const string& mName;
69  public:
70  // constructors
71  /// \brief Constructor.
72  /// \param inName The name to compare against.
73  NameComparator(const string& inName) : mName(inName) {}
74  // operators
75  /// \brief Function operator taking a Named object.
76  /// \returns true if the given object's name matches the desired name, or false
77  /// otherwise.
78  bool operator() (const Named& inNamed) const { return inNamed.getName() == mName; }
79  /// \brief Function operator taking a Named shared pointer.
80  /// \returns true if the given object's name matches the desired name, or false
81  /// otherwise.
82  bool operator() (const NamedSharedPtr& inNamedPtr) const
83  { return inNamedPtr->getName() == mName; }
84  };
85 
86 } // namespace physical
87 } // namespace torc
88 
89 #endif // TORC_PHYSICAL_NAMED_HPP
NameComparator(const string &inName)
Constructor.
Definition: Named.hpp:73
bool operator==(const Named &rhs) const
Equality operator.
Definition: Named.hpp:54
std::string string
Imported type name.
Definition: Named.hpp:40
string mName
The name of the object.
Definition: Named.hpp:43
Named(const string &inName)
Constructor which must specify the object name.
Definition: Named.hpp:48
Concept for any object that can be named.
Definition: Named.hpp:36
std::string string
boost::shared_ptr< Named > NamedSharedPtr
Shared pointer encapsulation of a Named object.
Definition: Named.hpp:58
Comparator class to serve as a predicate when searching for names.
Definition: Named.hpp:61
std::string string
Imported type name.
Definition: Named.hpp:65
const string & getName(void) const
Returns the object name.
Definition: Named.hpp:51
const string & mName
The name to compare against.
Definition: Named.hpp:68
bool operator()(const Named &inNamed) const
Function operator taking a Named object.
Definition: Named.hpp:78