User Manual, Developers Guide and API Documentation

MultiAccessible.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 5, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 
00029 #ifndef WNS_CONTAINER_MULTIACCESSIBLE_HPP
00030 #define WNS_CONTAINER_MULTIACCESSIBLE_HPP
00031 
00032 #include <WNS/Assure.hpp>
00033 
00034 #include <cstddef>
00035 #include <cassert>
00036 #include <algorithm>
00037 
00038 namespace wns { namespace container {
00042     namespace MultiAccessibleDefs
00043     {
00047         typedef std::size_t SizeType;
00048     }
00049 
00078     template<typename T,
00079          MultiAccessibleDefs::SizeType N,
00080          typename R = const T&,
00081          typename I = MultiAccessibleDefs::SizeType
00082          >
00083     class MultiReadAccessible
00084     {
00085     public:
00089         typedef T ValueType;
00090 
00094         typedef MultiAccessibleDefs::SizeType SizeType;
00095 
00099         typedef I IndexType;
00100 
00104         typedef R ReturnType;
00105 
00110         typedef const MultiReadAccessible<ValueType, N-1, ReturnType, IndexType>& ConstReference;
00111 
00115         virtual ~MultiReadAccessible() {};
00116 
00123         virtual ConstReference operator[](const IndexType& index) const = 0;
00124 
00141         template<class InputIterator>
00142         ValueType at(const InputIterator& first, const InputIterator& last) const
00143         {
00144             InputIterator temp = first;
00145             return (*this)[*first].at(++temp, last);
00146         }
00147 
00154         virtual SizeType dimSize(const SizeType& dim) const = 0;
00155 
00161         virtual SizeType size() const
00162         {
00163             SizeType s = 1;
00164             for (SizeType i = 0; i < N; ++i) s *= dimSize(i);
00165             return s;
00166         }
00167     };
00168 
00169     template<typename T,
00170          typename ReturnType,
00171          typename I
00172          >
00173     class MultiReadAccessible<T, 1, ReturnType, I>
00174     {
00175     public:
00176         typedef T ValueType;
00177         typedef MultiAccessibleDefs::SizeType SizeType;
00178         typedef I IndexType;
00179 
00180         virtual ~MultiReadAccessible() {};
00181 
00182         virtual ReturnType operator[](const IndexType& index) const = 0;
00183 
00184         template<class InputIterator>
00185 #ifndef WNS_NDEBUG
00186         ValueType at(const InputIterator& first, const InputIterator& last) const
00187 #else
00188         ValueType at(const InputIterator& first, const InputIterator& /*last*/) const
00189 #endif
00190         {
00191             assure(std::distance(first, last) == 1, "range error");
00192             return (*this)[*first];
00193         }
00194 
00195         virtual SizeType dimSize(const SizeType& dim) const = 0;
00196 
00197         virtual SizeType size() const
00198         {
00199             return dimSize(0);
00200         }
00201     };
00202 
00232     template<typename T,
00233          MultiAccessibleDefs::SizeType N,
00234          typename I = MultiAccessibleDefs::SizeType>
00235     class MultiWriteAccessible
00236     {
00237     public:
00241         typedef T ValueType;
00242 
00246         typedef MultiAccessibleDefs::SizeType SizeType;
00247 
00251         typedef I IndexType;
00252 
00257         typedef MultiWriteAccessible<ValueType, N-1, IndexType>& Reference;
00258 
00262         virtual ~MultiWriteAccessible() {};
00263 
00269         virtual Reference operator[](const IndexType& index) = 0;
00270 
00288         template<class InputIterator>
00289         ValueType& at(const InputIterator& first, const InputIterator& last)
00290         {
00291             InputIterator temp = first;
00292             return (*this)[*first].at(++temp, last);
00293         }
00294 
00301         virtual SizeType dimSize(const SizeType& dim) const = 0;
00302 
00308         virtual SizeType size() const
00309         {
00310             SizeType s = 1;
00311             for (SizeType i = 0; i < N; ++i) s *= dimSize(i);
00312             return s;
00313         }
00314     };
00315 
00316     template<typename T,
00317          typename I>
00318     class MultiWriteAccessible<T, 1, I>
00319     {
00320     public:
00321         typedef T ValueType;
00322         typedef MultiAccessibleDefs::SizeType SizeType;
00323         typedef I IndexType;
00324 
00325         typedef ValueType& Reference;
00326 
00327         virtual ~MultiWriteAccessible() {};
00328 
00329         virtual Reference operator[](const IndexType& index) = 0;
00330 
00331         template<class InputIterator>
00332         Reference at(const InputIterator& first, const InputIterator& last)
00333         {
00334             assert(std::distance(first, last) == 1);
00335             return (*this)[*first];
00336         }
00337 
00338         virtual SizeType dimSize(const SizeType& dim) const = 0;
00339 
00340         virtual SizeType size() const
00341         {
00342             return dimSize(0);
00343         }
00344     };
00345 
00359     template<typename T,
00360          MultiAccessibleDefs::SizeType N,
00361          typename R = const T&,
00362          typename I = MultiAccessibleDefs::SizeType>
00363     class MultiReadWriteAccessible : public MultiReadAccessible<T, N, R, I>,
00364                      public MultiWriteAccessible<T, N, I>
00365     {
00366     public:
00370         typedef T ValueType;
00371 
00375         typedef MultiAccessibleDefs::SizeType SizeType;
00376 
00380         typedef I IndexType;
00381 
00385         typedef R ReturnType;
00386 
00390         virtual ~MultiReadWriteAccessible() {};
00391 
00398         virtual SizeType dimSize(const SizeType& dim) const = 0;
00399 
00405         virtual SizeType size() const
00406         {
00407             SizeType s = 1;
00408             for (SizeType i = 0; i < N; ++i) s *= dimSize(i);
00409             return s;
00410         }
00411     };
00412 }}
00413 
00414 #endif // _MULTIACCESSIBLE_HPP
00415 
00416 

Generated on Fri May 25 03:31:36 2012 for openWNS by  doxygen 1.5.5