From f8c6579b910d2752f40850fbf17f045fa5de0366 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 12 Dec 2014 12:01:59 +0100 Subject: Update copyright headers --- include/astra/AstraObjectManager.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'include/astra/AstraObjectManager.h') diff --git a/include/astra/AstraObjectManager.h b/include/astra/AstraObjectManager.h index afb6312..ab4f39c 100644 --- a/include/astra/AstraObjectManager.h +++ b/include/astra/AstraObjectManager.h @@ -1,13 +1,13 @@ /* ----------------------------------------------------------------------- -Copyright 2012 iMinds-Vision Lab, University of Antwerp +Copyright: 2010-2014, iMinds-Vision Lab, University of Antwerp + 2014, CWI, Amsterdam -Contact: astra@ua.ac.be -Website: http://astra.ua.ac.be +Contact: astra@uantwerpen.be +Website: http://sf.net/projects/astra-toolbox +This file is part of the ASTRA Toolbox. -This file is part of the -All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA Toolbox"). The ASTRA Toolbox is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -- cgit v1.2.3 From 37fde19dfe60bb8e0b0d96119cc005f756172a3e Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Mon, 26 Jan 2015 11:36:11 +0100 Subject: Update copyright to -2015 --- include/astra/AstraObjectManager.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/astra/AstraObjectManager.h') diff --git a/include/astra/AstraObjectManager.h b/include/astra/AstraObjectManager.h index ab4f39c..895f955 100644 --- a/include/astra/AstraObjectManager.h +++ b/include/astra/AstraObjectManager.h @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------- -Copyright: 2010-2014, iMinds-Vision Lab, University of Antwerp - 2014, CWI, Amsterdam +Copyright: 2010-2015, iMinds-Vision Lab, University of Antwerp + 2014-2015, CWI, Amsterdam Contact: astra@uantwerpen.be Website: http://sf.net/projects/astra-toolbox -- cgit v1.2.3 From bc2e4018054f494fcba01e6a27a63e151bf1e9a4 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 16 Feb 2016 15:15:13 +0100 Subject: Refactor AstraObjectManager to add an AstraIndexManager The new AstraIndexManager can be used to obtain information about objects without knowing their type. --- include/astra/AstraObjectManager.h | 104 ++++++++++++++++++++++++++++--------- 1 file changed, 80 insertions(+), 24 deletions(-) (limited to 'include/astra/AstraObjectManager.h') diff --git a/include/astra/AstraObjectManager.h b/include/astra/AstraObjectManager.h index 895f955..eab3f03 100644 --- a/include/astra/AstraObjectManager.h +++ b/include/astra/AstraObjectManager.h @@ -52,17 +52,41 @@ namespace astra { * among all ObjectManagers. */ +class CAstraObjectManagerBase { + virtual std::string getInfo(int index) const =0; + virtual void remove(int index) =0; + virtual std::string getType() const =0; +}; -class CAstraIndexManager { -protected: - /** The index of the previously stored data object. + +class CAstraIndexManager : public Singleton { +public: + CAstraIndexManager() : m_iLastIndex(0) { } + + int store(CAstraObjectManagerBase* m) { + m_table[++m_iLastIndex] = m; + return m_iLastIndex; + } + + CAstraObjectManagerBase* get(int index) const { + std::map::const_iterator i; + i = m_table.find(index); + if (i != m_table.end()) + return i->second; + else + return 0; + } + +private: + /** The index last handed out */ - static int m_iPreviousIndex; + int m_iLastIndex; + std::map m_table; }; template -class CAstraObjectManager : public Singleton >, CAstraIndexManager { +class CAstraObjectManager : public CAstraObjectManagerBase { public: @@ -117,7 +141,11 @@ public: */ void clear(); - /** Get info. + /** Get info of object. + */ + std::string getInfo(int index) const; + + /** Get list with info of all managed objects. */ std::string info(); @@ -149,9 +177,9 @@ CAstraObjectManager::~CAstraObjectManager() template int CAstraObjectManager::store(T* _pDataObject) { - m_iPreviousIndex++; - m_mIndexToObject[m_iPreviousIndex] = _pDataObject; - return m_iPreviousIndex; + int iIndex = CAstraIndexManager::getSingleton().store(this); + m_mIndexToObject[iIndex] = _pDataObject; + return iIndex; } //---------------------------------------------------------------------------------------- @@ -219,20 +247,30 @@ void CAstraObjectManager::clear() //---------------------------------------------------------------------------------------- // Print info to string +template +std::string CAstraObjectManager::getInfo(int index) const { + typename map::const_iterator it = m_mIndexToObject.find(index); + if (it == m_mIndexToObject.end()) + return ""; + const T* pObject = it->second; + std::stringstream res; + res << index << " \t"; + if (pObject->isInitialized()) { + res << "v "; + } else { + res << "x "; + } + res << pObject->description(); + return res.str(); +} + template std::string CAstraObjectManager::info() { std::stringstream res; res << "id init description" << std::endl; res << "-----------------------------------------" << std::endl; - for (typename map::iterator it = m_mIndexToObject.begin(); it != m_mIndexToObject.end(); it++) { - res << (*it).first << " \t"; - T* pObject = m_mIndexToObject[(*it).first]; - if (pObject->isInitialized()) { - res << "v "; - } else { - res << "x "; - } - res << pObject->description() << endl; + for (typename map::const_iterator it = m_mIndexToObject.begin(); it != m_mIndexToObject.end(); it++) { + res << getInfo(it->first) << endl; } res << "-----------------------------------------" << std::endl; return res.str(); @@ -247,42 +285,60 @@ std::string CAstraObjectManager::info() { * assigned to each data object by which it can be accessed in the future. * Indices are always >= 1. */ -class _AstraExport CProjector2DManager : public CAstraObjectManager{}; +class _AstraExport CProjector2DManager : public Singleton, public CAstraObjectManager +{ + virtual std::string getType() const { return "projector2d"; } +}; /** * This class contains functionality to store 3D projector objects. A unique index handle will be * assigned to each data object by which it can be accessed in the future. * Indices are always >= 1. */ -class _AstraExport CProjector3DManager : public CAstraObjectManager{}; +class _AstraExport CProjector3DManager : public Singleton, public CAstraObjectManager +{ + virtual std::string getType() const { return "projector3d"; } +}; /** * This class contains functionality to store 2D data objects. A unique index handle will be * assigned to each data object by which it can be accessed in the future. * Indices are always >= 1. */ -class _AstraExport CData2DManager : public CAstraObjectManager{}; +class _AstraExport CData2DManager : public Singleton, public CAstraObjectManager +{ + virtual std::string getType() const { return "data2d"; } +}; /** * This class contains functionality to store 3D data objects. A unique index handle will be * assigned to each data object by which it can be accessed in the future. * Indices are always >= 1. */ -class _AstraExport CData3DManager : public CAstraObjectManager{}; +class _AstraExport CData3DManager : public Singleton, public CAstraObjectManager +{ + virtual std::string getType() const { return "data3d"; } +}; /** * This class contains functionality to store algorithm objects. A unique index handle will be * assigned to each data object by which it can be accessed in the future. * Indices are always >= 1. */ -class _AstraExport CAlgorithmManager : public CAstraObjectManager{}; +class _AstraExport CAlgorithmManager : public Singleton, public CAstraObjectManager +{ + virtual std::string getType() const { return "algorithm"; } +}; /** * This class contains functionality to store matrix objects. A unique index handle will be * assigned to each data object by which it can be accessed in the future. * Indices are always >= 1. */ -class _AstraExport CMatrixManager : public CAstraObjectManager{}; +class _AstraExport CMatrixManager : public Singleton, public CAstraObjectManager +{ + virtual std::string getType() const { return "matrix"; } +}; } // end namespace -- cgit v1.2.3 From 9847d2c4a8287f220f169236b4fa1962d50d1187 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 16 Feb 2016 15:22:59 +0100 Subject: Also remove objects from index manager --- include/astra/AstraObjectManager.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'include/astra/AstraObjectManager.h') diff --git a/include/astra/AstraObjectManager.h b/include/astra/AstraObjectManager.h index eab3f03..8b9da30 100644 --- a/include/astra/AstraObjectManager.h +++ b/include/astra/AstraObjectManager.h @@ -77,6 +77,13 @@ public: return 0; } + void remove(int index) { + std::map::iterator i; + i = m_table.find(index); + if (i != m_table.end()) + m_table.erase(i); + } + private: /** The index last handed out */ @@ -216,7 +223,9 @@ void CAstraObjectManager::remove(int _iIndex) // delete data delete (*it).second; // delete from map - m_mIndexToObject.erase(it); + m_mIndexToObject.erase(it); + + CAstraIndexManager::getSingleton().remove(_iIndex); } //---------------------------------------------------------------------------------------- -- cgit v1.2.3 From 8cfe13a410a051e5a6b9835e3a4cd6c808cf5d29 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 16 Feb 2016 15:34:08 +0100 Subject: Add astra_mex delete/info based on index manager --- include/astra/AstraObjectManager.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/astra/AstraObjectManager.h') diff --git a/include/astra/AstraObjectManager.h b/include/astra/AstraObjectManager.h index 8b9da30..35b4534 100644 --- a/include/astra/AstraObjectManager.h +++ b/include/astra/AstraObjectManager.h @@ -53,6 +53,7 @@ namespace astra { */ class CAstraObjectManagerBase { +public: virtual std::string getInfo(int index) const =0; virtual void remove(int index) =0; virtual std::string getType() const =0; -- cgit v1.2.3 From 7b6d74bd403f5bb0e4c8ba451eefa13193e7ed34 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 16 Feb 2016 16:19:26 +0100 Subject: Slightly simplify CAstraObjectManager::remove --- include/astra/AstraObjectManager.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'include/astra/AstraObjectManager.h') diff --git a/include/astra/AstraObjectManager.h b/include/astra/AstraObjectManager.h index 35b4534..ad89c2a 100644 --- a/include/astra/AstraObjectManager.h +++ b/include/astra/AstraObjectManager.h @@ -216,11 +216,10 @@ T* CAstraObjectManager::get(int _iIndex) const template void CAstraObjectManager::remove(int _iIndex) { - if (!hasIndex(_iIndex)) { - return; - } // find data typename map::iterator it = m_mIndexToObject.find(_iIndex); + if (it == m_mIndexToObject.end()) + return; // delete data delete (*it).second; // delete from map -- cgit v1.2.3 From 8b67986464daae799d0171aed70a0d2cd96fd8d1 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 22 Apr 2016 17:39:59 +0200 Subject: Fix build --- include/astra/AstraObjectManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/astra/AstraObjectManager.h') diff --git a/include/astra/AstraObjectManager.h b/include/astra/AstraObjectManager.h index ad89c2a..9faecbe 100644 --- a/include/astra/AstraObjectManager.h +++ b/include/astra/AstraObjectManager.h @@ -60,7 +60,7 @@ public: }; -class CAstraIndexManager : public Singleton { +class _AstraExport CAstraIndexManager : public Singleton { public: CAstraIndexManager() : m_iLastIndex(0) { } -- cgit v1.2.3