/* Menes - C++ High-Level Utility Library * Copyright (C) 2002-2004 Jay Freeman (saurik) */ /* * Redistribution and use in source and binary * forms, with or without modification, are permitted * provided that the following conditions are met: *· * 1. Redistributions of source code must retain the * above copyright notice, this list of conditions * and the following disclaimer. * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions * and the following disclaimer in the documentation * and/or other materials provided with the * distribution. * 3. The name of the author may not be used to endorse * or promote products derived from this software * without specific prior written permission. *· * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef MENES_ETL_COMPOSITE_HPP #define MENES_ETL_COMPOSITE_HPP #include "cxx/platform.hpp" #ifdef MENES_PRAGMA_ONCE #pragma once #endif #include "etl/integral.hpp" #include "etl/list.hpp" #include "etl/traits.hpp" namespace etl { namespace be { template class CompositeType : public CompositeType { private: typedef CompositeType This_; typedef CompositeType Base_; static const size_t Index_ = Length::value; protected: typename Cell_::Head value_; protected: CompositeType() { } template CompositeType(const Arg0_ &arg0) : value_(arg0) { } template CompositeType(const Arg0_ &arg0, const Arg1_ &arg1) : Base_(arg0), value_(arg1) { } _finline bool operator <(const This_ &rhs) const { return value_ == rhs.value_ ? Base_::operator <(rhs) : value_ < rhs.value_; } _finline bool operator ==(const This_ &rhs) const { return value_ == rhs.value_ && Base_::operator ==(rhs); } }; template <> class CompositeType { private: typedef CompositeType This_; public: _finline bool operator <(const This_ &rhs) const { return false; } _finline bool operator ==(const This_ &rhs) const { return true; } }; } template class Composite : public be::CompositeType::Result> { private: typedef Composite This_; typedef typename Reverse::Result Order_; typedef be::CompositeType Base_; public: typedef typename Cell_::Head Head; public: Composite() { } template Composite(const Arg0_ &arg0) : Base_(arg0) { } template Composite(const Arg0_ &arg0, const Arg1_ &arg1) : Base_(arg0, arg1) { } template _finline const typename At::Result &Get() const { return be::CompositeType::Result>::value_; } template _finline typename At::Result &Get() { return be::CompositeType::Result>::value_; } template void Set(const typename At::Result &value) { be::CompositeType::Result>::value_ = value; } _finline const typename At::Result &First() const { return be::CompositeType::Result>::value_; } _finline typename At::Result &First() { return be::CompositeType::Result>::value_; } _finline const typename At::Result &Second() const { return be::CompositeType::Result>::value_; } _finline typename At::Result &Second() { return be::CompositeType::Result>::value_; } bool operator <(const This_ &rhs) const { return Base_::operator <(rhs); } bool operator ==(const This_ &rhs) const { return Base_::operator ==(rhs); } }; template struct IsMemMovable< etl::be::CompositeType > { static const bool value = IsMemMovable::value && IsMemMovable< etl::be::CompositeType >::value; }; template <> struct IsMemMovable< etl::be::CompositeType > { static const bool value = true; }; template struct IsMemMovable< etl::Composite > { static const bool value = IsMemMovable< etl::be::CompositeType::Result> >::value; }; template class Pair : public etl::Composite::Result> { private: typedef Pair This_; typedef etl::Composite::Result> Base_; public: Pair() { } Pair(const This_ &rhs) : Base_(rhs.First(), rhs.Second()) { } Pair(const First_ &first) : Base_(first) { } Pair(const First_ &first, const Second_ &second) : Base_(first, second) { } template Pair(const Pair &rhs) : Base_(rhs.First(), rhs.Second()) { } }; template struct IsMemMovable< etl::Pair > { static const bool value = IsMemMovable< etl::Composite::Result> >::value; }; template < typename Arg0_ = be::ListNull_, typename Arg1_ = be::ListNull_, typename Arg2_ = be::ListNull_, typename Arg3_ = be::ListNull_, typename Arg4_ = be::ListNull_, typename Arg5_ = be::ListNull_, typename Arg6_ = be::ListNull_ > struct Tuple { typedef Composite::Result> Result; }; } #endif//MENES_ETL_COMPOSITE_HPP