00001 00002 /****************************************************************************** 00003 * MODULE : literal.cpp 00004 * DESCRIPTION: Literal expressions (the leafs of a plain generic) 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 #include <basix/literal.hpp> 00014 namespace mmx { 00015 00016 /****************************************************************************** 00017 * General conversions 00018 ******************************************************************************/ 00019 00020 syntactic 00021 flatten (const literal& s) { 00022 return as_syntactic (as<generic> (s)); 00023 } 00024 00025 string 00026 literal_to_string (const generic& g) { 00027 return as_string (as<literal> (g)); 00028 } 00029 00030 generic::generic (): 00031 rep (new generic_concrete_rep<literal> (literal (""))) {} 00032 generic::generic (const char* s): 00033 rep (new generic_concrete_rep<literal> (literal (s))) {} 00034 generic::generic (const string& s): 00035 rep (new generic_concrete_rep<literal> (literal (s))) {} 00036 00037 generic lit (const char* s) { 00038 return new generic_concrete_rep<literal> (literal (s)); } 00039 generic lit (const string& s) { 00040 return new generic_concrete_rep<literal> (literal (s)); } 00041 00042 /****************************************************************************** 00043 * Special conversions 00044 ******************************************************************************/ 00045 00046 bool 00047 is_literal_string (const literal& l) { 00048 return is_quoted (*l); 00049 } 00050 00051 bool 00052 is_literal_int (const literal& l) { 00053 return is_numeric_string<int> (*l); 00054 } 00055 00056 bool 00057 is_literal_double (const literal& l) { 00058 return is_numeric_string<double> (*l); 00059 } 00060 00061 string 00062 as_literal_string (const literal& l) { 00063 return unquote (*l); 00064 } 00065 00066 int 00067 as_literal_int (const literal& l) { 00068 return string_as_numeric<int> (*l); 00069 } 00070 00071 double 00072 as_literal_double (const literal& l) { 00073 return string_as_numeric<double> (*l); 00074 } 00075 00076 } // namespace mmx