A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
object-factory.h
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #ifndef OBJECT_FACTORY_H
21 #define OBJECT_FACTORY_H
22 
23 #include "attribute-construction-list.h"
24 #include "object.h"
25 #include "type-id.h"
26 
27 namespace ns3 {
28 
29 class AttributeValue;
30 
40 {
41 public:
42  ObjectFactory ();
43  ObjectFactory (std::string typeId);
44 
48  void SetTypeId (TypeId tid);
52  void SetTypeId (const char *tid);
56  void SetTypeId (std::string tid);
61  void Set (std::string name, const AttributeValue &value);
62 
67  TypeId GetTypeId (void) const;
68 
72  Ptr<Object> Create (void) const;
80  template <typename T>
81  Ptr<T> Create (void) const;
82 
83 private:
84  friend std::ostream & operator << (std::ostream &os, const ObjectFactory &factory);
85  friend std::istream & operator >> (std::istream &is, ObjectFactory &factory);
86 
87  TypeId m_tid;
88  AttributeConstructionList m_parameters;
89 };
90 
91 std::ostream & operator << (std::ostream &os, const ObjectFactory &factory);
92 std::istream & operator >> (std::istream &is, ObjectFactory &factory);
93 
94 
119 template <typename T>
120 Ptr<T>
121 CreateObjectWithAttributes (std::string n1 = "", const AttributeValue & v1 = EmptyAttributeValue (),
122  std::string n2 = "", const AttributeValue & v2 = EmptyAttributeValue (),
123  std::string n3 = "", const AttributeValue & v3 = EmptyAttributeValue (),
124  std::string n4 = "", const AttributeValue & v4 = EmptyAttributeValue (),
125  std::string n5 = "", const AttributeValue & v5 = EmptyAttributeValue (),
126  std::string n6 = "", const AttributeValue & v6 = EmptyAttributeValue (),
127  std::string n7 = "", const AttributeValue & v7 = EmptyAttributeValue (),
128  std::string n8 = "", const AttributeValue & v8 = EmptyAttributeValue (),
129  std::string n9 = "", const AttributeValue & v9 = EmptyAttributeValue ());
130 
131 
132 
133 
140 
141 } // namespace ns3
142 
143 namespace ns3 {
144 
145 template <typename T>
146 Ptr<T>
148 {
149  Ptr<Object> object = Create ();
150  return object->GetObject<T> ();
151 }
152 
153 template <typename T>
154 Ptr<T>
155 CreateObjectWithAttributes (std::string n1, const AttributeValue & v1,
156  std::string n2, const AttributeValue & v2,
157  std::string n3, const AttributeValue & v3,
158  std::string n4, const AttributeValue & v4,
159  std::string n5, const AttributeValue & v5,
160  std::string n6, const AttributeValue & v6,
161  std::string n7, const AttributeValue & v7,
162  std::string n8, const AttributeValue & v8,
163  std::string n9, const AttributeValue & v9)
164 {
165  ObjectFactory factory;
166  factory.SetTypeId (T::GetTypeId ());
167  factory.Set(n1, v1);
168  factory.Set(n2, v2);
169  factory.Set(n3, v3);
170  factory.Set(n4, v4);
171  factory.Set(n5, v5);
172  factory.Set(n6, v6);
173  factory.Set(n7, v7);
174  factory.Set(n8, v8);
175  factory.Set(n9, v9);
176  return factory.Create<T> ();
177 }
178 
179 
180 } // namespace ns3
181 
182 #endif /* OBJECT_FACTORY_H */
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:49
TypeId GetTypeId(void) const
Hold a value for an Attribute.
Definition: attribute.h:51
void SetTypeId(TypeId tid)
A class for an empty attribute value.
Definition: attribute.h:204
Ptr< Object > Create(void) const
Ptr< T > CreateObjectWithAttributes(std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
#define ATTRIBUTE_HELPER_HEADER(type)
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:43
void Set(std::string name, const AttributeValue &value)
instantiate subclasses of ns3::Object.
a unique identifier for an interface.
Definition: type-id.h:44