// Copyright (c) 2005-2007 Andre Merzky (andre@merzky.net) // Copyright (c) 2005-2007 Hartmut Kaiser (hartmut.kaiser@gmail.com) // Copyright (c) 2005 Michel Zandstra [michelzandstra@gmail.com] // // Distributed under the Boost Software License, Version 1.0. (See accompanying // job LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef CONTEXT_BASE_HPP #define CONTEXT_BASE_HPP #include #include #include #include #include #include #include #include #include namespace saga { namespace impl { /** * Context_base: base class for all context classes */ class context : public saga::impl::object, public saga::impl::attribute, public saga::context_base { private: typedef saga::impl::attribute attribute_base; saga::context::type type_; explicit context (saga::context::type t, attribute const& rhs_attr) : saga::impl::object(saga::object::Context), attribute_base(rhs_attr), type_ (t) { } public: /** constructor, defines context type */ explicit context (saga::context::type t) : object(saga::object::Context), type_ (t) { } /** Get the type of this context */ saga::context::type get_ctype (void) const { return type_; }; // saga::object interface saga::object clone() const { if (type_ == saga::context_base::Unknown) { SAGA_THROW("Can't clone a context of type 'Unknown'.", saga::IncorrectState); } return saga::context(new saga::impl::context(type_, static_cast(*this))); } bool is_equal (saga::impl::object *rhs) const { if (rhs->get_type() != saga::object::Context || static_cast(rhs)->get_ctype() != type_) { return false; } return static_cast(*this).is_equal( *(rhs->get_attributes())); } saga::impl::attribute* get_attributes() { return this; } saga::impl::attribute const* get_attributes() const { return this; } }; // class context_base } // namespace impl } // namespace saga #endif // CONTEXT_BASE_HPP