replicode
structure_member.h
Go to the documentation of this file.
1 // structure_member.h
2 //
3 // Author: Eric Nivel
4 //
5 // BSD license:
6 // Copyright (c) 2010, Eric Nivel
7 // All rights reserved.
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are met:
10 //
11 // - Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // - Redistributions in binary form must reproduce the above copyright
14 // notice, this list of conditions and the following disclaimer in the
15 // documentation and/or other materials provided with the distribution.
16 // - Neither the name of Eric Nivel nor the
17 // names of their contributors may be used to endorse or promote products
18 // derived from this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
21 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
24 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #ifndef structure_member_h
32 #define structure_member_h
33 
34 #include <string>
35 
36 #include "r_code/image.h"
37 #include "r_code/atom.h"
38 
39 
40 using namespace r_code;
41 
42 namespace r_comp {
43 
44 class Class;
45 class Compiler;
46 class RepliStruct;
47 
48 typedef enum {
49  ANY = 0,
50  NUMBER = 1,
51  TIMESTAMP = 2,
52  SET = 3,
53  BOOLEAN = 4,
54  STRING = 5,
55  NODE_ID = 6,
56  DEVICE_ID = 7,
58  CLASS = 9
59 } ReturnType;
60 
61 typedef bool (Compiler::*_Read)(RepliStruct *, bool, const Class *, uint16_t, uint16_t &, bool); // reads from the stream and writes in an object.
62 
63 class Metadata;
65 public:
66  typedef enum {
67  I_CLASS = 0, // iterate using the class to enumerate elements.
68  I_EXPRESSION = 1, // iterate using the class in read_expression.
69  I_SET = 2, // iterate using the class in read_set.
70  I_DCLASS // iterate using read_class in read_set.
71  } Iteration;
72 private:
73  typedef enum {
74  R_ANY = 0,
75  R_NUMBER = 1,
76  R_TIMESTAMP = 2,
77  R_BOOLEAN = 3,
78  R_STRING = 4,
79  R_NODE = 5,
80  R_DEVICE = 6,
81  R_FUNCTION = 7,
82  R_EXPRESSION = 8,
83  R_SET = 9,
84  R_CLASS = 10
85  } ReadID; // used for serialization
88  std::string _class; // when r==read_set or read_expression, _class specifies the class of said set/expression if one is targeted in particular; otherwise _class=="".
89  Iteration iteration; // indicates how to use the _class to read the elements of the set: as an enumeration of types, as a class of expression, or as an enumeration of types to use for reading subsets.
90 public:
91  std::string name; // unused for anything but set/object/marker classes.
93  StructureMember(_Read r, // compiler's read function.
94  std::string m, // member's name.
95  std::string p = "", // class name of return type if r==Compiler::read_expression or name of the structure to enumerate elements if r==Compiler::read_set.
96  Iteration i = I_CLASS); // specified only if r==Compiler::read_set.
97  Class *get_class(Metadata *metadata) const;
98  ReturnType get_return_type() const;
99  bool used_as_expression() const;
100  Iteration getIteration() const;
101  _Read read() const;
102 
103  void write(uintptr_t *storage) const;
104  void read(uintptr_t *storage);
105  size_t get_size();
106 };
107 }
108 
109 
110 #endif
Definition: structure_member.h:56
ReturnType
Definition: structure_member.h:48
Definition: class.h:41
Iteration iteration
Definition: structure_member.h:89
Definition: structure_member.h:51
Definition: atom.cpp:36
Definition: compiler.h:47
Definition: structure_member.h:58
Definition: segments.h:59
Definition: structure_member.h:57
std::string name
Definition: structure_member.h:91
dll_export r_comp::Compiler Compiler
Definition: init.cpp:66
ReturnType type
Definition: structure_member.h:87
Definition: structure_member.h:49
Definition: structure_member.h:53
Definition: structure_member.h:55
bool(Compiler::* _Read)(RepliStruct *, bool, const Class *, uint16_t, uint16_t &, bool)
Definition: structure_member.h:61
std::string _class
Definition: structure_member.h:88
Definition: structure_member.h:52
Definition: structure_member.h:64
Iteration
Definition: structure_member.h:66
Definition: image.h:41
Definition: structure_member.h:54
_Read _read
Definition: structure_member.h:86
Definition: structure_member.h:50
Definition: replistruct.h:14