OLD | NEW |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2008 INRIA | 3 * Copyright (c) 2008 INRIA |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "attribute.h" | 23 #include "attribute.h" |
24 #include "attribute-accessor-helper.h" | 24 #include "attribute-accessor-helper.h" |
25 #include "trace-source-accessor.h" | 25 #include "trace-source-accessor.h" |
26 #include "attribute-helper.h" | 26 #include "attribute-helper.h" |
27 #include "callback.h" | 27 #include "callback.h" |
28 #include "deprecated.h" | 28 #include "deprecated.h" |
29 #include "hash.h" | 29 #include "hash.h" |
30 #include <string> | 30 #include <string> |
31 #include <stdint.h> | 31 #include <stdint.h> |
32 | 32 |
| 33 #include "ns3/ns3-module.h" |
| 34 #define NS3_MODULE NS3_CORE_MODULE |
| 35 #include "ns3/ns3-export.h" |
| 36 |
33 /** | 37 /** |
34 * \file | 38 * \file |
35 * \ingroup object | 39 * \ingroup object |
36 * ns3::TypeId declaration; inline and template implementations. | 40 * ns3::TypeId declaration; inline and template implementations. |
37 */ | 41 */ |
38 | 42 |
39 namespace ns3 { | 43 namespace ns3 { |
40 | 44 |
41 class ObjectBase; | 45 class ObjectBase; |
42 | 46 |
43 /** | 47 /** |
44 * \ingroup object | 48 * \ingroup object |
45 * \brief a unique identifier for an interface. | 49 * \brief a unique identifier for an interface. |
46 * | 50 * |
47 * This class records a lot of meta-information about a· | 51 * This class records a lot of meta-information about a· |
48 * subclass of the Object base class: | 52 * subclass of the Object base class: |
49 * - the base class of the subclass | 53 * - the base class of the subclass |
50 * - the set of accessible constructors in the subclass | 54 * - the set of accessible constructors in the subclass |
51 * - the set of 'attributes' accessible in the subclass | 55 * - the set of 'attributes' accessible in the subclass |
52 * | 56 * |
53 * \see attribute_TypeId | 57 * \see attribute_TypeId |
54 * | 58 * |
55 * \internal | 59 * \internal |
56 * See the discussion in IidManager about hash chaining of TypeId's. | 60 * See the discussion in IidManager about hash chaining of TypeId's. |
57 */ | 61 */ |
58 class TypeId | 62 class NS3_EXPORT TypeId |
59 { | 63 { |
60 public: | 64 public: |
61 /** Flags describing when a given attribute can be read or written. */ | 65 /** Flags describing when a given attribute can be read or written. */ |
62 enum AttributeFlag { | 66 enum AttributeFlag { |
63 ATTR_GET = 1<<0, /**< The attribute can be read */ | 67 ATTR_GET = 1<<0, /**< The attribute can be read */ |
64 ATTR_SET = 1<<1, /**< The attribute can be written */ | 68 ATTR_SET = 1<<1, /**< The attribute can be written */ |
65 ATTR_CONSTRUCT = 1<<2, /**< The attribute can be written at construction-tim
e */ | 69 ATTR_CONSTRUCT = 1<<2, /**< The attribute can be written at construction-tim
e */ |
66 ATTR_SGC = ATTR_GET | ATTR_SET | ATTR_CONSTRUCT, /**< The attribute can be r
ead, and written at any time */ | 70 ATTR_SGC = ATTR_GET | ATTR_SET | ATTR_CONSTRUCT, /**< The attribute can be r
ead, and written at any time */ |
67 }; | 71 }; |
68 /** The level of support or deprecation for attributes or trace sources. */ | 72 /** The level of support or deprecation for attributes or trace sources. */ |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 * | 166 * |
163 * \param [in] i Index of the TypeId. | 167 * \param [in] i Index of the TypeId. |
164 * \returns The TypeId instance whose index is \c i. | 168 * \returns The TypeId instance whose index is \c i. |
165 */ | 169 */ |
166 static TypeId GetRegistered (uint16_t i); | 170 static TypeId GetRegistered (uint16_t i); |
167 | 171 |
168 /** | 172 /** |
169 * Constructor. | 173 * Constructor. |
170 * | 174 * |
171 * \param [in] name The name of the interface to construct. | 175 * \param [in] name The name of the interface to construct. |
| 176 * \param [in] canBeDuplicate If true, this class can be registered more than
once |
172 * | 177 * |
173 * No two instances can share the same name. The name is expected to be | 178 * No two instances can share the same name. The name is expected to be |
174 * the full c++ typename of associated c++ object. | 179 * the full c++ typename of associated c++ object. |
175 */ | 180 */ |
176 explicit TypeId (const char * name); | 181 explicit TypeId (const char * name, bool canBeDuplicate = false); |
177 | 182 |
178 /** | 183 /** |
179 * Get the parent of this TypeId. | 184 * Get the parent of this TypeId. |
180 * | 185 * |
181 * \returns The parent of this TypeId | 186 * \returns The parent of this TypeId |
182 * | 187 * |
183 * This method cannot fail. It will return itself | 188 * This method cannot fail. It will return itself |
184 * if this TypeId has no parent. i.e., it is at the top | 189 * if this TypeId has no parent. i.e., it is at the top |
185 * of the TypeId hierarchy. Currently, this is the | 190 * of the TypeId hierarchy. Currently, this is the |
186 * case for the TypeId associated to the ns3::ObjectBase class· | 191 * case for the TypeId associated to the ns3::ObjectBase class· |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 * \param [in] size The size of the object, in bytes. | 346 * \param [in] size The size of the object, in bytes. |
342 * \returns This TypeId instance. | 347 * \returns This TypeId instance. |
343 */ | 348 */ |
344 TypeId SetSize (std::size_t size); | 349 TypeId SetSize (std::size_t size); |
345 ·· | 350 ·· |
346 /** | 351 /** |
347 * Record in this TypeId the fact that the default constructor | 352 * Record in this TypeId the fact that the default constructor |
348 * is accessible. | 353 * is accessible. |
349 * | 354 * |
350 * \tparam T \explicit The class name represented by this TypeId. | 355 * \tparam T \explicit The class name represented by this TypeId. |
| 356 * \param [in] canBeDuplicate If true, this class can be registered more than
once |
351 * \returns This TypeId instance | 357 * \returns This TypeId instance |
352 */ | 358 */ |
353 template <typename T> | 359 template <typename T> |
354 TypeId AddConstructor (void); | 360 TypeId AddConstructor (bool canBeDuplicate = false); |
355 | 361 |
356 /** | 362 /** |
357 * Record in this TypeId the fact that a new attribute exists. | 363 * Record in this TypeId the fact that a new attribute exists. |
358 * | 364 * |
359 * \param [in] name The name of the new attribute | 365 * \param [in] name The name of the new attribute |
360 * \param [in] help Some help text which describes the purpose of this | 366 * \param [in] help Some help text which describes the purpose of this |
361 * attribute. | 367 * attribute. |
362 * \param [in] initialValue The initial value for this attribute. | 368 * \param [in] initialValue The initial value for this attribute. |
363 * \param [in] accessor An instance of the associated AttributeAccessor | 369 * \param [in] accessor An instance of the associated AttributeAccessor |
364 * subclass. | 370 * subclass. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 * "ns3::" namespace qualifier. | 459 * "ns3::" namespace qualifier. |
454 * \param [in] supportLevel Support/deprecation status of the attribute. | 460 * \param [in] supportLevel Support/deprecation status of the attribute. |
455 * \param [in] supportMsg Upgrade hint if this attribute is no longer | 461 * \param [in] supportMsg Upgrade hint if this attribute is no longer |
456 * supported. If the attribute is \c DEPRECATED the attribute | 462 * supported. If the attribute is \c DEPRECATED the attribute |
457 * behavior still exists, but user code should be updated | 463 * behavior still exists, but user code should be updated |
458 * following guidance in the hint.. | 464 * following guidance in the hint.. |
459 * If the attribute is \c OBSOLETE, the hint should indicate | 465 * If the attribute is \c OBSOLETE, the hint should indicate |
460 * which class the attribute functional has been moved to, | 466 * which class the attribute functional has been moved to, |
461 * or that the functionality is no longer supported. | 467 * or that the functionality is no longer supported. |
462 * See test file type-id-test-suite.cc for examples. | 468 * See test file type-id-test-suite.cc for examples. |
| 469 * \param [in] canBeDuplicate If true, this class can be registered more than
once |
463 * \returns This TypeId instance. | 470 * \returns This TypeId instance. |
464 */ | 471 */ |
465 TypeId AddTraceSource (std::string name, | 472 TypeId AddTraceSource (std::string name, |
466 std::string help, | 473 std::string help, |
467 Ptr<const TraceSourceAccessor> accessor, | 474 Ptr<const TraceSourceAccessor> accessor, |
468 std::string callback, | 475 std::string callback, |
469 SupportLevel supportLevel = SUPPORTED, | 476 SupportLevel supportLevel = SUPPORTED, |
470 const std::string &supportMsg = ""); | 477 const std::string &supportMsg = "", |
| 478 bool canBeDuplicate = false); |
471 | 479 |
472 /** | 480 /** |
473 * Hide this TypeId from documentation. | 481 * Hide this TypeId from documentation. |
474 * \returns This TypeId instance. | 482 * \returns This TypeId instance. |
475 */ | 483 */ |
476 TypeId HideFromDocumentation (void); | 484 TypeId HideFromDocumentation (void); |
477 | 485 |
478 /** | 486 /** |
479 * Find an Attribute by name, retrieving the associated AttributeInformation. | 487 * Find an Attribute by name, retrieving the associated AttributeInformation. |
480 * | 488 * |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 | 569 |
562 /** | 570 /** |
563 * Construct from an integer value. | 571 * Construct from an integer value. |
564 * \param [in] tid The TypeId value as an integer. | 572 * \param [in] tid The TypeId value as an integer. |
565 */ | 573 */ |
566 explicit TypeId (uint16_t tid); | 574 explicit TypeId (uint16_t tid); |
567 /** | 575 /** |
568 * Implementation for AddConstructor(). | 576 * Implementation for AddConstructor(). |
569 * | 577 * |
570 * \param [in] callback Callback which constructs an instance of this TypeId. | 578 * \param [in] callback Callback which constructs an instance of this TypeId. |
| 579 * \param [in] canBeDuplicate True if this class can be registered more than o
nce |
571 */ | 580 */ |
572 void DoAddConstructor (Callback<ObjectBase *> callback); | 581 void DoAddConstructor (Callback<ObjectBase *> callback, bool canBeDuplicate =
false); |
573 ·· | 582 ·· |
574 /** The TypeId value. */· | 583 /** The TypeId value. */· |
575 uint16_t m_tid; | 584 uint16_t m_tid; |
576 }; | 585 }; |
577 | 586 |
578 /** | 587 /** |
579 * \relates TypeId | 588 * \relates TypeId |
580 * Output streamer. | 589 * Output streamer. |
581 * | 590 * |
582 * \param [in,out] os The output stream. | 591 * \param [in,out] os The output stream. |
583 * \param [in] tid The TypeId. | 592 * \param [in] tid The TypeId. |
584 * \returns The output stream. | 593 * \returns The output stream. |
585 */ | 594 */ |
586 std::ostream & operator << (std::ostream &os, TypeId tid); | 595 NS3_EXPORT std::ostream & operator << (std::ostream &os, TypeId tid); |
587 /** | 596 /** |
588 * \relates TypeId | 597 * \relates TypeId |
589 * Input Streamer. | 598 * Input Streamer. |
590 * \param [in,out] is The input stream. | 599 * \param [in,out] is The input stream. |
591 * \param [out] tid The TypeId to set from the stream. | 600 * \param [out] tid The TypeId to set from the stream. |
592 * \returns The input stream. | 601 * \returns The input stream. |
593 */ | 602 */ |
594 std::istream & operator >> (std::istream &is, TypeId &tid); | 603 NS3_EXPORT std::istream & operator >> (std::istream &is, TypeId &tid); |
595 ·· | 604 ·· |
596 /** | 605 /** |
597 * Comparison operator. | 606 * Comparison operator. |
598 * \param [in] a One value. | 607 * \param [in] a One value. |
599 * \param [in] b The other value. | 608 * \param [in] b The other value. |
600 * \returns The result of the comparison. | 609 * \returns The result of the comparison. |
601 * @{ | 610 * @{ |
602 */ | 611 */ |
603 inline bool operator == (TypeId a, TypeId b); | 612 inline bool operator == (TypeId a, TypeId b); |
604 inline bool operator != (TypeId a, TypeId b); | 613 inline bool operator != (TypeId a, TypeId b); |
605 bool operator < (TypeId a, TypeId b); | 614 bool operator < (TypeId a, TypeId b); |
606 /** @} */ | 615 /** @} */ |
607 | 616 |
608 ATTRIBUTE_HELPER_HEADER (TypeId); | 617 ATTRIBUTE_HELPER_HEADER_LIB (TypeId, NS3_EXPORT); |
609 | 618 |
610 } // namespace ns3· | 619 } // namespace ns3· |
611 | 620 |
612 namespace ns3 { | 621 namespace ns3 { |
613 | 622 |
614 TypeId::TypeId () | 623 TypeId::TypeId () |
615 : m_tid (0) { | 624 : m_tid (0) { |
616 } | 625 } |
617 TypeId::TypeId (const TypeId &o) | 626 TypeId::TypeId (const TypeId &o) |
618 : m_tid (o.m_tid) { | 627 : m_tid (o.m_tid) { |
(...skipping 23 matching lines...) Expand all Loading... |
642 | 651 |
643 template <typename T> | 652 template <typename T> |
644 TypeId· | 653 TypeId· |
645 TypeId::SetParent (void) | 654 TypeId::SetParent (void) |
646 { | 655 { |
647 return SetParent (T::GetTypeId ()); | 656 return SetParent (T::GetTypeId ()); |
648 } | 657 } |
649 | 658 |
650 template <typename T> | 659 template <typename T> |
651 TypeId· | 660 TypeId· |
652 TypeId::AddConstructor (void) | 661 TypeId::AddConstructor (bool canBeDuplicate) |
653 { | 662 { |
654 struct Maker { | 663 struct Maker { |
655 static ObjectBase * Create () { | 664 static ObjectBase * Create () { |
656 ObjectBase * base = new T (); | 665 ObjectBase * base = new T (); |
657 return base; | 666 return base; |
658 } | 667 } |
659 }; | 668 }; |
660 Callback<ObjectBase *> cb = MakeCallback (&Maker::Create); | 669 Callback<ObjectBase *> cb = MakeCallback (&Maker::Create); |
661 DoAddConstructor (cb); | 670 DoAddConstructor (cb, canBeDuplicate); |
662 return *this; | 671 return *this; |
663 } | 672 } |
664 | 673 |
665 } // namespace ns3 | 674 } // namespace ns3 |
666 | 675 |
667 #endif /* TYPE_ID_H */ | 676 #endif /* TYPE_ID_H */ |
OLD | NEW |