BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface software
restriction.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
26 
27 namespace graphene { namespace protocol {
28 
29 struct adder {
30  size_t sum = 0;
31  void operator()(const restriction& r) { sum += r.restriction_count(); }
32  void operator()(const vector<restriction>& r) { sum += std::for_each(r.begin(), r.end(), adder()).sum; }
33 };
34 
35 size_t restriction::restriction_count(const vector<restriction>& restrictions) {
36  return std::for_each(restrictions.begin(), restrictions.end(), adder()).sum;
37 }
38 
40  if (argument.is_type<vector<restriction>>()) {
41  const vector<restriction>& rs = argument.get<vector<restriction>>();
42  return 1 + std::for_each(rs.begin(), rs.end(), adder()).sum;
43  } else if (argument.is_type<vector<vector<restriction>>>()) {
44  const vector<vector<restriction>>& rs = argument.get<vector<vector<restriction>>>();
45  return 1 + std::for_each(rs.begin(), rs.end(), adder()).sum;
46  } else if (argument.is_type<variant_assert_argument_type>()) {
48  return 1 + std::for_each(arg.second.begin(), arg.second.end(), adder()).sum;
49  }
50  return 1;
51 }
52 
53 } } // namespace graphene::protocol
void operator()(const restriction &r)
Definition: restriction.cpp:31
Definition: api.cpp:56
static size_t restriction_count(const vector< restriction > &restrictions)
Definition: restriction.cpp:35
void operator()(const vector< restriction > &r)
Definition: restriction.cpp:32
pair< int64_t, vector< restriction >> variant_assert_argument_type
Definition: restriction.hpp:53
void for_each(T &&t, const account_object &a, seq< Is... >)
Definition: database.hpp:700