p≡p JSON adapter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.3 KiB

3 years ago
  1. // overloads, specializations & instantiations for pEp-sepcific data types.
  2. #ifndef PEP_TYPES_HH
  3. #define PEP_TYPES_HH
  4. #include "function_map.hh"
  5. #include <pEp/message_api.h>
  6. #include <pEp/sync_api.h>
  7. // just a tag type:
  8. struct Language{};
  9. template<>
  10. struct In<Language>
  11. {
  12. typedef const char* c_type; // the according type in C function parameter
  13. enum { is_output = false, need_input = true };
  14. ~In() = default;
  15. In(const In<Language>& other) = delete;
  16. In(In<Language>&& victim) = delete;
  17. void operator=(const In<Language>&) = delete;
  18. // default implementation:
  19. In<Language>(const js::Value& v, Context*, unsigned)
  20. {
  21. const std::string vs = v.get_str();
  22. if(vs.size() != 2)
  23. {
  24. throw std::runtime_error("Language must be a string of length 2, but I got \"" + vs + "\".");
  25. }
  26. array_value[0]=vs[0];
  27. array_value[1]=vs[1];
  28. array_value[2]='\0';
  29. }
  30. js::Value to_json() const
  31. {
  32. return js::Value( std::string(get_value(), get_value()+2) );
  33. }
  34. c_type get_value() const { return array_value; }
  35. char array_value[3];
  36. };
  37. struct In_Pep_Session : public InBase<PEP_SESSION, ParamFlag::NoInput>
  38. {
  39. typedef InBase<PEP_SESSION, ParamFlag::NoInput> Base;
  40. // fetch PEP_SESSION from Context, instead of returning default value (which would be: nullptr)
  41. In_Pep_Session(const js::Value&, Context*, unsigned);
  42. };
  43. #endif // PEP_TYPES_HH