diff --git a/server/c_string.hh b/server/c_string.hh index ca5a122..a45a926 100644 --- a/server/c_string.hh +++ b/server/c_string.hh @@ -88,9 +88,9 @@ struct InOutP; // Holds the length of the string in the previous c_string parameter template -struct InLength : In +struct InLength : public InBase { - typedef In Base; + typedef InBase Base; InLength(const js::Value& v, Context* ctx, unsigned param_nr) : Base( ctx->retrieve(param_nr-1) ) diff --git a/server/ev_server.cc b/server/ev_server.cc index 78fb138..8bee60d 100644 --- a/server/ev_server.cc +++ b/server/ev_server.cc @@ -29,20 +29,6 @@ #include "mini-adapter-impl.hh" -template<> -In::~In() -{ - // do nothing -} - -template<> -In::In(const js::Value&, Context* ctx, unsigned) -: value( ctx ) -{ - -} - - namespace fs = boost::filesystem; // compile-time default. might be overwritten in main() or before any ev_server function is called. diff --git a/server/inout.hh b/server/inout.hh index 19b1c6a..dcb6a16 100644 --- a/server/inout.hh +++ b/server/inout.hh @@ -10,6 +10,7 @@ // Just for debugging: #include + // is a bitfield that controls the In<> / Out<> parameter types enum class ParamFlag : unsigned { @@ -40,10 +41,7 @@ bool operator!(ParamFlag pf) namespace js = json_spirit; -template struct In; -template struct Out; -// "params" and "position" might be used to fetch additional parameters from the array. template T from_json(const js::Value& v); @@ -51,25 +49,16 @@ T from_json(const js::Value& v); template js::Value to_json(const T& t); - -// helper classes to specify in- and out-parameters -template -struct In +// common stuff in base class +template +struct InBase { typedef T c_type; // the according type in C function parameter enum { is_output = false, need_input = !(PF & ParamFlag::NoInput) }; - explicit In(const T& t) : value(t) {} - ~In(); - - In(const In& other) = delete; - In(In&& victim) = delete; - In& operator=(const In&) = delete; - - // default implementation: - In(const js::Value& v, Context*, unsigned param_nr) - : In( from_json(v) ) - { } + InBase(const InBase& other) = delete; + InBase(InBase&& victim) = delete; + void operator=(const InBase&) = delete; js::Value to_json() const { @@ -79,66 +68,61 @@ struct In c_type get_value() const { return value; } T value; + +protected: + explicit InBase(T&& t) : value(t) {} +}; + + +// helper classes to specify in- and out-parameters +template +struct In : public InBase +{ + typedef InBase Base; + ~In(); + + // default implementation: + In(const js::Value& v, Context*, unsigned param_nr) + : Base( from_json(v) ) + { } }; template -struct In +struct In : public InBase { - typedef T c_type; // the according type in C function parameter - enum { is_output = false, need_input = false }; - typedef In Self; - - explicit In(const T& t) : value(t) {} + typedef InBase Base; ~In() {} - In(const Self& other) = delete; - In(Self&& victim) = delete; - Self& operator=(const Self&) = delete; - - // default implementation: - In(const js::Value& v, Context*, unsigned param_nr) - : value{ T{} } + // default implementation: ignore all parameters + In(const js::Value&, Context*, unsigned param_nr) + : Base{ T{} } { } - - js::Value to_json() const - { - throw std::logic_error( std::string("Never call to_json() for a In<") + typeid(T).name() + "> data type! fn=" + __PRETTY_FUNCTION__ ); - } - - T get_value() const { return value; } - - T value; }; +class JsonAdapter; + +template<> +struct In : public InBase +{ + typedef InBase Base; + ~In() {} + + // defined in json-adapter.cc + In(const js::Value&, Context*, unsigned param_nr); +}; + // to call functions that operate directly on the JSON data type template -struct InRaw +struct InRaw : public InBase { - typedef js::Value c_type; // do not unwrap JSON data type - enum { is_output = false, need_input = !(PF & ParamFlag::NoInput) }; - - explicit InRaw(const js::Value& t) : value(t) {} ~InRaw() = default; - InRaw(const InRaw& other) = delete; - InRaw(InRaw&& victim) = delete; - InRaw& operator=(const InRaw&) = delete; - // default implementation: InRaw(const js::Value& v, Context*, unsigned param_nr) - : InRaw(v) + : InBase(v) { } - - js::Value to_json() const - { - throw std::logic_error( std::string(typeid(T).name()) + " is not for output!" ); - } - - c_type get_value() const { return value; } - - js::Value value; }; @@ -149,15 +133,9 @@ struct InOut : public In { typedef In Base; enum { is_output = true, need_input = !(PF & ParamFlag::NoInput) }; - - explicit InOut(const T& t) : Base(t) {} - ~InOut() = default; - InOut& operator=(const InOut&) = delete; - - // default implementation: - InOut(const js::Value& v, Context*, unsigned param_nr) - : Base( from_json(v) ) + InOut(const js::Value& v, Context* ctx, unsigned param_nr) + : Base(v, ctx, param_nr) { } js::Value to_json() const diff --git a/server/json-adapter.cc b/server/json-adapter.cc index adf2924..a61f5cb 100644 --- a/server/json-adapter.cc +++ b/server/json-adapter.cc @@ -172,9 +172,8 @@ JsonAdapter* from_json(const js::Value& /* not used */) } -template<> In::In(const js::Value&, Context*, unsigned) -: value{ &JsonAdapter::getInstance() } +: Base{ &JsonAdapter::getInstance() } { // nothing to do here. :-D } diff --git a/server/pEp-types.hh b/server/pEp-types.hh index 60b2383..06cfbee 100644 --- a/server/pEp-types.hh +++ b/server/pEp-types.hh @@ -48,9 +48,9 @@ struct In }; -struct In_Pep_Session : public In +struct In_Pep_Session : public InBase { - typedef In Base; + typedef InBase Base; // fetch PEP_SESSION from Context, instead of returning default value (which would be: nullptr) In_Pep_Session(const js::Value&, Context*, unsigned);