basix_doc 0.1
/Users/mourrain/Devel/mmx/basix/include/basix/compound.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : compound.hpp
00004 * DESCRIPTION: Compound generic expressions
00005 * COPYRIGHT  : (C) 2005  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license and comes WITHOUT
00008 * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
00009 * If you don't have this file, write to the Free Software Foundation, Inc.,
00010 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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 * Compound expressions
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 vector<generic> as_vector (const compound& v) { return v.v; }
00033   inline friend symbol<vector<generic> > as_symbol (const compound& v) {
00034     return v.sym; }
00035   inline compound (): v (), sym (v) {}
00036   inline compound (const vector<generic>& v2): v (v2), sym (v) {}
00037   inline compound (const compound& c): v (c.v), sym (c.sym) {}
00038   inline compound (const symbol<vector<generic> >& s2): v (*s2), sym (s2) {}
00039 };
00040 
00041 inline nat hash (const compound& c) {
00042   return hash (as_symbol (c)); }
00043 inline nat exact_hash (const compound& c) {
00044   return exact_hash (as_symbol (c)); }
00045 inline nat hard_hash (const compound& c) {
00046   return hard_hash (as_vector (c)); }
00047 inline bool operator == (const compound& c1, const compound& c2) {
00048   return as_symbol (c1) == as_symbol (c2); }
00049 inline bool operator != (const compound& c1, const compound& c2) {
00050   return as_symbol (c1) != as_symbol (c2); }
00051 inline bool exact_eq (const compound& c1, const compound& c2) {
00052   return exact_eq (as_symbol (c1), as_symbol (c2)); }
00053 inline bool exact_neq (const compound& c1, const compound& c2) {
00054   return exact_neq (as_symbol (c1), as_symbol (c2)); }
00055 inline bool hard_eq (const compound& c1, const compound& c2) {
00056   return hard_eq (as_vector (c1), as_vector (c2)); }
00057 inline bool hard_neq (const compound& c1, const compound& c2) {
00058   return hard_neq (as_vector (c1), as_vector (c2)); }
00059 
00060 vector<generic> compound_to_vector (const generic& g);
00061 generic vector_to_compound (const vector<generic>& v);
00062 syntactic flatten (const compound& c);
00063 
00064 template<>
00065 struct binary_helper<compound>: public void_binary_helper<compound> {
00066   static inline string short_type_name () { return "Co"; }
00067   static inline generic full_type_name () { return "Compound"; }
00068   static inline generic disassemble (const compound& c) {
00069     return binary_disassemble<vector<generic> > (*c); }
00070   static inline compound assemble (const generic& x) {
00071     return compound (binary_assemble<vector<generic> > (x)); }
00072   static inline void write (const port& out, const compound& c) {
00073     binary_write<vector<generic> > (out, *c); }
00074   static inline compound read (const port& in) {
00075     return compound (binary_read<vector<generic> > (in)); }
00076 };
00077 
00078 STMPL
00079 struct inspector<compound> {
00080   static inline nat length (const compound& v) {
00081     return N (as_vector (v)); }
00082   static inline generic access (const compound& v, nat i) {
00083     VERIFY (i < N (as_vector (v)), "out of range");
00084     return read (as_vector (v), i); }
00085 };
00086 
00087 } // namespace mmx
00088 #endif // __COMPOUND_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines