From 12105975f42bf06b36ca6f741008504afec7054f Mon Sep 17 00:00:00 2001 From: Adam Radziszewski <adam.radziszewski@pwr.wroc.pl> Date: Thu, 1 Dec 2011 12:51:02 +0100 Subject: [PATCH] add has (var_name) to ParsedExpression --- CMakeLists.txt | 2 +- libwccl/ops/parsedexpression.h | 14 ++++++++++++++ swig/parsedexpression.i | 10 +++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2fbf777..ec1f390 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.0) set(wccl_ver_major "0") set(wccl_ver_minor "1") -set(wccl_ver_patch "3") +set(wccl_ver_patch "4") set(LIBWCCL_VERSION "${wccl_ver_major}.${wccl_ver_minor}.${wccl_ver_patch}") diff --git a/libwccl/ops/parsedexpression.h b/libwccl/ops/parsedexpression.h index c8daf20..d615f8d 100644 --- a/libwccl/ops/parsedexpression.h +++ b/libwccl/ops/parsedexpression.h @@ -129,6 +129,14 @@ public: template<class T> void set(const std::string& var_name, const T& value); + /** + * Checks if has a variable with given name and type. + * @returns if such variable exists AND is of type T. + * @param var_name Variable name. + */ + template<class T> + bool has(const std::string& var_name); + /** * Sets all variables to their default values. * @note Values of variables are preserved between applications @@ -235,6 +243,12 @@ void ParsedExpression::set(const std::string& var_name, const T& value) { get<T>(var_name) = value; } +template<class T> +bool ParsedExpression::has(const std::string& var_name) { + boost::shared_ptr<T> value = variables_->get<T>(var_name); + return value; +} + inline void ParsedExpression::clean() { diff --git a/swig/parsedexpression.i b/swig/parsedexpression.i index fdaa42c..b8e216a 100644 --- a/swig/parsedexpression.i +++ b/swig/parsedexpression.i @@ -42,8 +42,16 @@ namespace Wccl { %template(get_strset) get<StrSet>; %template(get_position) get<Position>; %template(get_match) get<Match>; + + template<class T> bool has(const std::string& var_name); + %template(has_bool) has<Bool>; + %template(has_tset) has<TSet>; + %template(has_strset) has<StrSet>; + %template(has_position) has<Position>; + %template(has_match) has<Match>; - /* --------------------------------------------------------------------- */ + /* Those functions are overridden later to handle shared_ptr values, + * anyway they are needed for those overrides to work. */ template<class T> void set(const std::string& var_name, const T& value); %template(set_bool) set<Bool>; %template(set_tset) set<TSet>; -- GitLab