DCCL v4
Loading...
Searching...
No Matches
dynamic_conditions.h
1// Copyright 2022-2023:
2// GobySoft, LLC (2013-)
3// Community contributors (see AUTHORS file)
4// File authors:
5// Toby Schneider <toby@gobysoft.org>
6//
7//
8// This file is part of the Dynamic Compact Control Language Library
9// ("DCCL").
10//
11// DCCL is free software: you can redistribute it and/or modify
12// it under the terms of the GNU Lesser General Public License as published by
13// the Free Software Foundation, either version 2.1 of the License, or
14// (at your option) any later version.
15//
16// DCCL is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Lesser General Public License for more details.
20//
21// You should have received a copy of the GNU Lesser General Public License
22// along with DCCL. If not, see <http://www.gnu.org/licenses/>.
23#ifndef DCCLDYNAMICCONDITIONALS20220214H
24#define DCCLDYNAMICCONDITIONALS20220214H
25
26#include <google/protobuf/descriptor.h>
27#include <google/protobuf/message.h>
28
29#include "dccl/def.h"
30#include "option_extensions.pb.h"
31
32namespace sol
33{
34class state;
35}
36
37namespace dccl
38{
40{
41 public:
44
45 void set_field(const google::protobuf::FieldDescriptor* field_desc)
46 {
47 field_desc_ = field_desc;
48 }
49
50 void set_repeated_index(int index) { index_ = index; }
51
52 void regenerate(const google::protobuf::Message* this_msg,
53 const google::protobuf::Message* root_msg, int repeated_index = -1);
54
55 const dccl::DCCLFieldOptions::Conditions& conditions();
56
57 bool has_required_if() { return conditions().has_required_if() || conditions().has_only_if(); }
58 bool has_omit_if() { return conditions().has_omit_if() || conditions().has_only_if(); }
59 bool has_only_if() { return conditions().has_only_if(); }
60 bool has_min() { return conditions().has_min(); }
61 bool has_max() { return conditions().has_max(); }
62
63 bool required();
64 bool omit();
65
66 // required if true, omit if false
67 bool only();
68 double min();
69 double max();
70
71 private:
72 std::string return_prefix(const std::string& script)
73 {
74 if (script.find("return") == std::string::npos)
75 return "return " + script;
76 else
77 return script;
78 }
79
80 bool is_initialized() { return root_msg_ && this_msg_ && field_desc_; }
81 const google::protobuf::FieldDescriptor* field_desc_{nullptr};
82 const google::protobuf::Message* this_msg_{nullptr};
83 const google::protobuf::Message* root_msg_{nullptr};
84 int index_{0};
85
86#if DCCL_HAS_LUA
87 sol::state* lua_{nullptr};
88#endif
89};
90
91} // namespace dccl
92
93#endif
Dynamic Compact Control Language namespace.
Definition any.h:47