00001 /* 00002 File : gadget_w_string.h 00003 Date : 19-Sep-02 00004 Description : Class to represent a toolbox gadget that has a string value. 00005 00006 Copyright © 1995-2002 Alexander Thoukydides 00007 00008 This program is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU General Public License 00010 as published by the Free Software Foundation; either version 2 00011 of the License, or (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 00021 */ 00022 00023 // Only include header file once 00024 #ifndef gadget_w_string_h 00025 #define gadget_w_string_h 00026 00027 // Include cpplib header files 00028 #include "string.h" 00029 00030 // A class to represent a gadget with a string value 00031 class gadget_w_string 00032 { 00033 public: 00034 00035 /* 00036 Parameters : value - The text string to set. 00037 Returns : void 00038 Description : Set the value of this gadget. 00039 */ 00040 void set_value(const char *value); 00041 00042 /* 00043 Parameters : value - The text string to set. 00044 Returns : void 00045 Description : Set the value of this gadget. 00046 */ 00047 void set_value(const string &value); 00048 00049 /* 00050 Parameters : value - The text string to set. 00051 Returns : gadget_w_string - This object. 00052 Description : Set the value of this gadget. To reduce flicker the value 00053 is not updated unless it has changed. 00054 */ 00055 gadget_w_string &operator=(const char *value); 00056 00057 /* 00058 Parameters : value - The text string to set. 00059 Returns : gadget_w_string - This object. 00060 Description : Set the value of this gadget. To reduce flicker the value 00061 is not updated unless it has changed. 00062 */ 00063 gadget_w_string &operator=(const string &value); 00064 00065 /* 00066 Parameters : void 00067 Returns : size_t - The size of buffer required to hold the value. 00068 Description : Get the size of the buffer required to read the value. 00069 */ 00070 size_t get_value_size() const; 00071 00072 /* 00073 Parameters : value - Pointer to buffer to hold the value. 00074 size - The size of the buffer. 00075 Returns : size_t - Number of bytes written to the buffer. 00076 Description : Get the value of this gadget. 00077 */ 00078 size_t get_value(char *value, size_t size) const; 00079 00080 /* 00081 Parameters : void 00082 Returns : string - The value. 00083 Description : Get the value of this gadget. 00084 */ 00085 string get_value() const; 00086 00087 /* 00088 Parameters : void 00089 Returns : string - The value. 00090 Description : Get the value of this gadget. 00091 */ 00092 string operator()() const; 00093 00094 protected: 00095 00096 /* 00097 Parameters : value - The text string to set. 00098 Returns : void 00099 Description : Gadget specific function to set the value. 00100 */ 00101 virtual void _set_value(const char *value) = 0; 00102 00103 /* 00104 Parameters : value - Pointer to buffer to hold the value, or NULL 00105 to read the size of buffer required. 00106 size - The size of the buffer. 00107 Returns : size_t - Number of bytes written to the buffer, or 00108 the buffer size required if NULL passed. 00109 Description : Gadget specific function to get the value or the buffer 00110 size required. 00111 */ 00112 virtual size_t _get_value(char *value, size_t size) const = 0; 00113 }; 00114 00115 /* 00116 Parameters : value - The text string to set. 00117 Returns : void 00118 Description : Set the value of this gadget. 00119 */ 00120 inline void gadget_w_string::set_value(const char *value) 00121 { 00122 _set_value(value); 00123 } 00124 00125 /* 00126 Parameters : value - The text string to set. 00127 Returns : void 00128 Description : Set the value of this gadget. 00129 */ 00130 inline void gadget_w_string::set_value(const string &value) 00131 { 00132 _set_value(value.c_str()); 00133 } 00134 00135 /* 00136 Parameters : value - The text string to set. 00137 Returns : gadget_w_string - This object. 00138 Description : Set the value of this gadget. To reduce flicker the value 00139 is not updated unless it has changed. 00140 */ 00141 inline gadget_w_string &gadget_w_string::operator=(const char *value) 00142 { 00143 if (string(value) != get_value()) _set_value(value); 00144 return *this; 00145 } 00146 00147 /* 00148 Parameters : value - The text string to set. 00149 Returns : gadget_w_string - This object. 00150 Description : Set the value of this gadget. To reduce flicker the value 00151 is not updated unless it has changed. 00152 */ 00153 inline gadget_w_string &gadget_w_string::operator=(const string &value) 00154 { 00155 if (value != get_value()) _set_value(value.c_str()); 00156 return *this; 00157 } 00158 00159 /* 00160 Parameters : void 00161 Returns : size_t - The size of buffer required to hold the value. 00162 Description : Get the size of the buffer required to read the value. 00163 */ 00164 inline size_t gadget_w_string::get_value_size() const 00165 { 00166 return _get_value(NULL, 0); 00167 } 00168 00169 /* 00170 Parameters : value - Pointer to buffer to hold the value. 00171 size - The size of the buffer. 00172 Returns : size_t - Number of bytes written to the buffer. 00173 Description : Get the value of this gadget. 00174 */ 00175 inline size_t gadget_w_string::get_value(char *value, size_t size) const 00176 { 00177 return _get_value(value, size); 00178 } 00179 00180 /* 00181 Parameters : void 00182 Returns : string - The value. 00183 Description : Get the value of this gadget. 00184 */ 00185 inline string gadget_w_string::operator()() const 00186 { 00187 return get_value(); 00188 } 00189 00190 #endif
1.3.3