00001 /* 00002 FALCON - The Falcon Programming Language. 00003 FILE: autocstring.h 00004 00005 SUtility to convert falcon items and strings into C Strings. 00006 ------------------------------------------------------------------- 00007 Author: Giancarlo Niccolai 00008 Begin: sab ago 4 2007 00009 00010 ------------------------------------------------------------------- 00011 (C) Copyright 2004: the FALCON developers (see list in AUTHORS file) 00012 00013 See LICENSE file for licensing details. 00014 */ 00015 00021 #ifndef flc_autocstring_H 00022 #define flc_autocstring_H 00023 00024 #include <falcon/setup.h> 00025 #include <falcon/types.h> 00026 #include <falcon/string.h> 00027 00028 namespace Falcon { 00029 00030 class Item; 00031 class VMachine; 00032 00033 00113 class FALCON_DYN_CLASS AutoCString 00114 { 00115 typedef enum { 00116 AutoCString_BUF_SPACE = 128 00117 } e_consts; 00118 00119 char *m_pData; 00120 uint32 m_len; 00121 char m_buffer[ AutoCString_BUF_SPACE ]; 00122 void init_vm_and_format( VMachine *vm, const Item &itm, const String &fmt ); 00123 00124 public: 00125 AutoCString( const Falcon::String &str ); 00126 00127 AutoCString( const Falcon::Item &itm ); 00128 00129 AutoCString( Falcon::VMachine *vm, const Falcon::Item &itm ): 00130 m_pData( 0 ) 00131 { 00132 init_vm_and_format( vm, itm, "" ); 00133 } 00134 00135 AutoCString( Falcon::VMachine *vm, const Falcon::Item &itm, const Falcon::String &fmt ): 00136 m_pData( 0 ) 00137 { 00138 init_vm_and_format( vm, itm, fmt ); 00139 } 00140 00141 ~AutoCString(); 00142 00143 const char *c_str() const { return m_pData; } 00144 operator const char *() const { return m_pData; } 00145 bool isValid() const { return m_pData[0] != (char) 255; } 00146 00153 uint32 length() const { return m_len; } 00154 }; 00155 00156 } 00157 00158 #endif 00159 00160 /* end of autocstring.h */