Rice  1.5.2
 All Classes Files Functions Variables Typedefs Friends Pages
Struct.hpp
1 #ifndef Rice__ruby_struct__hpp_
2 #define Ruplu__ruby_struct__hpp_
3 
4 #include "Array.hpp"
5 #include "Hash.hpp"
6 #include "Module.hpp"
7 #include "Class.hpp"
8 #include "Builtin_Object.hpp"
9 #include "Address_Registration_Guard.hpp"
10 
11 namespace Rice
12 {
13  class Struct;
14 
16 Struct define_struct();
17 
19 
57 class Struct
58  : public Module_impl<Class, Struct>
59 {
60 public:
62  Struct();
63 
65  Struct(Struct const & s);
66 
68  virtual ~Struct();
69 
71 
77 
79 
84  Module module,
85  Identifier name);
86 
88 
94  size_t offset_of(Identifier name) const;
95 
96  class Instance;
97  friend class Instance;
98  friend Struct Rice::define_struct();
99 
101 
104  Instance new_instance(Array args = Array()) const;
105 
107  void swap(Struct & other);
108 
109  Array members() const { return members_; }
110 
111 private:
112  Array members_;
113  Address_Registration_Guard members_guard_;
114 
115  Hash member_offset_;
116  Address_Registration_Guard member_offset_guard_;
117 };
118 
119 
123  : public Builtin_Object<RStruct, T_STRUCT>
124 {
125 public:
127 
130  Instance(
131  Struct const & type,
132  Array args = Array());
133 
135 
138  Instance(
139  Struct const & type,
140  Object s);
141 
143 
147  template<typename T>
148  Object operator[](T index);
149 
151  void swap(Instance & other);
152 
153 private:
154  Struct type_;
155 };
156 
157 } // namespace Rice
158 
159 #include "Struct.ipp"
160 
161 #endif // Rice__ruby_struct__hpp_
162 
Definition: Module_impl.hpp:47
A wrapper for the ID type.
Definition: Identifier.hpp:15
void swap(Struct &other)
Swap with another Struct.
virtual ~Struct()
Destructor.
Struct & initialize(Module module, Identifier name)
Initialize the Struct class.
A smartpointer-like wrapper for Ruby builtin objects.
Definition: Builtin_Object_defn.hpp:18
Instance new_instance(Array args=Array()) const
Create a new instance of the Struct.
A wrapper for creating Struct classes.
Definition: Struct.hpp:57
String name() const
Return the name of the module.
Definition: Hash.hpp:24
Object operator[](T index)
Get a member, given its offset.
A helper for defining a Module and its methods.
Definition: Module_defn.hpp:23
A guard to register a given address with the GC.
Definition: Address_Registration_Guard_defn.hpp:29
Definition: Struct.hpp:122
The base class for all Objects.
Definition: Object_defn.hpp:23
size_t offset_of(Identifier name) const
Get the offset of a member in the Struct.
void swap(Instance &other)
Swap with another Struct::Instance.
A wrapper for the ruby Array class.
Definition: Array.hpp:22
Instance(Struct const &type, Array args=Array())
Create a new Instance of a Struct.
Struct & define_member(Identifier name)
Define a new Struct member.
Struct()
Create a new Struct.