/* * Copyright (c) 2007 INRIA, Mathieu Lacage * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation; * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Authors: Mathieu Lacage */ #ifndef OBJECT_MAP_H #define OBJECT_MAP_H #include "attribute.h" #include "object-ptr-container.h" #include "object.h" #include "ptr.h" /** * \file * \ingroup attribute_ObjectMap * ns3::ObjectMap attribute value declarations and template implementations. */ namespace ns3 { /** * \ingroup attribute_ObjectMap * ObjectMapValue is an alias for ObjectPtrContainerValue */ typedef ObjectPtrContainerValue ObjectMapValue; /** * \ingroup attribute_ObjectMap * MakeAccessorHelper implementation for ObjectVector. * \copydetails ns3::DoMakeAccessorHelperOne(U T::*) */ template Ptr MakeObjectMapAccessor(U T::*memberVariable); // Documentation generated by print-introspected-doxygen.cc template Ptr MakeObjectMapChecker(); /** * \ingroup attribute_ObjectMap * \copydoc ns3::MakeObjectPtrContainerAccessor() */ template Ptr MakeObjectMapAccessor(Ptr (T::*get)(INDEX) const, INDEX (T::*getN)() const); /** * \ingroup attribute_ObjectMap * \copydoc ns3::MakeObjectPtrContainerAccessor() */ template Ptr MakeObjectMapAccessor(INDEX (T::*getN)() const, Ptr (T::*get)(INDEX) const); /*************************************************************** * Implementation of the templates declared above. ***************************************************************/ template Ptr MakeObjectMapAccessor(U T::*memberVector) { struct MemberStdContainer : public ObjectPtrContainerAccessor { bool DoGetN(const ObjectBase* object, std::size_t* n) const override { const T* obj = dynamic_cast(object); if (obj == nullptr) { return false; } *n = (obj->*m_memberVector).size(); return true; } Ptr DoGet(const ObjectBase* object, std::size_t i, std::size_t* index) const override { const T* obj = static_cast(object); typename U::const_iterator begin = (obj->*m_memberVector).begin(); typename U::const_iterator end = (obj->*m_memberVector).end(); uint32_t k = 0; for (typename U::const_iterator j = begin; j != end; j++, k++) { if (k == i) { *index = (*j).first; return (*j).second; break; } } NS_ASSERT(false); // quiet compiler. return nullptr; } U T::*m_memberVector; }* spec = new MemberStdContainer(); spec->m_memberVector = memberVector; return Ptr(spec, false); } template Ptr MakeObjectMapChecker() { return MakeObjectPtrContainerChecker(); } template Ptr MakeObjectMapAccessor(Ptr (T::*get)(INDEX) const, INDEX (T::*getN)() const) { return MakeObjectPtrContainerAccessor(get, getN); } template Ptr MakeObjectMapAccessor(INDEX (T::*getN)() const, Ptr (T::*get)(INDEX) const) { return MakeObjectPtrContainerAccessor(get, getN); } } // namespace ns3 #endif /* OBJECT_MAP_H */