From 8c3b96b2b7c9bfda6b19fd96a4305ded8d52a164 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 21 Mar 2013 20:11:08 -0700 Subject: gras: move element details into header --- include/gras/CMakeLists.txt | 1 + include/gras/detail/element.hpp | 27 +++++++++++++++++++++++++++ include/gras/element.hpp | 21 ++++++++------------- 3 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 include/gras/detail/element.hpp (limited to 'include/gras') diff --git a/include/gras/CMakeLists.txt b/include/gras/CMakeLists.txt index 12e1bb1..0ea4f2d 100644 --- a/include/gras/CMakeLists.txt +++ b/include/gras/CMakeLists.txt @@ -30,6 +30,7 @@ install(FILES detail/block.hpp detail/chrono.hpp + detail/element.hpp detail/sbuffer.hpp detail/work_buffer.hpp diff --git a/include/gras/detail/element.hpp b/include/gras/detail/element.hpp new file mode 100644 index 0000000..35033e1 --- /dev/null +++ b/include/gras/detail/element.hpp @@ -0,0 +1,27 @@ +// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. + +#ifndef INCLUDED_GRAS_DETAIL_ELEMENT_HPP +#define INCLUDED_GRAS_DETAIL_ELEMENT_HPP + +namespace gras +{ + template + inline Element::Element(const boost::shared_ptr &elem) + { + *this = elem->shared_to_element(); + } + + //! Convert a shared ptr of a derived class to an Element + inline Element &Element::shared_to_element(void) + { + try + { + this->weak_self = this->shared_from_this(); + } + catch(...){} + return *this; + } + +} //namespace gras + +#endif /*INCLUDED_GRAS_DETAIL_ELEMENT_HPP*/ diff --git a/include/gras/element.hpp b/include/gras/element.hpp index 2b236ce..3211ac3 100644 --- a/include/gras/element.hpp +++ b/include/gras/element.hpp @@ -28,6 +28,10 @@ struct GRAS_API Element : ElementBase, boost::enable_shared_from_this //! Creates a new element given the name Element(const std::string &name); + /******************************************************************* + * identification interface + ******************************************************************/ + //! An integer ID that is unique across the process long unique_id(void) const; @@ -45,21 +49,10 @@ struct GRAS_API Element : ElementBase, boost::enable_shared_from_this * Good for that factory function/shared ptr paradigm. */ template - inline Element(const boost::shared_ptr &elem) - { - *this = elem->shared_to_element(); - } + inline Element(const boost::shared_ptr &elem); //! Convert a shared ptr of a derived class to an Element - inline Element &shared_to_element(void) - { - try - { - this->weak_self = this->shared_from_this(); - } - catch(...){} - return *this; - } + inline Element &shared_to_element(void); //! for internal use only boost::weak_ptr weak_self; @@ -68,6 +61,8 @@ struct GRAS_API Element : ElementBase, boost::enable_shared_from_this } //namespace gras +#include + #ifdef _MSC_VER #pragma warning(pop) #endif //_MSC_VER -- cgit