Adobe Source Libraries 1.49.0
A collection of C++ libraries.
Loading...
Searching...
No Matches
virtual_machine.hpp
Go to the documentation of this file.
1/*
2 Copyright 2013 Adobe
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5*/
6/**************************************************************************************************/
7
8#ifndef ADOBE_VIRTUAL_MACHINE_HPP
9#define ADOBE_VIRTUAL_MACHINE_HPP
10
11#include <adobe/config.hpp>
12
13#include <bitset>
14#include <functional>
15#include <optional>
16#include <stdexcept>
17#include <string>
18#include <vector>
19
20
21#define BOOST_FUNCTION_NO_DEPRECATED
22#include <boost/operators.hpp>
23
24#include <adobe/any_regular.hpp>
25#include <adobe/array_fwd.hpp>
27#include <adobe/name.hpp>
28
29/**************************************************************************************************/
30
31namespace adobe {
32
33/**************************************************************************************************/
34
36const char* type_name(const std::type_info& type);
37
38/**************************************************************************************************/
39
41template <class T>
42auto cast(adobe::any_regular_t& x) -> decltype(x.cast<T>()) {
43 if constexpr (!std::is_same_v<T, adobe::any_regular_t>) {
44 if (x.type_info() != typeid(promote_t<T>))
45 throw std::runtime_error(std::string{"expected `"} + type_name(typeid(promote_t<T>)) +
46 "` found `" + type_name(x.type_info()) + "`");
47 }
48 return x.cast<T>();
49}
50
52template <class T>
53auto cast(const adobe::any_regular_t& x) -> decltype(x.cast<T>()) {
54 if constexpr (!std::is_same_v<T, adobe::any_regular_t>) {
55 if (x.type_info() != typeid(promote_t<T>))
56 throw std::runtime_error(std::string{"expected `"} + type_name(typeid(promote_t<T>)) +
57 "` found `" + type_name(x.type_info()) + "`");
58 }
59 return x.cast<T>();
60}
61
62/**************************************************************************************************/
63/*
64 Note: For all bitwise operators the numeric data type (double) will be cast down to a
65 std::uint32_t for the operation.
66*/
68public:
70
76 std::size_t index);
77
78 using variable_lookup_t = std::function<variable_lookup_signature_t>;
79 using dictionary_function_lookup_t = std::function<dictionary_function_lookup_signature_t>;
80 using array_function_lookup_t = std::function<array_function_lookup_signature_t>;
81 using named_index_lookup_t = std::function<named_index_lookup_signature_t>;
82 using numeric_index_lookup_t = std::function<numeric_index_lookup_signature_t>;
83
85 const any_regular_t&);
86
87 using binary_op_override_t = std::function<binary_op_override_signature_t>;
88
89#if !defined(ADOBE_NO_DOCUMENTATION)
92
94
96#endif
97
98 void evaluate(const expression_t& expression);
99#if 0
100 void evaluate_named_arguments(const dictionary_t&);
101#endif
102
103 const any_regular_t& back() const;
105 void pop_back();
106
112
114
115 class implementation_t;
116
117private:
118 implementation_t* object_m;
119};
120
121/**************************************************************************************************/
122
123} // namespace adobe
124
125/**************************************************************************************************/
126
127#endif
128
129/**************************************************************************************************/
A runtime polymorphic type similar to boost::any which can hold any type which models Regular.
void set_variable_lookup(const variable_lookup_t &)
void override_operator(name_t, const binary_op_override_t &)
std::function< dictionary_function_lookup_signature_t > dictionary_function_lookup_t
any_regular_t & back()
any_regular_t numeric_index_lookup_signature_t(const any_regular_t &, std::size_t index)
std::function< array_function_lookup_signature_t > array_function_lookup_t
virtual_machine_t(const virtual_machine_t &)
any_regular_t binary_op_override_signature_t(const any_regular_t &, const any_regular_t &)
void set_dictionary_function_lookup(const dictionary_function_lookup_t &)
const any_regular_t & back() const
void set_numeric_index_lookup(const numeric_index_lookup_t &)
virtual_machine_t & operator=(const virtual_machine_t &rhs)
std::function< binary_op_override_signature_t > binary_op_override_t
std::function< numeric_index_lookup_signature_t > numeric_index_lookup_t
std::function< variable_lookup_signature_t > variable_lookup_t
any_regular_t dictionary_function_lookup_signature_t(name_t, const dictionary_t &)
std::function< named_index_lookup_signature_t > named_index_lookup_t
any_regular_t array_function_lookup_signature_t(name_t, const array_t &)
any_regular_t named_index_lookup_signature_t(const any_regular_t &, name_t index)
any_regular_t variable_lookup_signature_t(name_t)
void set_named_index_lookup(const named_index_lookup_t &)
void set_array_function_lookup(const array_function_lookup_t &)
void evaluate(const expression_t &expression)
closed_hash_map< name_t, any_regular_t > dictionary_t
const char * type_name(const std::type_info &type)
Returns a simple name for the core types used by the virtual machine.
auto cast(adobe::any_regular_t &x) -> decltype(x.cast< T >())
Does a runtime cast on an any_regular_t with better error reporting.
std::vector< any_regular_t > array_t
Definition array_fwd.hpp:23
typename promote< T >::type promote_t
A character string class for immutable strings.
Definition name.hpp:220