ISIS Core Library 0.7.2 (api 3.0.0)
|
00001 /* 00002 Copyright (C) 2010 reimer@cbs.mpg.de 00003 00004 This program is free software: you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation, either version 3 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 00017 */ 00018 00019 #ifndef SORTEDCHUNKLIST_HPP 00020 #define SORTEDCHUNKLIST_HPP 00021 00022 #include "chunk.hpp" 00023 #include "../CoreUtils/vector.hpp" 00024 #include <stack> 00025 #include <boost/shared_ptr.hpp> 00026 00028 namespace isis 00029 { 00030 namespace data 00031 { 00032 namespace _internal 00033 { 00034 00035 /* 00036 * This class sorts the inserted chunks by the given properties while construction. 00037 * The rules of the sorting depends on the upper level using these chunkLists later on. 00038 * See the special classes, e.g. MRImage to find details about sorting criterias. 00039 */ 00040 class SortedChunkList 00041 { 00042 public: 00043 struct scalarPropCompare { 00044 util::PropertyMap::KeyType propertyName; 00045 scalarPropCompare( const util::PropertyMap::KeyType &prop_name ); 00046 bool operator()( const util::PropertyValue &a, const util::PropertyValue &b ) const; 00047 }; 00048 struct posCompare { 00049 bool operator()( const util::fvector3 &a, const util::fvector3 &b ) const; 00050 }; 00051 struct chunkPtrOperator { 00052 virtual boost::shared_ptr<Chunk> operator()( const boost::shared_ptr<Chunk> &ptr ) = 0; 00053 virtual ~chunkPtrOperator(); 00054 }; 00055 private: 00056 typedef std::map<util::PropertyValue, boost::shared_ptr<Chunk>, scalarPropCompare> SecondaryMap; 00057 typedef std::map<util::fvector3, SecondaryMap, posCompare> PrimaryMap; 00058 00059 std::stack<scalarPropCompare> secondarySort; 00060 posCompare primarySort; 00061 PrimaryMap chunks; 00062 00063 // low level finding 00064 boost::shared_ptr<Chunk> secondaryFind( const util::PropertyValue &key, SecondaryMap &map ); 00065 SecondaryMap *primaryFind( const util::fvector3 &key ); 00066 00067 // low level inserting 00068 std::pair<boost::shared_ptr<Chunk>, bool> secondaryInsert( SecondaryMap &map, const Chunk &ch ); 00069 std::pair<boost::shared_ptr<Chunk>, bool> primaryInsert( const Chunk &ch ); 00070 00071 std::list<util::PropertyMap::PropPath> equalProps; 00072 public: 00073 00074 //initialisation 00078 SortedChunkList( util::PropertyMap::KeyType comma_separated_equal_props ); 00079 00084 void addSecondarySort( const util::PropertyMap::KeyType &cmp ); 00085 00086 // utils 00087 00089 void transform( chunkPtrOperator &op ); 00090 00092 bool insert( const Chunk &ch ); 00093 00095 bool isEmpty()const; 00096 00098 void clear(); 00099 00101 std::vector<boost::shared_ptr<Chunk> > getLookup(); 00102 00104 bool isRectangular(); 00105 00107 size_t getHorizontalSize(); 00108 }; 00109 00110 00111 } 00112 } 00113 } 00115 00116 #endif // SORTEDCHUNKLIST_HPP