Turi Create  4.0
function_closure_info.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 // this file should not be included directly
7 // due to circular include issues with variant.hpp
8 // instead. we redirect to variant.hpp which will then include this again.
9 #include <model_server/lib/variant.hpp>
10 #ifndef TURI_UNITY_LIB_API_FUNCTION_CLOSURE_INFO_HPP
11 #define TURI_UNITY_LIB_API_FUNCTION_CLOSURE_INFO_HPP
12 #include <string>
13 #include <vector>
14 #include <utility>
15 #include <memory>
16 #include <core/storage/serialization/serialization_includes.hpp>
17 namespace turi {
18 /**
19  * Describes a function capture closure.
20  *
21  * Defines a closure class describing a lambda closure. Contains 2 fields:
22  *
23  * \param native_fn_name The toolkit native function name
24  *
25  * \param arguments An array of the same length as the toolkit native function.
26  * Each array element is an array of 2 elements [is_capture, value]
27  * \code{.py}
28  * If is_capture == 1:
29  * value contains the captured value
30  * If is_capture == 0:
31  * value contains a number denoting the lambda argument position.
32  * \endcode
33  *
34  * Example:
35  * \code{.py}
36  * lambda x, y: fn(10, x, x, y)
37  * \endcode
38  *
39  * Then arguments will be
40  *
41  * [1, 10], --> is captured value. has value 10
42  * [0, 0], --> is not captured value. is argument 0 of the lambda.
43  * [0, 0], --> is not captured value. is argument 0 of the lambda.
44  * [0, 1] --> is not captured value. is argument 1 of the lambda.
45  * \endcode
46  */
48  std::string native_fn_name;
49  std::vector<std::pair<size_t, std::shared_ptr<variant_type>>> arguments;
50 
51  enum argument_type {
52  CAPTURED_VALUE = 1,
53  PARAMETER = 0
54  };
55 
56  void save(oarchive& oarc) const;
57  void load(iarchive& iarc);
58 };
59 
60 } // namespace turi
61 #endif // TURI_UNITY_LIB_API_FUNCTION_CLOSURE_INFO_HPP
The serialization input archive object which, provided with a reference to an istream, will read from the istream, providing deserialization capabilities.
Definition: iarchive.hpp:60
The serialization output archive object which, provided with a reference to an ostream, will write to the ostream, providing serialization capabilities.
Definition: oarchive.hpp:80