Tide 0.1.0

memory_cluster.h

Go to the documentation of this file.
00001 /* Tide
00002  *
00003  * Header for the in-memory Cluster.
00004  *
00005  * Copyright 2011 Geoffrey Biggs geoffrey.biggs@aist.go.jp
00006  *     RT-Synthesis Research Group
00007  *     Intelligent Systems Research Institute,
00008  *     National Institute of Advanced Industrial Science and Technology (AIST),
00009  *     Japan
00010  *     All rights reserved.
00011  *
00012  * This file is part of Tide.
00013  *
00014  * Tide is free software; you can redistribute it and/or modify it under
00015  * the terms of the GNU Lesser General Public License as published by
00016  * the Free Software Foundation; either version 2.1 of the License, or
00017  * (at your option) any later version.
00018  *
00019  * Tide is distributed in the hope that it will be useful, but WITHOUT
00020  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00021  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00022  * License for more details.
00023  *
00024  * You should have received a copy of the GNU Lesser General Public
00025  * License along with Tide. If not, see <http://www.gnu.org/licenses/>.
00026  */
00027 
00028 #if !defined(TIDE_MEMORY_CLUSTER_H_)
00029 #define TIDE_MEMORY_CLUSTER_H_
00030 
00031 #include <boost/iterator/iterator_facade.hpp>
00032 #include <boost/type_traits/is_convertible.hpp>
00033 #include <boost/utility/enable_if.hpp>
00034 #include <tide/block_element.h>
00035 #include <tide/cluster.h>
00036 #include <tide/win_dll.h>
00037 
00040 
00041 namespace tide
00042 {
00050     class TIDE_EXPORT MemoryCluster : public Cluster
00051     {
00052         protected:
00054             typedef std::vector<BlockElement::Ptr> BlockStore;
00055 
00056         public:
00062             MemoryCluster(uint64_t timecode=0);
00063 
00065             // Iterator types
00067 
00068             template <typename BlockType, typename IterType>
00069             class TIDE_EXPORT IteratorBase
00070                 : public boost::iterator_facade<
00071                     IteratorBase<BlockType, IterType>,
00072                     BlockType, boost::bidirectional_traversal_tag>
00073             {
00074                 private:
00075                     struct enabler {};
00076 
00077                 public:
00079                     IteratorBase()
00080                     {
00081                     }
00082 
00087                     IteratorBase(IterType iter)
00088                         : iter_(iter)
00089                     {
00090                     }
00091 
00097                     template <typename OtherType, typename OtherIterType>
00098                     IteratorBase(IteratorBase<OtherType, OtherIterType> const& other)
00099                         : iter_(other.iter_)
00100                     {
00101                     }
00102 
00103                 protected:
00104                     // Necessary for Boost::iterator implementation.
00105                     friend class boost::iterator_core_access;
00106 
00107                     // Integrate with owning container
00108                     friend class MemoryCluster;
00109 
00110                     IterType iter_;
00111 
00113                     void increment()
00114                     {
00115                         ++iter_;
00116                     }
00117 
00119                     void decrement()
00120                     {
00121                         --iter_;
00122                     }
00123 
00128                     template <typename OtherType, typename OtherIterType>
00129                     bool equal(
00130                             IteratorBase<OtherType, OtherIterType> const& other) const
00131                     {
00132                         return iter_ == other.iter_;
00133                     }
00134 
00138                     BlockType& dereference() const
00139                     {
00140                         return *iter_;
00141                     }
00142             }; // class IteratorBase
00143 
00149             typedef IteratorBase<BlockElement::Ptr, BlockStore::iterator> Iterator;
00156             typedef IteratorBase<Block::ConstPtr, BlockStore::const_iterator>
00157                 ConstIterator;
00158 
00160             // Iterator access
00162 
00167             Iterator begin();
00172             ConstIterator begin() const;
00177             Iterator end();
00182             ConstIterator end() const;
00183 
00185             // Cluster interface
00187 
00189             virtual bool empty() const { return blocks_.empty(); }
00191             virtual size_type count() const { return blocks_.size(); }
00193             virtual void clear() { blocks_.clear(); }
00194 
00199             virtual void erase(Iterator position)
00200                 { blocks_.erase(position.iter_); }
00206             virtual void erase(Iterator first, Iterator last)
00207                 { blocks_.erase(first.iter_, last.iter_); }
00208 
00214             virtual void push_back(value_type const& value)
00215                 { blocks_.push_back(value); }
00216 
00218             std::streamsize finalise(std::ostream& output);
00219 
00220         protected:
00222             BlockStore blocks_;
00223 
00225             std::streamsize blocks_size() const;
00226 
00228             std::streamsize read_blocks(std::istream& input,
00229                     std::streamsize size);
00230     }; // class MemoryCluster
00231 }; // namespace tide
00232 
00234 // group elements
00235 
00236 #endif // TIDE_MEMORY_CLUSTER_H_
00237 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines