Back to index

texmacs  1.0.7.15
string.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : string.hpp
00004 * DESCRIPTION: Fixed size strings with reference counting and
00005 *              pointer copying. Zero-characters are allowed in strings.
00006 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00007 *******************************************************************************
00008 * This software falls under the GNU general public license version 3 or later.
00009 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00010 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00011 ******************************************************************************/
00012 
00013 #ifndef STRING_H
00014 #define STRING_H
00015 #include "basic.hpp"
00016 
00017 class string;
00018 class string_rep: concrete_struct {
00019   int n;
00020   char* a;
00021 
00022 public:
00023   inline string_rep (): n(0), a(NULL) {}
00024          string_rep (int n);
00025   inline ~string_rep () { if (n!=0) tm_delete_array (a); }
00026   void resize (int n);
00027 
00028   friend class string;
00029   friend inline int N (string a);
00030 };
00031 
00032 class string {
00033   CONCRETE(string);
00034   inline string (): rep (tm_new<string_rep> ()) {}
00035   inline string (int n): rep (tm_new<string_rep> (n)) {}
00036   string (char c);
00037   string (const char *s);
00038   string (const char *s, int n);
00039   inline char& operator [] (int i) { return rep->a[i]; }
00040   bool operator == (const char* s);
00041   bool operator != (const char* s);
00042   bool operator == (string s);
00043   bool operator != (string s);
00044   string operator () (int start, int end);
00045 };
00046 CONCRETE_CODE(string);
00047 
00048 extern inline int N (string a) { return a->n; }
00049 string   copy (string a);
00050 tm_ostream& operator << (tm_ostream& out, string a);
00051 string&  operator << (string& a, char);
00052 string&  operator << (string& a, string b);
00053 string   operator * (const char* a, string b);
00054 string   operator * (string a, string b);
00055 string   operator * (string a, const char* b);
00056 bool     operator <= (string a, string b);
00057 int      hash (string s);
00058 
00059 bool   as_bool   (string s);
00060 int    as_int    (string s);
00061 double as_double (string s);
00062 char*  as_charp  (string s);
00063 string as_string_bool (bool f);
00064 string as_string (int i);
00065 string as_string (unsigned int i);
00066 string as_string (long int i);
00067 string as_string (unsigned long int i);
00068 string as_string (double x);
00069 string as_string (const char* s);
00070 bool   is_bool   (string s);
00071 bool   is_int    (string s);
00072 bool   is_double (string s);
00073 bool   is_charp  (string s);
00074 
00075 bool   is_quoted (string s);
00076 bool   is_id     (string s);
00077 
00078 void  set_info_handler (void (*) (string, string, int));
00079 void  set_wait_handler (void (*) (string, string, int));
00080 void  set_warning_handler (void (*) (string, string, int));
00081 void  set_error_handler (void (*) (string, string, int));
00082 void  system_info (string message, string argument= "", int level= 0);
00083 void  system_wait (string message, string argument= "", int level= 0);
00084 void  system_warning (string message, string argument= "", int level= 0);
00085 void  system_error (string message, string argument= "", int level= 0);
00086 
00087 #endif // defined STRING_H