Browse Source

re-structured In<> and InOut<> class templates. I hope, MSVC is happy now.

JSON-143
Roker 2 years ago
parent
commit
9ea49f9073
5 changed files with 49 additions and 86 deletions
  1. +2
    -2
      server/c_string.hh
  2. +0
    -14
      server/ev_server.cc
  3. +44
    -66
      server/inout.hh
  4. +1
    -2
      server/json-adapter.cc
  5. +2
    -2
      server/pEp-types.hh

+ 2
- 2
server/c_string.hh View File

@ -88,9 +88,9 @@ struct InOutP<c_string, PF>;
// Holds the length of the string in the previous c_string parameter
template<ParamFlag PF = ParamFlag::Default>
struct InLength : In<size_t, PF>
struct InLength : public InBase<size_t, PF>
{
typedef In<size_t, PF> Base;
typedef InBase<size_t, PF> Base;
InLength(const js::Value& v, Context* ctx, unsigned param_nr)
: Base( ctx->retrieve(param_nr-1) )


+ 0
- 14
server/ev_server.cc View File

@ -29,20 +29,6 @@
#include "mini-adapter-impl.hh"
template<>
In<Context*, ParamFlag::Default>::~In()
{
// do nothing
}
template<>
In<Context*, ParamFlag::Default>::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.


+ 44
- 66
server/inout.hh View File

@ -10,6 +10,7 @@
// Just for debugging:
#include <iostream>
// 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<class T, ParamFlag PF> struct In;
template<class T, ParamFlag PF> struct Out;
// "params" and "position" might be used to fetch additional parameters from the array.
template<class T>
T from_json(const js::Value& v);
@ -51,25 +49,16 @@ T from_json(const js::Value& v);
template<class T>
js::Value to_json(const T& t);
// helper classes to specify in- and out-parameters
template<class T, ParamFlag PF=ParamFlag::Default>
struct In
// common stuff in base class
template<class T, ParamFlag PF>
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<T,PF>& other) = delete;
In(In<T,PF>&& victim) = delete;
In<T,PF>& operator=(const In<T,PF>&) = delete;
// default implementation:
In(const js::Value& v, Context*, unsigned param_nr)
: In( from_json<T>(v) )
{ }
InBase(const InBase<T,PF>& other) = delete;
InBase(InBase<T,PF>&& victim) = delete;
void operator=(const InBase<T,PF>&) = 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) {}
};
template<class T>
struct In<T, ParamFlag::NoInput>
// helper classes to specify in- and out-parameters
template<class T, ParamFlag PF=ParamFlag::Default>
struct In : public InBase<T,PF>
{
typedef T c_type; // the according type in C function parameter
enum { is_output = false, need_input = false };
typedef In<T, ParamFlag::NoInput> Self;
explicit In(const T& t) : value(t) {}
~In() {}
In(const Self& other) = delete;
In(Self&& victim) = delete;
Self& operator=(const Self&) = delete;
typedef InBase<T,PF> Base;
~In();
// default implementation:
In(const js::Value& v, Context*, unsigned param_nr)
: value{ T{} }
: Base( from_json<T>(v) )
{ }
};
template<class T>
struct In<T, ParamFlag::NoInput> : public InBase<T, ParamFlag::NoInput>
{
typedef InBase<T, ParamFlag::NoInput> Base;
~In() {}
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;
// default implementation: ignore all parameters
In(const js::Value&, Context*, unsigned param_nr)
: Base{ T{} }
{ }
};
class JsonAdapter;
template<>
struct In<JsonAdapter*, ParamFlag::NoInput> : public InBase<JsonAdapter*, ParamFlag::NoInput>
{
typedef InBase<JsonAdapter*, ParamFlag::NoInput> 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<class T, ParamFlag PF=ParamFlag::Default>
struct InRaw
struct InRaw : public InBase<T, PF>
{
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<T,PF>& other) = delete;
InRaw(InRaw<T,PF>&& victim) = delete;
InRaw<T,PF>& operator=(const InRaw<T,PF>&) = delete;
// default implementation:
InRaw(const js::Value& v, Context*, unsigned param_nr)
: InRaw(v)
: InBase<T,PF>(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<T,PF>
{
typedef In<T,PF> Base;
enum { is_output = true, need_input = !(PF & ParamFlag::NoInput) };
explicit InOut(const T& t) : Base(t) {}
~InOut() = default;
InOut<T,PF>& operator=(const InOut<T,PF>&) = delete;
// default implementation:
InOut(const js::Value& v, Context*, unsigned param_nr)
: Base( from_json<T>(v) )
InOut(const js::Value& v, Context* ctx, unsigned param_nr)
: Base(v, ctx, param_nr)
{ }
js::Value to_json() const


+ 1
- 2
server/json-adapter.cc View File

@ -172,9 +172,8 @@ JsonAdapter* from_json(const js::Value& /* not used */)
}
template<>
In<JsonAdapter*, ParamFlag::NoInput>::In(const js::Value&, Context*, unsigned)
: value{ &JsonAdapter::getInstance() }
: Base{ &JsonAdapter::getInstance() }
{
// nothing to do here. :-D
}


+ 2
- 2
server/pEp-types.hh View File

@ -48,9 +48,9 @@ struct In<Language>
};
struct In_Pep_Session : public In<PEP_SESSION, ParamFlag::NoInput>
struct In_Pep_Session : public InBase<PEP_SESSION, ParamFlag::NoInput>
{
typedef In<PEP_SESSION, ParamFlag::NoInput> Base;
typedef InBase<PEP_SESSION, ParamFlag::NoInput> Base;
// fetch PEP_SESSION from Context, instead of returning default value (which would be: nullptr)
In_Pep_Session(const js::Value&, Context*, unsigned);


Loading…
Cancel
Save