From 97f57a698bf3fee5dd8e0d7d0b04ae3fe1afbd53 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 3 May 2007 00:35:39 +0200 Subject: [PATCH] remove dead code --- SConstruct | 2 - src/core/object-container.cc | 201 ---------------------------------- src/core/object-container.h | 205 ----------------------------------- 3 files changed, 408 deletions(-) delete mode 100644 src/core/object-container.cc delete mode 100644 src/core/object-container.h diff --git a/SConstruct b/SConstruct index 28d1d08d4..7101946fd 100644 --- a/SConstruct +++ b/SConstruct @@ -25,7 +25,6 @@ core.add_sources([ 'test.cc', 'random-variable.cc', 'rng-stream.cc', - 'object-container.cc', ]) env = Environment() if env['PLATFORM'] == 'posix' or env['PLATFORM'] == 'darwin' or env['PLATFORM'] == 'cygwin': @@ -49,7 +48,6 @@ core.add_inst_headers([ 'test.h', 'random-variable.h', 'rng-stream.h', - 'object-container.h' ]) def config_core (env, config): diff --git a/src/core/object-container.cc b/src/core/object-container.cc deleted file mode 100644 index 0a767c8a2..000000000 --- a/src/core/object-container.cc +++ /dev/null @@ -1,201 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 INRIA - * All rights reserved. - * - * 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 - * - * Author: Mathieu Lacage - */ -#include "object-container.h" - -namespace ns3 { - -ObjectContainer::DeleterList ObjectContainer::m_deleterList; - -ObjectContainer::~ObjectContainer () -{ - Cleanup (); -} - -void -ObjectContainer::Cleanup (void) -{ - for (List::iterator i = m_list.begin (); i != m_list.end (); i++) - { - uint32_t uid = i->first; - std::vector *vec = i->second; - ObjectDeleter deleter = LookupObjectDeleter (uid); - for (std::vector::iterator j = vec->begin (); - j != vec->end (); j++) - { - (deleter) (*j); - } - delete vec; - } - m_list.erase (m_list.begin (), m_list.end ()); -} - -uint32_t -ObjectContainer::GetGlobalUid (void) const -{ - static uint32_t globalUid = 0; - globalUid ++; - return globalUid; -} - -uint32_t -ObjectContainer::RegisterUid (uint32_t uid, ObjectDeleter deleter) const -{ - for (DeleterList::iterator i = m_deleterList.begin (); - i != m_deleterList.end (); i++) - { - NS_ASSERT (i->first != uid); - } - m_deleterList.push_back (std::make_pair (uid, deleter)); - return uid; -} - -ObjectContainer::ObjectDeleter -ObjectContainer::LookupObjectDeleter (uint32_t uid) const -{ - for (DeleterList::iterator i = m_deleterList.begin (); - i != m_deleterList.end (); i++) - { - if (i->first == uid) - { - return i->second; - } - } - NS_FATAL_ERROR ("unknown deleter requested."); - return 0; -} - -}//namespace ns3 - - -#ifdef RUN_SELF_TESTS - -#include "test.h" -namespace ns3 { - -class A -{ -public: - A () {} - ~A () {} -}; - -class WithCopy -{ -public: - WithCopy () {} - ~WithCopy () {} - WithCopy *Copy (void) const {return new WithCopy ();} -}; - -class B -{ -public: - B () {} - ~B () {} -}; - -class Base -{ -public: - Base () {} - virtual ~Base () {} -}; - -class DerivedA -{ -public: - DerivedA () {} - virtual ~DerivedA () {} -}; - -class DerivedB -{ -public: - DerivedB () {} - virtual ~DerivedB () {} -}; - - -class ObjectContainerTest : public Test -{ -public: - ObjectContainerTest (); - virtual ~ObjectContainerTest (); - - virtual bool RunTests (void); -}; - -ObjectContainerTest::ObjectContainerTest () - : Test ("ObjectContainer") -{} - -ObjectContainerTest::~ObjectContainerTest () -{} - -bool -ObjectContainerTest::RunTests (void) -{ - bool ok = true; - - ObjectContainer container; - A *a = new A (); - A *firstA = a; - container.Acquire (a); - a = new A (); - container.Acquire (a); - a = new A (); - container.Acquire (a); - B *b = new B (); - container.Acquire (b); - a = new A (); - container.Acquire (a); - b = new B (); - container.Acquire (b); - - container.Remove (firstA); - delete firstA; - - Base *base = new Base (); - container.Acquire (base); - DerivedA *derivedA = new DerivedA (); - container.Acquire (derivedA); - DerivedB *derivedB = new DerivedB (); - container.Acquire (derivedB); - base = new Base (); - container.Acquire (base); - derivedB = new DerivedB (); - container.Acquire (derivedB); - - - // the following cannot work because no copy method defined. - //container.Add (A ()); - container.Add (WithCopy ()); - - container.Cleanup (); - - return ok; -} - -static ObjectContainerTest g_objectContainerTest; - -}//namespace ns3 - -#endif /* RUN_SELF_TESTS */ diff --git a/src/core/object-container.h b/src/core/object-container.h deleted file mode 100644 index a46e446e4..000000000 --- a/src/core/object-container.h +++ /dev/null @@ -1,205 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 INRIA - * All rights reserved. - * - * 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 - * - * Author: Mathieu Lacage - */ -#ifndef OBJECT_CONTAINER_H -#define OBJECT_CONTAINER_H - -#include -#include -#include -#include "fatal-error.h" - -namespace ns3 { - - -/** - * \brief Store objects for delayed deletion. - * - * This class can store any type of object provided it can be deleted. - * There is no requirement that the destructor of these objects be - * virtual. When the ObjectContainer::Cleanup method is invoked, - * all the objects still left in the container will be deleted. - * Alternatively, Cleanup is called automatically. when this object is - * destroyed. - */ -class ObjectContainer -{ -public: - /** - * Invoke ObjectContainer::Cleanup if the user has not invoked it - * himself. - */ - ~ObjectContainer (); - /** - * Delete all objects stored in this container. - */ - void Cleanup (void); - - /** - * \param object object to store in the container. - * - * Take ownership of the input pointer: the object - * will be deleted when ObjectContainer::Cleanup is invoked. - */ - template - void Acquire (T *object); - - /** - * \param object template of the object to store in the - * container. - * - * Invoke the Copy method of the input object. This method is - * expected to return a pointer of similar type and that - * pointer will be returned. Furthermore, the pointer will - * be stored internally to delete it when ObjectContainer::Cleanup - * is invoked. - */ - template - T *Add (T const &object); - - /** - * \param object object to remove from container. - * - * Remove the object from the container: it will not - * be deleted when the ObjectContainer::Cleanup method - * is invoked. - */ - template - void Remove (T *object); - -private: - typedef void (*ObjectDeleter) (void *); - typedef std::list *> > List; - typedef std::list > DeleterList; - template - static void DeleteObject (void *ptr); - template - uint32_t GetUid (void) const; - - template - std::vector *GetVector (void) const; - - uint32_t GetGlobalUid (void) const; - uint32_t RegisterUid (uint32_t uid, ObjectDeleter deleter) const; - ObjectContainer::ObjectDeleter LookupObjectDeleter (uint32_t uid) const; - List m_list; - static DeleterList m_deleterList; -}; - -}; // namespace ns3 - -namespace ns3 { - -template -void -ObjectContainer::Acquire (T *object) -{ - uint32_t uid = GetUid (); - for (List::iterator i = m_list.begin (); i != m_list.end (); i++) - { - if (i->first == uid) - { - i->second->push_back (object); - return; - } - } - std::vector * vec = new std::vector (); - vec->push_back (object); - m_list.push_back (std::make_pair (uid, vec)); -} - -template -T * -ObjectContainer::Add (T const &object) -{ - T *copy = object.Copy (); - Acquire (copy); - return copy; -} - - -template -void -ObjectContainer::Remove (T *object) -{ - uint32_t uid = GetUid (); - for (List::iterator i = m_list.begin (); i != m_list.end (); i++) - { - if (i->first == uid) - { - for (std::vector::iterator j = i->second->begin (); - j != i->second->end (); j++) - { - if ((*j) == object) - { - i->second->erase (j); - return; - } - } - goto error; - } - } - error: - NS_FATAL_ERROR ("tried to remove non-existant object from object container"); -} - -template -std::vector * -ObjectContainer::GetVector (void) const -{ - uint32_t uid = GetUid (); - for (List::const_iterator i = m_list.begin (); i != m_list.end (); i++) - { - if (i->first == uid) - { - std::vector *vec = i->second; - std::vector *retval = (std::vector *)vec; - return retval; - } - } - NS_FATAL_ERROR ("no object registered for requested type."); - // quiet compiler - return 0; -} - - - - -template -void -ObjectContainer::DeleteObject (void *ptr) -{ - T *object = (T*) ptr; - delete object; -} - -template -uint32_t -ObjectContainer::GetUid (void) const -{ - static uint32_t uid = RegisterUid (GetGlobalUid (), - &ObjectContainer::DeleteObject); - return uid; -} - -}//namespace ns3 - - -#endif /* OBJECT_CONTAINER_H */