basix_doc 0.1
|
00001 00002 /****************************************************************************** 00003 * MODULE : document.hpp 00004 * DESCRIPTION: Expressions for (TeXmacs) documents with special markup 00005 * COPYRIGHT : (C) 2009 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 __DOCUMENT_HPP 00014 #define __DOCUMENT_HPP 00015 #include <basix/syntactic.hpp> 00016 #include <basix/literal.hpp> 00017 #include <basix/vector.hpp> 00018 00020 00021 namespace mmx { 00022 00023 /****************************************************************************** 00024 * The document wrapper type 00025 ******************************************************************************/ 00026 00027 class document { 00028 MMX_ALLOCATORS 00029 protected: 00030 generic rep; 00031 inline document (const generic& g): rep (g) {} 00032 public: 00033 inline document (): rep () {} 00034 document (const char* s); 00035 document (const string& s); 00036 inline generic operator * () const { return rep; } 00037 friend document as_document (const generic& g); 00038 inline friend nat N (const document& g) { return N (g.rep); } 00039 inline document operator [] (nat i) const { return document (rep[i]); } 00040 }; 00041 00042 /****************************************************************************** 00043 * Basic routines 00044 ******************************************************************************/ 00045 00046 inline generic as_generic (const document& g) { return *g; } 00047 inline document as_document (const generic& g) { return document (g); } 00048 inline nat hash (const document& c) { return hash (*c); } 00049 inline nat exact_hash (const document& c) { return exact_hash (*c); } 00050 inline nat hard_hash (const document& c) { return hard_hash (*c); } 00051 inline bool operator == (const document& c1, const document& c2) { 00052 return (*c1) == (*c2); } 00053 inline bool operator != (const document& c1, const document& c2) { 00054 return (*c1) != (*c2); } 00055 inline bool exact_eq (const document& c1, const document& c2) { 00056 return exact_eq (*c1, *c2); } 00057 inline bool exact_neq (const document& c1, const document& c2) { 00058 return exact_neq (*c1, *c2); } 00059 inline bool hard_eq (const document& c1, const document& c2) { 00060 return hard_eq (*c1, *c2); } 00061 inline bool hard_neq (const document& c1, const document& c2) { 00062 return hard_neq (*c1, *c2); } 00063 00064 /****************************************************************************** 00065 * Input/output 00066 ******************************************************************************/ 00067 00068 inline syntactic flatten (const document& d) { 00069 return as_syntactic (gen ("$text", as_generic (d))); } 00070 00071 template<> 00072 struct binary_helper<document>: public void_binary_helper<document> { 00073 static inline string short_type_name () { return "Doc"; } 00074 static inline generic full_type_name () { return "Document"; } 00075 static inline generic disassemble (const document& x) { 00076 return *x; } 00077 static inline document assemble (const generic& x) { 00078 return as_document (x); } 00079 static inline void write (const port& out, const document& s) { 00080 binary_write<generic> (out, *s); } 00081 static inline document read (const port& in) { 00082 return as_document (binary_read<generic> (in)); } 00083 }; 00084 00085 /****************************************************************************** 00086 * Further routines 00087 ******************************************************************************/ 00088 00089 document make_text (const generic& x); 00090 document make_text (const document& x); 00091 document make_math (const generic& x); 00092 document make_math (const document& x); 00093 document make_row (const vector<document>& v); 00094 document make_inline (const vector<document>& v); 00095 document make_block (const vector<document>& v); 00096 document make_texmacs (const string& x, const vector<document>& v); 00097 document make_texmacs (const literal& x, const vector<document>& v); 00098 00099 } // namespace mmx 00100 #endif // __DOCUMENT_HPP