Mirror reflection library - Lagoon run-time layer 0.5.13

lagoon/range/limit.hpp

Go to the documentation of this file.
00001 
00010 #ifndef LAGOON_RANGE_LIMIT_1011291729_HPP
00011 #define LAGOON_RANGE_LIMIT_1011291729_HPP
00012 
00013 #include <lagoon/lagoon_fwd.hpp>
00014 #include <cassert>
00015 
00016 LAGOON_NAMESPACE_BEGIN
00017 namespace aux {
00018 
00019 template <class Range>
00020 struct limited
00021 {
00022 private:
00023     Range range;
00024     size_t remaining;
00025 
00026 public:
00027     limited(limited&& other)
00028      : range(std::move(other.range))
00029      , remaining(other.remaining)
00030     { }
00031 
00032     limited(const Range& rng, size_t limit)
00033      : range(rng)
00034      , remaining(limit)
00035     { }
00036 
00037     limited(Range&& rng, size_t limit)
00038      : range(std::forward(rng))
00039      , remaining(limit)
00040     { }
00041 
00042     inline bool empty(void) const
00043     {
00044         return (remaining == 0) || range.empty();
00045     }
00046 
00047     void step_front(void)
00048     {
00049         assert(remaining != 0);
00050         --remaining;
00051         range.step_front();
00052     }
00053 
00054     size_t leap_front(size_t amount)
00055     {
00056         if(amount > remaining)
00057             amount = remaining;
00058         return range.leap_front(amount);
00059 
00060     }
00061 
00062     inline auto front(void) const -> decltype(range.front())
00063     {
00064         assert(remaining != 0);
00065         return range.front();
00066     }
00067 
00068     friend inline bool same_position(
00069         const limited& a,
00070         const limited& b
00071     )
00072     {
00073         return same_position(a.range, b.range);
00074     }
00075 };
00076 
00077 } // namespace aux
00078 
00079 #ifdef MIRROR_DOCUMENTATION_ONLY
00080 
00081 
00089 template <class Range>
00090 UnspecifiedRange limit(Range range, size_t count);
00091 #else
00092 template <class Range>
00093 inline aux::limited<Range> limit(Range range, size_t count)
00094 {
00095     return aux::limited<Range>(range, count);
00096 }
00097 #endif
00098 
00099 LAGOON_NAMESPACE_END
00100 
00101 #endif //include guard
00102 

Copyright © 2006-2011 Matus Chochlik, University of Zilina, Zilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Fri Dec 16 2011 by Doxygen (version 1.7.3).
Important note: Although the 'boostified' version of Mirror uses the Boost C++ libraries Coding Guidelines and is implemented inside of the boost namespace, it IS NOT an officially reviewed and accepted Boost library. Mirror is being developed with the intention to be submitted for review for inclusion to the Boost C++ libraries.