// Copyright (c) 2005-2007 Andre Merzky (andre@merzky.net) // Copyright (c) 2005-2007 Hartmut Kaiser (hartmut.kaiser@gmail.com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef SAGA_IMPL_ENGINE_ATTRIBUTE_CACHE_HPP #define SAGA_IMPL_ENGINE_ATTRIBUTE_CACHE_HPP // include stl #include #include #include #include #include // suppress warnings about dependent classes not being exported from the dll #if defined(BOOST_MSVC) #pragma warning(push) #pragma warning(disable : 4251 4231 4660) #endif /////////////////////////////////////////////////////////////////////////////// namespace saga { namespace impl { /////////////////////////////////////////////////////////////////////////// // in SAGA, attribute is actually an interface. However, our implementation // does not shy back from multiple inheritance, and implement it here... class SAGA_EXPORT attrib { public: typedef std::vector strvec_type; typedef std::map strmap_type; enum type { Unknown = -1, Scalar = 0, Vector = 1 }; private: std::string key_; // name of attrib strvec_type val_; // value of attrib type type_; // scalar or vector attrib? bool ro_; // is attrib read only? bool ext_; // is attrib an extension? public: explicit attrib (type type = Scalar, bool ro = true, bool ext = false); attrib (std::string const& key, std::string const& val, type type = Scalar, bool ro = true, bool ext = false); attrib (std::string const& key, strvec_type const& val, type type = Scalar, bool ro = true, bool ext = false); bool is_ro (void) const; bool is_ext (void) const; bool is_vec (void) const; void val (std::string const& in); void val (strvec_type const& in); std::string key (void) const; std::string val_s (void) const; strvec_type val_v (void) const; }; SAGA_EXPORT bool operator==(attrib const& lhs, attrib const& rhs); /////////////////////////////////////////////////////////////////////////// class SAGA_EXPORT attribute_cache { public: typedef std::vector strvec_type; typedef std::map strmap_type; typedef std::map a_map_type; private: typedef boost::recursive_mutex mutex_type; // the attributes mutable mutex_type mtx_; a_map_type a_map_; // allowed key names (used, if extensible is false) strvec_type keynames_; // have attributes been initialized? bool inited_; // can custom attrib's be defined? bool extensible_; public: bool is_valid_key(std::string const& key) const; attribute_cache (void); attribute_cache (attribute_cache const& rhs); void init (strmap_type const& ro_scalar, strmap_type const& rw_scalar, strmap_type const& ro_vector, strmap_type const& rw_vector); void init (bool extensible); void init_keynames(strvec_type const& keynames); // setters/getters std::string get_attribute (std::string const& key) const; void set_attribute (std::string const& key, std::string const& val); strvec_type get_vector_attribute (std::string const& key) const; void set_vector_attribute (std::string const& key, strvec_type const& val); void remove_attribute (std::string const& key); // inspection strvec_type list_attributes () const; strvec_type find_attributes (std::string const& pattern) const; bool attribute_exists (std::string const& key) const; bool attribute_is_readonly (std::string const& key) const; bool attribute_is_writable (std::string const& key) const; bool attribute_is_vector (std::string const& key) const; bool attribute_is_extended (std::string const& key) const; bool attributes_extensible () const; attribute_cache clone() const; bool is_equal(attribute_cache const& rhs) const; }; } // namespace impl } // namespace saga #if defined(BOOST_MSVC) #pragma warning(pop) #endif #endif // SAGA_IMPL_ENGINE_ATTRIBUTE_CACHE_HPP