00001
00006 #ifndef DIVINE_STATE_HH
00007 #define DIVINE_STATE_HH
00008
00009 #ifndef DOXYGEN_PROCESSING
00010 #include <iostream>
00011 #include "common/types.hh"
00012
00013 namespace divine
00014 {
00015 #endif //DOXYGEN_PROCESSING
00017
00020 struct state_t
00021 {
00022 state_t();
00023 char *ptr;
00024 std::size_t size;
00025 };
00026
00027
00029 bool operator< (const state_t& arg1, const state_t& arg2);
00031 bool operator> (const state_t& arg1, const state_t& arg2);
00033 bool operator!= (const state_t& arg1, const state_t& arg2);
00035 bool operator== (const state_t& arg1, const state_t& arg2);
00036
00038 state_t duplicate_state(state_t state);
00040 void clear_state(state_t);
00042 state_t new_state(const std::size_t size);
00044
00049 state_t new_state(char * const state_memory, const std::size_t size);
00051 void delete_state(state_t& state);
00052
00054 void realloc_state(state_t &state, size_t new_size);
00055
00056
00057 inline byte_t state_pos_to_byte(const state_t state,
00058 const std::size_t pos)
00059 { return ((byte_t *)(state.ptr))[pos]; }
00060
00061 inline sshort_int_t state_pos_to_int(const state_t state,
00062 const std::size_t pos)
00063 {
00064
00065
00066 return (*((sshort_int_t *)(&((byte_t *)(state.ptr))[pos])));
00067 }
00068
00069 inline ushort_int_t state_pos_to_uint(const state_t state,
00070 const std::size_t pos)
00071 {
00072
00073
00074 return (*((ushort_int_t *)(&((byte_t *)(state.ptr))[pos])));
00075 }
00076
00077 inline ulong_int_t state_pos_to_ulong_int(const state_t state,
00078 const std::size_t pos)
00079 { return (*((ulong_int_t *)(&((byte_t *)(state.ptr))[pos]))); }
00080
00081
00082
00083 inline void byte_to_state_pos(const state_t state, const std::size_t pos,
00084 const byte_t value)
00085 { ((byte_t *)(state.ptr))[pos] = value; }
00086
00087 inline void int_to_state_pos(const state_t state, const std::size_t pos,
00088 const sshort_int_t value)
00089 { (*((sshort_int_t *)(&((byte_t *)(state.ptr))[pos]))) = value; }
00090
00091 inline void uint_to_state_pos(const state_t state, const std::size_t pos,
00092 const ushort_int_t value)
00093 { (*((ushort_int_t *)(&((byte_t *)(state.ptr))[pos]))) = value; }
00094
00095 inline void ulong_int_to_state_pos(const state_t state,
00096 const std::size_t pos, const ulong_int_t value)
00097 { (*((ulong_int_t *)(&((byte_t *)(state.ptr))[pos]))) = value; }
00098
00099
00100
00101
00102
00103
00105
00112 template<class T>
00113 inline T state_pos_to(const state_t state, const std::size_t pos);
00114
00115 template <>
00116 inline byte_t state_pos_to<byte_t>(const state_t state,
00117 const std::size_t pos)
00118 { return state_pos_to_byte(state,pos); }
00119
00120 template <>
00121 inline sshort_int_t state_pos_to<sshort_int_t>(const state_t state,
00122 const std::size_t pos)
00123 { return state_pos_to_int(state,pos); }
00124
00125 template <>
00126 inline ushort_int_t state_pos_to<ushort_int_t>(const state_t state,
00127 const std::size_t pos)
00128 { return state_pos_to_uint(state,pos); }
00129
00130 template <>
00131 inline ulong_int_t state_pos_to<ulong_int_t>(const state_t state,
00132 const std::size_t pos)
00133 { return state_pos_to_ulong_int(state,pos); }
00134
00136
00143 template<class T> void set_to_state_pos(const state_t state,
00144 const std::size_t pos, const T value);
00145
00146 template <>
00147 inline void set_to_state_pos<byte_t>(const state_t state,
00148 const std::size_t pos, const byte_t value)
00149 { return byte_to_state_pos(state,pos,value); }
00150
00151 template <>
00152 inline void set_to_state_pos<sshort_int_t>(const state_t state,
00153 const std::size_t pos, const sshort_int_t value)
00154 { return int_to_state_pos(state,pos,value); }
00155
00156 template <>
00157 inline void set_to_state_pos<ushort_int_t>(const state_t state,
00158 const std::size_t pos, const ushort_int_t value)
00159 { return uint_to_state_pos(state,pos,value); }
00160
00161 template <>
00162 inline void set_to_state_pos<ulong_int_t>(const state_t state,
00163 const std::size_t pos, const ulong_int_t value)
00164 { return ulong_int_to_state_pos(state,pos,value); }
00165
00166
00167 #ifndef DOXYGEN_PROCESSING
00168 }
00169 #endif //DOXYGEN_PROCESSING
00170
00171 #endif