basix_doc 0.1
/Users/mourrain/Devel/mmx/basix/include/basix/literal.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : literal.hpp
00004 * DESCRIPTION: Atomic literals
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 __LITERAL_HPP
00014 #define __LITERAL_HPP
00015 #include <basix/port.hpp>
00016 #include <basix/symbol.hpp>
00017 
00019 
00020 namespace mmx {
00021 
00022 /******************************************************************************
00023 * Literals
00024 ******************************************************************************/
00025 
00026 class literal {
00027 MMX_ALLOCATORS
00028   string s;
00029   symbol<string> sym;
00030 public:
00031   inline string operator * () const { return s; }
00032   inline friend string as_string (const literal& l) { return l.s; }
00033   inline friend symbol<string> as_symbol (const literal& s) { return s.sym; }
00034   inline literal (): s (""), sym (s) {}
00035   inline literal (const char *s2): s (string (s2)), sym (s) {}
00036   inline literal (const string& s2): s (s2), sym (s) {}
00037   inline literal (const literal& l): s (l.s), sym (l.sym) {}
00038   inline literal (const symbol<string>& sym2): s (*sym2), sym (sym2) {}
00039 };
00040 
00041 inline nat hash (const literal& c) { return hash (as_symbol (c)); }
00042 inline nat exact_hash (const literal& c) { return exact_hash (as_symbol (c)); }
00043 inline nat hard_hash (const literal& c) { return hard_hash (as_string (c)); }
00044 inline bool operator == (const literal& c1, const literal& c2) {
00045   return as_symbol (c1) == as_symbol (c2); }
00046 inline bool operator != (const literal& c1, const literal& c2) {
00047   return as_symbol (c1) != as_symbol (c2); }
00048 inline bool exact_eq (const literal& c1, const literal& c2) {
00049   return exact_eq (as_symbol (c1), as_symbol (c2)); }
00050 inline bool exact_neq (const literal& c1, const literal& c2) {
00051   return exact_neq (as_symbol (c1), as_symbol (c2)); }
00052 inline bool hard_eq (const literal& c1, const literal& c2) {
00053   return hard_eq (as_string (c1), as_string (c2)); }
00054 inline bool hard_neq (const literal& c1, const literal& c2) {
00055   return hard_neq (as_string (c1), as_string (c2)); }
00056 
00057 template<typename C> C
00058 make_literal (const literal& lit) {
00059   return C (as_string (lit));
00060 }
00061 
00062 string literal_to_string (const generic& g);
00063 syntactic flatten (const literal& s);
00064 
00065 template<>
00066 struct binary_helper<literal>: public void_binary_helper<literal> {
00067   static inline string short_type_name () { return "L"; }
00068   static inline generic full_type_name () { return "Literal"; }
00069   static inline generic disassemble (const literal& x) {
00070     return as<generic> (*x); }
00071   static inline literal assemble (const generic& x) {
00072     return literal (as<string> (x)); }
00073   static inline void write (const port& out, const literal& l) {
00074     binary_write<string> (out, as_string (l)); }
00075   static inline literal read (const port& in) {
00076     return literal (binary_read<string> (in)); }
00077 };
00078 
00079 } // namespace mmx
00080 #endif // __LITERAL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines