v8toolkit  0.0.1
Utility library for embedding V8 Javascript engine in a c++ program
sample.cpp
Go to the documentation of this file.
1 #include "class_parser.h"
2 
3 
4 #include <functional>
5 #include "sample2.h"
6 
7 
8 class A : public v8toolkit::WrappedClassBase {
9 public:
10  V8TOOLKIT_CUSTOM_EXTENSION static void custom_extension();
11  A(A * a = nullptr);
12  bool some_bool_func(bool, bool *, bool &);
13  V8TOOLKIT_USE_NAME(OtherA) A();
15 };
16 
17 class B : A {
18 public:
19  // this should be generated as a
20  using A::custom_extension;
21 };
22 
23 
24 
25 template<class T>
27 
28 
29 namespace v8 {
30  template<class> class Local;
31  class FunctionTemplate;
32 };
33 
34 
35 //
36 //int do_something(int i){return i;}
37 //
38 //char do_something(char c){return c;}
39 //
40 //class V8TOOLKIT_WRAPPED_CLASS AbstractClass {
41 //public:
42 // AbstractClass(){}
43 // virtual void pure_virtual_function() = 0;
44 //};
45 //
46 class HelperClass {
47 public:
48  using Callback = std::function<int(char)>;
49 };
50 
51 
52 
53 
56 public:
57  WrappedClass(int a, int b = 2, int c = 3, WrappedClass * wc_ptr = nullptr);
61  std::vector<std::string> vector_of_ints;
62  std::vector<WrappedClass *> vector_of_selfs;
63 
64  V8TOOLKIT_EXTEND_WRAPPER static void extend_wrapper();
65  V8TOOLKIT_CUSTOM_EXTENSION static void custom_extension();
66 
67  int simple_member_function(char const * some_string = "asdf");
68  static std::string simple_static_function(double some_double);
69 
70  void std_function_default_parameter(std::function<void()> some_function = std::function<void()>());
71 
72  enum class EnumClass{A, B, C, D};
73 
74  template<class A = int, int b = 4>
75  void templated_method();
76 
77  void after_templated_method();
78 
79 };
80 
82 public:
85  static void static_method_with_no_constructor_on_class(int, int=5, char const * = "five");
86  void method_with_no_constructor_on_class(int, int const & =5, char const * = "five", WrappedClassDerived const & s = {});
87 };
88 
91 
92 
93 namespace Test {
94  template<class = char> class V8TOOLKIT_WRAPPED_CLASS MyTemplate;
95  template<class T> class MyTemplate<vector<T>> {};
96 }
97 
98 
99 
100 using asdf = int;
101 
102 namespace v8toolkit {
103 
104  template<
105  class Base,
106  class Child,
107  class ExternalTypeList = TypeList<>,
108  template<class, class...> class ParentType = FlexibleParent,
110  class CppFactory;
111 
112 
113  template<class Base, class Child, class... ExternalConstructorParams, template<class, class...> class ParentType, class FactoryBase>
114  class CppFactory<Base, Child, TypeList<ExternalConstructorParams...>, ParentType, FactoryBase> :
115  public ParentType<Base, TypeList<ExternalConstructorParams...>, FactoryBase> {
116  };
117 
118 
119 
120 }
121 
122 
123 
124 
125 template<class T>
127 public:
129 
130  }
131 };
132 
133 
135 
136 
138 //V8TOOLKIT_IGNORE_BASE_TYPE(MyTemplate<int>)
140 Foo : public FooParent, public Test::MyTemplate<vector<int>> {
141  struct NestedFooStruct{};
142 
143 
144  void foo_method(int*, int){}
145 
146 
147  double a;
148 public:
149  using Using=int;
150  using Using2 = Using;
151  V8TOOLKIT_BIDIRECTIONAL_CONSTRUCTOR Foo(int, char, short &&);
152 
154 
155  Test::MyTemplate<vector<int>> my_template_int;
156  Test::MyTemplate<vector<char>> my_template_char;
157 
160 
161  std::vector<int> returns_vector_of_ints();
162  std::map<string, int> returns_map_of_string_to_int();
163 
164 
165  const asdf const_typedef_to_int = 1;
166 
167 
168  template<class T2>
169  const T2& templated_function(const T2 & t){return t;};
170 
171 
172  V8TOOLKIT_SKIP Foo(int, char*); // skip this constructor, otherwise name error
173 
174  V8TOOLKIT_USE_NAME(FooInt) Foo(int); // This constructor gets different JS name - FooInt
175  V8TOOLKIT_SKIP void foo_explicitly_skipped();
176  virtual void fooparent_purevirtual_tobeoverridden();
177  virtual char const_virtual(int) const;
178 
179 
180  /**
181  * description
182  * @param a something -- missing a named parameter shouldn't cause the plugin to crash
183  */
184  void broken_comment(int);
185 
186  /**
187  * Test comment for foo_int_method
188  * @param a some string
189  * @param b some character
190  * @return some made up number
191  */
192  int foo_int_method(char* a, char b = 'a'){return 4;}
193  virtual void fooparent_virtual_tobeoverridden();
194  static int foo_static_method(const int *){return 8;}
195  const Using2 & using_return_type_test();
196  std::string take_and_return_string(string);
197  const std::string take_and_return_const_string(const string);
198  volatile const std::string & take_and_return_const_volatile_string(const volatile string *&);
199  const volatile map<const volatile int*&,const volatile Using2*&>*& map_test(const volatile std::map<const volatile Using2 *&,
200  const volatile std::set<const volatile int*&>*&>*&);
201 
202  void nested_foo_struct_test(const NestedFooStruct *&);
203  void call_helper_callback(HelperClass::Callback);
204 
205  HelperClass & do_foo_things(Foo & foo, HelperClass**&, volatile FooParent *&);
206 
207  float b;
209  std::unique_ptr<OnlyUsedInTemplate> unique_ptr_type_test;
210  virtual void templated_input_parameter_test(std::pair<OnlyUsedInTemplate, OnlyUsedInTemplate>);
211 
212  TemplatedClass<HelperClass, 5> test_method_with_templated_types(const TemplatedClass<const Using2*&, 8828>****&);
213 
215  static void wrapper_extension(v8toolkit::V8ClassWrapper<Foo> &);
216 
217  V8TOOLKIT_CUSTOM_EXTENSION
218  static void custom_extension(v8::Local<v8::FunctionTemplate> & function_template);
219 
220 
221  void same_name(int);
222 
223  V8TOOLKIT_USE_NAME(same_name_2)
224  void same_name(char*);
225 
226 
227  // just iterating through methods got foo_parent_virtual, foo_parent_pure_virtual
228  virtual void foo_parent_virtual(int, int, int) override;
229  virtual void foo_parent_pure_virtual(char, char, char, char) override;
230 
231  operator int();
232 
233 };
234 
235 
236 
237 
238 //
239 //class Foo;
240 //
241 //
242 //class V8TOOLKIT_WRAPPED_CLASS ConstructorTest {
243 // public:
244 // ~ConstructorTest();
245 //};
246 
247 //struct ALL FooStruct {
248 // int i;
249 // void foostruct_method(double, float){}
250 // static int static_method(const int *){return 8;}
251 //private:
252 // char j;
253 // char foostruct_char_method(const int &){return 'd';}
254 //};
255 
256 //
257 //class NOT_SPECIAL Foo2 { };
258 //
259 //struct Bar { };
260 //
261 //// this is the only one that should match
262 //struct SPECIAL Baz { };
263 //
264 
266 
267 
268 int main() {
269 
271 
272 
273  Foo f(5,5,5);
274 
275  f.templated_function(5);
276  f.templated_function<short>(5);
277  f.templated_function<long>(5);
278  f.templated_function<unsigned int>(5);
281 
282 
284  // DerivedFromWrappedClassBase<char>;
285 }
286 
Definition: sample.cpp:17
Definition: sample.cpp:137
UnwrappedClassThatIsUsed uctiu
Definition: sample.cpp:153
static int foo_static_method(const int *)
Definition: sample.cpp:194
#define V8TOOLKIT_READONLY
Definition: class_parser.h:40
int asdf
Definition: sample.cpp:100
int main()
Definition: sample.cpp:268
V8TOOLKIT_SKIP float c
Definition: sample.cpp:208
int foo_int_method(char *a, char b= 'a')
Definition: sample.cpp:192
::std::string string
Definition: gtest-port.h:1097
#define V8TOOLKIT_BIDIRECTIONAL_CLASS
Definition: class_parser.h:113
bool some_bool_func(bool, bool *, bool &)
#define V8TOOLKIT_EXTEND_WRAPPER
Definition: class_parser.h:46
#define V8TOOLKIT_USE_BASE_TYPE(name)
Definition: class_parser.h:95
#define V8TOOLKIT_BIDIRECTIONAL_CONSTRUCTOR
Definition: class_parser.h:118
Using Using2
Definition: sample.cpp:150
Definition: sample.cpp:29
Test::MyTemplate< vector< int > > my_template_int
Definition: sample.cpp:155
V8TOOLKIT_READONLY double double_member_readonly1
Definition: sample.cpp:59
class V8TOOLKIT_WRAPPED_CLASS MyTemplate
Definition: sample.cpp:94
float b
Definition: sample.cpp:207
A(A *a=nullptr)
double const double_member_readonly2
Definition: sample.cpp:60
std::vector< std::string > vector_of_ints
Definition: sample.cpp:61
std::vector< WrappedClass * > vector_of_selfs
Definition: sample.cpp:62
DerivedFromWrappedClassBase< short > derived_my_template_short
Definition: sample.cpp:158
DerivedFromWrappedClassBase< char * > derived_my_template_charp
Definition: sample.cpp:159
double double_member_readwrite2
Definition: sample.cpp:83
static V8TOOLKIT_CUSTOM_EXTENSION void custom_extension()
Definition: sample.cpp:93
#define V8TOOLKIT_SKIP
Definition: class_parser.h:33
Test::MyTemplate< vector< char > > my_template_char
Definition: sample.cpp:156
std::unique_ptr< OnlyUsedInTemplate > unique_ptr_type_test
Definition: sample.cpp:209
void function_in_templated_class(T t)
Definition: sample.cpp:128
Matcher< T > A()
int Using
Definition: sample.cpp:149
bool test_bool_type_string
Definition: sample.cpp:14
std::function< int(char)> Callback
Definition: sample.cpp:48
#define V8TOOLKIT_USE_NAME(name)
Definition: class_parser.h:65
V8TOOLKIT_USE_NAME(OtherA) A()
double double_member_readwrite
Definition: sample.cpp:58
const T2 & templated_function(const T2 &t)
Definition: sample.cpp:169
#define V8TOOLKIT_NAME_ALIAS
Definition: class_parser.h:58