torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PrimitiveSet.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 PrimitiveSet class.
18 
19 #ifndef TORC_PACKER_PRIMITIVESET_HPP
20 #define TORC_PACKER_PRIMITIVESET_HPP
21 
23 #include <string>
24 
25 namespace torc {
26 namespace physical {
27 
28 /// \brief PrimitiveSet.
29 
30 class PrimitiveSet : public Named, public Progeny<class PrimitiveSet>,
31  protected Progenitor<class PrimitiveSet> {
32  // friends
33 /// \brief The Factory class has direct access to our internals.
34 friend class RcFactory;
35 
36 
37 protected:
38 // types
39 /// \brief Imported type name.
41 // members
42 /// \brief Vector of primitive shared pointers.
44 
45  // constructors
46 PrimitiveSet(const string& inName) : Named(inName), Progenitor<class PrimitiveSet>(){}
47 public:
48 
49 // types
50 /// \brief Constant iterator for Primitive shared pointers.
51 typedef PrimitiveSharedPtrVector::const_iterator PrimitiveSharedPtrConstIterator;
52 /// \brief Non-constant iterator for Primitive shared pointers.
53 typedef PrimitiveSharedPtrVector::iterator PrimitiveSharedPtrIterator;
54 // functions
55 /// \brief Find a PrimitiveSet primitive by name.
56 /// \param inName The primitive name to look for.
57 /// \returns an iterator for the specified primitive, or primitivesEnd() if the name was not
58 /// found.
60 NameComparator predicate(inName);
61 return std::find_if(primitivesBegin(), primitivesEnd(), predicate);
62 }
63 /// \brief Add a primitive to the PrimitiveSet.
64 /// \param inPrimitivePtr The primitive to add.
65 /// \returns true if the primitive was added, or false if a primitive with the same name already
66 /// exists in the PrimitiveSet.
67 bool addPrimitive(PrimitiveSharedPtr& inPrimitivePtr) {
68 /// \todo Acquire mutex.
69 PrimitiveSharedPtrVector::iterator e = mPrimitives.end();
70 PrimitiveSharedPtrVector::iterator result = findPrimitive(inPrimitivePtr->getName());
71 if(result == e) mPrimitives.push_back(inPrimitivePtr);
72 return result == e; // return true if we added the primitive
73 /// \todo Release mutex.
74 }
75 /// \brief Remove a primitive from the PrimitiveSet.
76 /// \param inPrimitivePtr The primitive to remove.
77 /// \returns true if the primitive was removed, or false if the primitive did not exist.
78 bool removePrimitive(PrimitiveSharedPtr& inPrimitivePtr) {
79 /// \todo Acquire mutex.
80 PrimitiveSharedPtrVector::iterator e = mPrimitives.end();
81 PrimitiveSharedPtrVector::iterator result = std::find(mPrimitives.begin(), e, inPrimitivePtr);
82 if(result == e) return false;
83 mPrimitives.erase(result);
84 /// \todo Release mutex.
85 return true;
86 }
87 
88 
89 // accessors
90 
91 size_t getPrimitiveCount(void) const { return mPrimitives.size(); }
92 // iterators
93 /// \brief Returns the begin constant iterator for primitives.
95 /// \brief Returns the end constant iterator for primitives.
97 /// \brief Returns the begin non-constant iterator for primitives.
99 /// \brief Returns the end non-constant iterator for primitives.
101 
102 };
103 
104 /// \brief Shared pointer encapsulation of a PrimitiveSet.
105 typedef boost::shared_ptr<PrimitiveSet> PrimitiveSetSharedPtr;
106 
107  /// \brief Shared pointer encapsulation of a PrimitiveSet.
108 typedef boost::weak_ptr<PrimitiveSet> PrimitiveSetWeakPtr;
109 
110 /// \brief Vector of PrimitiveSet shared pointers.
111 typedef std::vector<PrimitiveSetSharedPtr> PrimitiveSetSharedPtrVector;
112 
113 } // namespace physical
114 } // namespace torc
115 
116 #endif // TORC_PACKER_PRIMITIVESET_HPP
PrimitiveSharedPtrIterator primitivesBegin(void)
Returns the begin non-constant iterator for primitives.
boost::shared_ptr< Primitive > PrimitiveSharedPtr
Shared pointer encapsulation of a Primitive.
Definition: Primitive.hpp:171
boost::weak_ptr< PrimitiveSet > PrimitiveSetWeakPtr
Shared pointer encapsulation of a PrimitiveSet.
std::string string
Imported type name.
RcFactory class for physical netlist elements.
Definition: RcFactory.hpp:34
PrimitiveSharedPtrConstIterator primitivesBegin(void) const
Returns the begin constant iterator for primitives.
Header for the Primitive class.
boost::shared_ptr< PrimitiveSet > PrimitiveSetSharedPtr
Shared pointer encapsulation of a PrimitiveSet.
Concept for any object that can be named.
Definition: Named.hpp:36
std::string string
PrimitiveSharedPtrIterator primitivesEnd(void)
Returns the end non-constant iterator for primitives.
size_t getPrimitiveCount(void) const
std::vector< PrimitiveSetSharedPtr > PrimitiveSetSharedPtrVector
Vector of PrimitiveSet shared pointers.
bool addPrimitive(PrimitiveSharedPtr &inPrimitivePtr)
Add a primitive to the PrimitiveSet.
Comparator class to serve as a predicate when searching for names.
Definition: Named.hpp:61
PrimitiveSharedPtrConstIterator primitivesEnd(void) const
Returns the end constant iterator for primitives.
bool removePrimitive(PrimitiveSharedPtr &inPrimitivePtr)
Remove a primitive from the PrimitiveSet.
PrimitiveSharedPtrIterator findPrimitive(const string &inName)
Find a PrimitiveSet primitive by name.
PrimitiveSharedPtrVector::const_iterator PrimitiveSharedPtrConstIterator
Constant iterator for Primitive shared pointers.
Concept for any object that may have children.
Definition: Progenitor.hpp:36
Concept for any object that may have a parent.
Definition: Progeny.hpp:29
PrimitiveSet(const string &inName)
PrimitiveSharedPtrVector::iterator PrimitiveSharedPtrIterator
Non-constant iterator for Primitive shared pointers.
std::vector< PrimitiveSharedPtr > PrimitiveSharedPtrVector
Vector of Primitive shared pointers.
Definition: Primitive.hpp:174
PrimitiveSharedPtrVector mPrimitives
Vector of primitive shared pointers.