Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: conditionally group bindings in a trait? #143

Open
michael-brade opened this issue Sep 4, 2023 · 0 comments
Open

Question: conditionally group bindings in a trait? #143

michael-brade opened this issue Sep 4, 2023 · 0 comments
Assignees
Labels

Comments

@michael-brade
Copy link

michael-brade commented Sep 4, 2023

Hi, another question: is it possible to conditially group a set of members in a binding trait, and if so, what's the syntax?

a bit stupid example because you could create another struct/class Turnus with its own binding instead:

struct test {
  int		m_id;
  std::string	m_turnusEinheit{}; //'E'=einmalig, 'D'=täglich, 'W'=wöchentlich, 'M'=monatlich
  unsigned int	m_turnusAnzahl{};  // abhängig von der Turnuseinheit auszuwerten, z.B. 2 = alle 2 Wochen/Monate
  unsigned int	m_turnusTag{};	  //'W': 1-7 = Montag-Sonntag; 'M': 1-31 = der 1. des Monats, der 2. des Monats,..., der 31. des Monats
};

template<typename T, typename = void>
struct my_traits
    : public tao::json::traits<T>
{};

template<>
struct my_traits<test>
    : public tao::json::binding::object<
           TAO_JSON_BIND_REQUIRED("id", &test::m_id),
	   // TODO: all three only if (!m_turnusEinheit.empty())
           TAO_JSON_BIND_OPTIONAL("turnusEinheit", &test::m_turnusEinheit),
           TAO_JSON_BIND_OPTIONAL("turnusAnzahl", &test::m_turnusAnzahl),
           TAO_JSON_BIND_OPTIONAL("turnusTag", &test::m_turnusTag)
     >
{};
@ColinH ColinH self-assigned this Sep 4, 2023
@ColinH ColinH added the question label Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants