00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef __COMPOUND_HPP
00014 #define __COMPOUND_HPP
00015 #include <basix/vector.hpp>
00016 #include <basix/symbol.hpp>
00017
00019
00020 namespace mmx {
00021
00022
00023
00024
00025
00026 class compound {
00027 MMX_ALLOCATORS
00028 vector<generic> v;
00029 symbol<vector<generic> > sym;
00030 public:
00031 inline vector<generic> operator * () const { return v; }
00032 inline friend nat N (const compound& v) { return N(v.v); }
00033 inline friend vector<generic> as_vector (const compound& v) { return v.v; }
00034 inline friend symbol<vector<generic> > as_symbol (const compound& v) {
00035 return v.sym; }
00036 inline compound (): v (), sym (v) {}
00037 inline compound (const vector<generic>& v2): v (v2), sym (v) {}
00038 inline compound (const compound& c): v (c.v), sym (c.sym) {}
00039 inline compound (const symbol<vector<generic> >& s2): v (*s2), sym (s2) {}
00040 inline generic operator [] (nat i) const { return v[i]; }
00041 };
00042
00043 inline nat hash (const compound& c) {
00044 return hash (as_symbol (c)); }
00045 inline nat exact_hash (const compound& c) {
00046 return exact_hash (as_symbol (c)); }
00047 inline nat hard_hash (const compound& c) {
00048 return hard_hash (as_vector (c)); }
00049 inline bool operator == (const compound& c1, const compound& c2) {
00050 return as_symbol (c1) == as_symbol (c2); }
00051 inline bool operator != (const compound& c1, const compound& c2) {
00052 return as_symbol (c1) != as_symbol (c2); }
00053 inline bool exact_eq (const compound& c1, const compound& c2) {
00054 return exact_eq (as_symbol (c1), as_symbol (c2)); }
00055 inline bool exact_neq (const compound& c1, const compound& c2) {
00056 return exact_neq (as_symbol (c1), as_symbol (c2)); }
00057 inline bool hard_eq (const compound& c1, const compound& c2) {
00058 return hard_eq (as_vector (c1), as_vector (c2)); }
00059 inline bool hard_neq (const compound& c1, const compound& c2) {
00060 return hard_neq (as_vector (c1), as_vector (c2)); }
00061
00062 vector<generic> compound_to_vector (const generic& g);
00063 generic vector_to_compound (const vector<generic>& v);
00064 syntactic flatten (const compound& c);
00065
00066 template<>
00067 struct binary_helper<compound>: public void_binary_helper<compound> {
00068 static inline string short_type_name () { return "Co"; }
00069 static inline generic full_type_name () { return "Compound"; }
00070 static inline generic disassemble (const compound& c) {
00071 return binary_disassemble<vector<generic> > (*c); }
00072 static inline compound assemble (const generic& x) {
00073 return compound (binary_assemble<vector<generic> > (x)); }
00074 static inline void write (const port& out, const compound& c) {
00075 binary_write<vector<generic> > (out, *c); }
00076 static inline compound read (const port& in) {
00077 return compound (binary_read<vector<generic> > (in)); }
00078 };
00079
00080 STMPL
00081 struct inspector<compound> {
00082 static inline nat length (const compound& v) {
00083 return N (as_vector (v)); }
00084 static inline generic access (const compound& v, nat i) {
00085 VERIFY (i < N (as_vector (v)), "out of range");
00086 return read (as_vector (v), i); }
00087 };
00088
00089 }
00090 #endif // __COMPOUND_HPP