// $Id$ // // Copyright (C) 2008 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file \brief Variables inline template implementation */ #include "Variables.ih" // Custom includes #define prefix_ inline //-///////////////////////////////////////////////////////////////////////////////////////////////// //-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::detail::QueryVariable template prefix_ senf::console::detail::QueryVariable::QueryVariable(Variable const & var) : var_ (var) {} template prefix_ typename senf::console::detail::QueryVariable::Traits::Overload::ptr senf::console::detail::QueryVariable::create(Variable const & var) { return CreateOverload::create(Function(QueryVariable(var))); } template prefix_ Variable const & senf::console::detail::QueryVariable::operator()() const { return var_; } //-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::detail::SetVariable template prefix_ senf::console::detail::SetVariable::SetVariable(Variable & var, OnChangeHandler handler) : var_ (var), handler_ (handler) {} template prefix_ typename senf::console::detail::SetVariable::Traits::Overload::ptr senf::console::detail::SetVariable::create(Variable & var) { typename Traits::Overload::ptr overload (CreateOverload::create(Function(SetVariable(var)))); overload->arg(0).name = "new_value"; return overload; } template prefix_ void senf::console::detail::SetVariable::operator()(Variable const & value) const { if (handler_) { Variable old (var_); var_ = value; handler_(old); } else var_ = value; } //-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::ConstVariableFactory template prefix_ senf::console::factory::ConstVariableFactory senf::console::factory::ConstVariableFactory::doc(std::string const & doc) { doc_ = doc; return *this; } template prefix_ senf::console::factory::ConstVariableFactory senf::console::factory::ConstVariableFactory::shortdoc(std::string const & doc) { shortdoc_ = doc; return *this; } template prefix_ senf::console::factory::ConstVariableFactory senf::console::factory::ConstVariableFactory::formatter(Formatter formatter) { queryOverload_->formatter(formatter); return *this; } template prefix_ senf::console::OverloadedCommandNode & senf::console::factory::ConstVariableFactory::create(DirectoryNode & dir, std::string const & name) const { OverloadedCommandNode & node (OverloadedCommandNode::insertOverload(dir, name, queryOverload_)); if (doc_) node.doc(*doc_); if (shortdoc_) node.shortdoc(*shortdoc_); return node; } template prefix_ senf::console::factory::ConstVariableFactory:: ConstVariableFactory(Variable const & var) : queryOverload_ (detail::QueryVariable::create(var)) {} //-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::console::VariableFactory template prefix_ typename senf::console::factory::VariableFactory senf::console::factory::VariableFactory::parser(Parser parser) { setOverload_->template arg<0>().parser = parser; return *this; } template prefix_ typename senf::console::factory::VariableFactory senf::console::factory::VariableFactory::typeName(std::string const & name) { setOverload_->arg(0).type = name; return *this; } template prefix_ typename senf::console::factory::VariableFactory senf::console::factory::VariableFactory::onChange(OnChangeHandler handler) { setOverload_->function( boost::bind(detail::SetVariable(var_, handler),_2)); return *this; } template prefix_ typename senf::console::factory::VariableFactory senf::console::factory::VariableFactory::doc(std::string const & doc) { ConstVariableFactory::doc(doc); return *this; } template prefix_ typename senf::console::factory::VariableFactory senf::console::factory::VariableFactory::shortdoc(std::string const & doc) { ConstVariableFactory::shortdoc(doc); return *this; } template prefix_ typename senf::console::factory::VariableFactory senf::console::factory::VariableFactory::formatter(Formatter formatter) { ConstVariableFactory::formatter(formatter); return *this; } template prefix_ senf::console::OverloadedCommandNode & senf::console::factory::VariableFactory::create(DirectoryNode & dir, std::string const & name) const { OverloadedCommandNode & node (ConstVariableFactory::create(dir,name)); node.add(setOverload_); return node; } template prefix_ senf::console::factory::VariableFactory::VariableFactory(Variable & var) : ConstVariableFactory (var), setOverload_ (detail::SetVariable::create(var)), var_ (var) {} //-///////////////////////////////////////////////////////////////////////////////////////////////// template prefix_ senf::console::factory::VariableFactory senf::console::factory::Variable(Var & var) { return VariableFactory(var); } template prefix_ senf::console::factory::VariableFactory senf::console::factory::Variable(boost::reference_wrapper var) { return VariableFactory(var); } template prefix_ senf::console::factory::ConstVariableFactory senf::console::factory::Variable(Var const & var) { return ConstVariableFactory(var); } template prefix_ senf::console::factory::ConstVariableFactory senf::console::factory::Variable(boost::reference_wrapper var) { return ConstVariableFactory(var); } //-///////////////////////////////////////////////////////////////////////////////////////////////// #undef prefix_ // Local Variables: // mode: c++ // fill-column: 100 // comment-column: 40 // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" // compile-command: "scons -u test" // End: