type.h Source File - 0.9.5 |RTTR
type.h
Go to the documentation of this file.
1 /************************************************************************************
2 * *
3 * Copyright (c) 2014, 2015 - 2016 Axel Menzel <info@rttr.org> *
4 * *
5 * This file is part of RTTR (Run Time Type Reflection) *
6 * License: MIT License *
7 * *
8 * Permission is hereby granted, free of charge, to any person obtaining *
9 * a copy of this software and associated documentation files (the "Software"), *
10 * to deal in the Software without restriction, including without limitation *
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
12 * and/or sell copies of the Software, and to permit persons to whom the *
13 * Software is furnished to do so, subject to the following conditions: *
14 * *
15 * The above copyright notice and this permission notice shall be included in *
16 * all copies or substantial portions of the Software. *
17 * *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
24 * SOFTWARE. *
25 * *
26 *************************************************************************************/
27 
28 #ifndef RTTR_TYPE_H_
29 #define RTTR_TYPE_H_
30 
31 #include "rttr/detail/base/core_prerequisites.h"
32 
33 #include <type_traits>
34 #include <vector>
35 #include <string>
36 #include <memory>
37 #include <cstdint>
38 
39 namespace rttr
40 {
41 class variant;
42 class constructor;
43 class destructor;
44 class method;
45 class property;
46 class enumeration;
47 class type;
48 class instance;
49 class argument;
50 
51 template<typename Target_Type, typename Source_Type>
52 Target_Type rttr_cast(Source_Type object);
53 
54 namespace detail
55 {
56 struct derived_info;
57 struct base_class_info;
58 struct type_converter_base;
59 class type_register;
60 class type_database;
61 
62 template<typename T, typename Enable = void>
63 struct type_getter;
64 
65 static type get_invalid_type();
66 } // end namespace detail
67 
153 class RTTR_API type
154 {
155  public:
156  typedef uint16_t type_id;
157 
162  RTTR_INLINE type(const type& other);
163 
169  RTTR_INLINE type& operator=(const type& other);
170 
176  RTTR_INLINE bool operator<(const type& other) const;
177 
183  RTTR_INLINE bool operator>(const type& other) const;
184 
190  RTTR_INLINE bool operator>=(const type& other) const;
191 
197  RTTR_INLINE bool operator<=(const type& other) const;
198 
205  RTTR_INLINE bool operator==(const type& other) const;
206 
213  RTTR_INLINE bool operator!=(const type& other) const;
214 
223  RTTR_INLINE type_id get_id() const;
224 
232  std::string get_name() const;
233 
239  RTTR_INLINE bool is_valid() const;
240 
246  RTTR_INLINE explicit operator bool() const;
247 
256  type get_raw_type() const;
257 
278  type get_wrapped_type() const;
279 
285  template<typename T>
286  static type get();
287 
298  template<typename T>
299  static type get(T&& object);
300 
311  static type get_by_name(const char* name);
312 
320  static std::vector<type> get_types();
321 
327  std::size_t get_sizeof() const;
328 
334  bool is_class() const;
335 
341  bool is_enumeration() const;
342 
351  enumeration get_enumeration() const;
352 
370  bool is_wrapper() const;
371 
379  bool is_array() const;
380 
387  bool is_pointer() const;
388 
396  bool is_arithmetic() const;
397 
404  bool is_function_pointer() const;
405 
412  bool is_member_object_pointer() const;
413 
420  bool is_member_function_pointer() const;
421 
431  bool is_derived_from(const type& other) const;
432 
442  template<typename T>
443  bool is_derived_from() const;
444 
456  std::vector<type> get_base_classes() const;
457 
468  std::vector<type> get_derived_classes() const;
469 
473 
482  variant get_metadata(const variant& key) const;
483 
492  constructor get_constructor(const std::vector<type>& params = std::vector<type>() ) const;
493 
499  std::vector<constructor> get_constructors() const;
500 
509  variant create(std::vector<argument> args = std::vector<argument>()) const;
510 
519  destructor get_destructor() const;
520 
527  void destroy(variant& obj) const;
528 
529 
537  property get_property(const char* name) const;
538 
547  std::vector<property> get_properties() const;
548 
556  static property get_global_property(const char* name);
557 
567  static std::vector<property> get_global_properties();
568 
569 
577  variant get_property_value(const char* name, instance obj) const;
578 
584  static variant get_property_value(const char* name);
585 
593  bool set_property_value(const char* name, instance obj, argument arg) const;
594 
600  static bool set_property_value(const char* name, argument arg);
601 
602 
610  method get_method(const char* name) const;
611 
620  method get_method(const char* name, const std::vector<type>& params) const;
621 
630  std::vector<method> get_methods() const;
631 
639  static method get_global_method(const char* name);
640 
649  static method get_global_method(const char* name, const std::vector<type>& params);
650 
660  static std::vector<method> get_global_methods();
661 
662 
674  variant invoke(const char* name, instance obj, std::vector<argument> args) const;
675 
683  static variant invoke(const char* name, std::vector<argument> args);
684 
706  template<typename F>
707  static void register_converter_func(F func);
708 
731  template<typename T>
732  static void register_comparators();
733 
734  private:
735 
739  RTTR_INLINE type();
740 
746  RTTR_INLINE type(type_id id);
747 
756  static void* apply_offset(void* ptr, const type& source_type, const type& target_type);
757 
764  const detail::type_converter_base* get_type_converter(const type& target_type) const;
765 
772  std::size_t get_pointer_dimension() const;
773 
781  type get_raw_array_type() const;
782 
788  std::string get_full_name() const;
789 
795  static std::string normalize_orig_name(const char* name);
796 
801  static void init_globals();
802 
803 
807 
809  variant create_variant(const argument& data) const;
810 
811  friend class variant;
812  template<typename Target_Type, typename Source_Type>
813  friend Target_Type rttr_cast(Source_Type object);
814 
815  template<typename T, typename Enable>
816  friend struct detail::type_getter;
817  friend class instance;
818  friend class detail::type_register;
819  friend type detail::get_invalid_type();
820  friend class detail::type_database;
821 
822  private:
823  type_id m_id;
824  static const type_id m_invalid_id = 0;
825 };
826 
827 } // end namespace rttr
828 
829 #include "rttr/detail/type/type_impl.h"
830 
831 #endif // RTTR_TYPE_H_
Definition: access_levels.h:33
The type class holds the type information for any arbitrary object.
Definition: type.h:153
Target_Type rttr_cast(Source_Type object)
Casts the given object of type Source_Type to an object of type Target_Type.
The destructor class provides a destructor for registered types.
Definition: destructor.h:71
The instance class is used for forwarding the instance of an object to invoke a property or method...
Definition: instance.h:46
The enumeration class provides several meta information about an enum.
Definition: enumeration.h:101
The method class provides several meta information about a method and can be invoked.
Definition: method.h:116
uint16_t type_id
Definition: type.h:156
The argument class is used for forwarding arguments to properties or methods.
Definition: argument.h:51
The variant class allows to store data of any type and convert between these types transparently...
Definition: variant.h:192
The constructor class provides several meta information about a constructor and can be invoked...
Definition: constructor.h:85