|
22 |
|
22 |
|
23 |
#include "attribute.h" |
23 |
#include "attribute.h" |
24 |
#include "attribute-accessor-helper.h" |
24 |
#include "attribute-accessor-helper.h" |
|
|
25 |
#include "config.h" |
25 |
#include <sstream> |
26 |
#include <sstream> |
26 |
#include "fatal-error.h" |
27 |
#include "fatal-error.h" |
27 |
|
28 |
|
|
29 |
|
30 |
|
30 |
/** |
31 |
/** |
31 |
* \ingroup attribute |
32 |
* \ingroup attribute |
32 |
* \defgroup attributehelper Attribute Helper |
33 |
* \defgroup attributehelper Attribute Helpers |
33 |
* |
34 |
* |
34 |
* All these macros can be used to generate automatically the code |
35 |
* All these macros can be used to generate automatically the code |
35 |
* for subclasses of AttributeValue, AttributeAccessor, and, AttributeChecker, |
36 |
* for subclasses of AttributeValue, AttributeAccessor, and, AttributeChecker, |
|
127 |
return Ptr<AttributeChecker> (checker, false); |
128 |
return Ptr<AttributeChecker> (checker, false); |
128 |
} |
129 |
} |
129 |
|
130 |
|
130 |
} |
131 |
|
131 |
|
|
|
132 |
/** |
132 |
/** |
133 |
* \ingroup attributehelper |
133 |
* \ingroup attributehelper |
134 |
* |
134 |
* |
|
192 |
Ptr<const AttributeChecker> checker); \ |
192 |
Ptr<const AttributeChecker> checker); \ |
193 |
private: \ |
193 |
private: \ |
194 |
type m_value; \ |
194 |
type m_value; \ |
195 |
}; |
195 |
} |
196 |
|
|
|
197 |
|
196 |
|
198 |
/** |
197 |
/** |
199 |
* \ingroup attributehelper |
198 |
* \ingroup attributehelper |
|
247 |
class type ## Checker : public AttributeChecker {}; \ |
246 |
class type ## Checker : public AttributeChecker {}; \ |
248 |
Ptr<const AttributeChecker> Make ## type ## Checker (void) |
247 |
Ptr<const AttributeChecker> Make ## type ## Checker (void) |
249 |
|
248 |
|
|
|
249 |
/** |
250 |
* \ingroup attributehelper |
251 |
* |
252 |
* Declare the Config::GetDefaultValue<>() specializations for \p type. |
253 |
* |
254 |
* \param type The return type. |
255 |
* |
256 |
* This macro declares the Config::GetDefaultValue<>() specialization |
257 |
* returning the current default configuration value of an attribute, |
258 |
* as a \c type. If the attribute at the configuration path is not |
259 |
* compatible with the requested type, the function will raise a |
260 |
* fatal error. |
261 |
* |
262 |
* This macro is typically invoked in the class header file. |
263 |
* |
264 |
* \note This macro must be invoked from <tt>namespace ns3</tt>. |
265 |
* |
266 |
* \see |
267 |
* GetDefaultValue<>() |
268 |
*/ |
269 |
#define ATTRIBUTE_GETDEFAULT_DEFINE(type) \ |
270 |
namespace Config { \ |
271 |
template<> type \ |
272 |
GetDefaultValue<type> (const std::string attributePath); \ |
273 |
} /* namespace Config */ |
274 |
|
250 |
|
275 |
|
251 |
/** |
276 |
/** |
252 |
* \ingroup attributehelper |
277 |
* \ingroup attributehelper |
|
345 |
Ptr<const AttributeChecker> Make ## type ## Checker (void) { \ |
370 |
Ptr<const AttributeChecker> Make ## type ## Checker (void) { \ |
346 |
return MakeSimpleAttributeChecker<type ## Value,type ## Checker> \ |
371 |
return MakeSimpleAttributeChecker<type ## Value,type ## Checker> \ |
347 |
(# type "Value", name); \ |
372 |
(# type "Value", name); \ |
348 |
} \ |
373 |
} |
|
|
374 |
|
375 |
|
376 |
namespace Config { |
377 |
|
378 |
/** |
379 |
* \ingroup config |
380 |
* Config::GetDefaultValue<>() helper to fetch an attribute path as |
381 |
* the base AttributeValue. |
382 |
* |
383 |
* \param attributePath The configuration path for the attribute. |
384 |
* \returns The AttributeValue. |
385 |
* |
386 |
* \internal |
387 |
* This is declared in attribute-helper.h to break an include cycle. |
388 |
* The implementation is in config.cc. |
389 |
*/ |
390 |
Ptr<const AttributeValue> |
391 |
GetDefaultAttributeValue (const std::string attributePath); |
392 |
|
393 |
} // namespace Config |
394 |
|
349 |
|
395 |
|
350 |
/** |
396 |
/** |
351 |
* \ingroup attributehelper |
397 |
* \ingroup attributehelper |
352 |
* |
398 |
* |
353 |
* Declare the attribute value, accessor and checkers for class \p type |
399 |
* Define the Config::GetDefaultValue<>() specialization for the attribute |
|
|
400 |
* value class \c \typeValue, for underlying class \p type. |
401 |
* |
402 |
* \param type The underlying type name. |
403 |
* \param typeValue The derived AttributeValue class corresponding to |
404 |
* \c type. |
405 |
* |
406 |
* This macro implements the Config::GetDefaultValue<>() specialization |
407 |
* returning the current default configuration value of an attribute |
408 |
* as a \c type. If the attribute at the configuration path is not |
409 |
* compatible with the requested type, the function will raise a |
410 |
* fatal error. |
411 |
* |
412 |
* This macro is typically invoked in the source file. |
413 |
* |
414 |
* \note This macro must be invoked from <tt>namespace ns3</tt>. |
415 |
* |
416 |
* \see Config::GetDefaultValue<>() |
417 |
*/ |
418 |
#define ATTRIBUTE_GETDEFAULT_IMPLEMENT_WITH_NAME(type,typeValue) \ |
419 |
namespace Config { \ |
420 |
template<> type \ |
421 |
GetDefaultValue<type> (const std::string attributePath) \ |
422 |
{ \ |
423 |
Ptr<const AttributeValue> attrValue = \ |
424 |
GetDefaultAttributeValue (attributePath); \ |
425 |
Ptr<const typeValue> attr = \ |
426 |
DynamicCast<const typeValue> (attrValue); \ |
427 |
if (!attr) { \ |
428 |
NS_FATAL_ERROR ("Unable to convert attribute \"" \ |
429 |
<< attributePath << "\" to type " \ |
430 |
<< #typeValue ); \ |
431 |
} \ |
432 |
return attr->Get (); \ |
433 |
} \ |
434 |
} /* namespace Config */ |
435 |
|
436 |
|
437 |
/** |
438 |
* \ingroup attributehelper |
439 |
* |
440 |
* Define the Config::GetDefaultValue<>() specialization for the attribute |
441 |
* value class \p \<Name>Value, for underlying class \p Name. |
442 |
* |
443 |
* \param Name The underlying type name. |
444 |
* |
445 |
* This macro implements the Config::GetDefaultValue<>() specialization |
446 |
* returning the current default configuration value of an attribute, |
447 |
* as a \c Name. If the attribute at the configuration path is not |
448 |
* compatible with the requested type, the function will raise a |
449 |
* fatal error. |
450 |
* |
451 |
* This macro is typically invoked in the source file. |
452 |
* |
453 |
* \note This macro must be invoked from <tt>namespace ns3</tt>. |
454 |
* |
455 |
* \see Config::GetDefaultValue<>() |
456 |
*/ |
457 |
#define ATTRIBUTE_GETDEFAULT_IMPLEMENT(Name) \ |
458 |
ATTRIBUTE_GETDEFAULT_IMPLEMENT_WITH_NAME(Name, Name ## Value) |
459 |
|
460 |
/** |
461 |
* \ingroup attributehelper |
462 |
* |
463 |
* Declare the attribute value, accessor, checkers and |
464 |
* Config::GetDefaultValue<>() specialization for class \p type |
354 |
* |
465 |
* |
355 |
* \param type the name of the class |
466 |
* \param type the name of the class |
356 |
* |
467 |
* |
|
363 |
* - The AttributeChecker class \p \<type>Checker |
474 |
* - The AttributeChecker class \p \<type>Checker |
364 |
* and the \c MakeTypeChecker function, |
475 |
* and the \c MakeTypeChecker function, |
365 |
* |
476 |
* |
|
|
477 |
* - The Config::GetDefaultValue<>() specialization for getting the default |
478 |
* configuration value of an attribute as a \p type, |
479 |
* |
366 |
* for class \p type. |
480 |
* for class \p type. |
367 |
* |
481 |
* |
368 |
* This macro should be invoked outside of the class |
482 |
* This macro should be invoked outside of the class |
369 |
* declaration in its public header. |
483 |
* declaration in its public header, normally in <tt>namespace ns3<tt>. |
370 |
*/ |
484 |
*/ |
371 |
#define ATTRIBUTE_HELPER_HEADER(type) \ |
485 |
#define ATTRIBUTE_HELPER_HEADER(type) \ |
372 |
ATTRIBUTE_VALUE_DEFINE (type); \ |
486 |
ATTRIBUTE_VALUE_DEFINE (type); \ |
373 |
ATTRIBUTE_ACCESSOR_DEFINE (type); \ |
487 |
ATTRIBUTE_ACCESSOR_DEFINE (type); \ |
374 |
ATTRIBUTE_CHECKER_DEFINE (type); |
488 |
ATTRIBUTE_CHECKER_DEFINE (type); \ |
|
|
489 |
ATTRIBUTE_GETDEFAULT_DEFINE (type) |
375 |
|
490 |
|
376 |
/** |
491 |
/** |
377 |
* \ingroup attributehelper |
492 |
* \ingroup attributehelper |
378 |
* |
493 |
* |
379 |
* Define the attribute value, accessor and checkers for class \p type |
494 |
* Define the attribute value, accessor, checkers and |
|
|
495 |
* Config::GetDefaultValue<>() specialization for class \p type |
380 |
* |
496 |
* |
381 |
* \param type the name of the class |
497 |
* \param type the name of the class |
382 |
* |
498 |
* |
|
386 |
* |
502 |
* |
387 |
* - The \c MakeTypeChecker function, |
503 |
* - The \c MakeTypeChecker function, |
388 |
* |
504 |
* |
|
|
505 |
* - The Config::GetDefaultValue<>() specialization, |
506 |
* |
389 |
* for class \p type. |
507 |
* for class \p type. |
390 |
* |
508 |
* |
391 |
* This macro should be invoked from the class implementation file. |
509 |
* This macro should be invoked from the class implementation file, |
|
|
510 |
* normally in <tt>namespace ns3</tt>. |
392 |
*/ |
511 |
*/ |
393 |
#define ATTRIBUTE_HELPER_CPP(type) \ |
512 |
#define ATTRIBUTE_HELPER_CPP(type) \ |
394 |
ATTRIBUTE_CHECKER_IMPLEMENT (type); \ |
513 |
ATTRIBUTE_CHECKER_IMPLEMENT (type); \ |
395 |
ATTRIBUTE_VALUE_IMPLEMENT (type); |
514 |
ATTRIBUTE_VALUE_IMPLEMENT (type); \ |
|
|
515 |
ATTRIBUTE_GETDEFAULT_IMPLEMENT (type) |
396 |
|
516 |
|
|
|
517 |
|
518 |
} // namespace ns3 |
397 |
|
519 |
|
398 |
#endif /* ATTRIBUTE_HELPER_H */ |
520 |
#endif /* ATTRIBUTE_HELPER_H */ |