Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members

gadget_w_text.h

Go to the documentation of this file.
00001 /*
00002     File        : gadget_w_text.h
00003     Date        : 19-Sep-02
00004     Description : Class to represent a toolbox gadget that has an associated
00005                   text string.
00006 
00007     Copyright © 1995-2002 Alexander Thoukydides
00008 
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License
00011     as published by the Free Software Foundation; either version 2
00012     of the License, or (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017     GNU General Public License for more details.
00018 
00019     You should have received a copy of the GNU General Public License
00020     along with this program; if not, write to the Free Software
00021     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00022 */
00023 
00024 // Only include header file once
00025 #ifndef gadget_w_text_h
00026 #define gadget_w_text_h
00027 
00028 // Include cpplib header files
00029 #include "string.h"
00030 
00031 // A class to represent a gadget with a text string
00032 class gadget_w_text
00033 {
00034 public:
00035 
00036     /*
00037         Parameters  : text  - The text string to set.
00038         Returns     : void
00039         Description : Set the text of this gadget.
00040     */
00041     void set_text(const char *text);
00042 
00043     /*
00044         Parameters  : text  - The text string to set.
00045         Returns     : void
00046         Description : Set the text of this gadget.
00047     */
00048     void set_text(const string &text);
00049 
00050     /*
00051         Parameters  : void
00052         Returns     : size_t    - The size of buffer required to hold the text.
00053         Description : Get the size of the buffer required to read the text.
00054     */
00055     size_t get_text_size() const;
00056 
00057     /*
00058         Parameters  : text      - Pointer to buffer to hold the text.
00059                       size      - The size of the buffer.
00060         Returns     : size_t    - Number of bytes written to the buffer.
00061         Description : Get the text of this gadget.
00062     */
00063     size_t get_text(char *text, size_t size) const;
00064 
00065     /*
00066         Parameters  : void
00067         Returns     : string    - The text.
00068         Description : Get the text of this gadget.
00069     */
00070     string get_text() const;
00071 
00072 protected:
00073 
00074     /*
00075         Parameters  : text  - The text string to set.
00076         Returns     : void
00077         Description : Gadget specific function to set the text.
00078     */
00079     virtual void _set_text(const char *text) = 0;
00080 
00081     /*
00082         Parameters  : text      - Pointer to buffer to hold the text, or NULL
00083                                   to read the size of buffer required.
00084                       size      - The size of the buffer.
00085         Returns     : size_t    - Number of bytes written to the buffer, or
00086                                   the buffer size required if NULL passed.
00087         Description : Gadget specific function to get the text or the buffer
00088                       size required.
00089     */
00090     virtual size_t _get_text(char *text, size_t size) const = 0;
00091 };
00092 
00093 /*
00094     Parameters  : text  - The text string to set.
00095     Returns     : void
00096     Description : Set the text of this gadget.
00097 */
00098 inline void gadget_w_text::set_text(const char *text)
00099 {
00100     _set_text(text);
00101 }
00102 
00103 /*
00104     Parameters  : text  - The text string to set.
00105     Returns     : void
00106     Description : Set the text of this gadget.
00107 */
00108 inline void gadget_w_text::set_text(const string &text)
00109 {
00110     _set_text(text.c_str());
00111 }
00112 
00113 /*
00114     Parameters  : void
00115     Returns     : size_t    - The size of buffer required to hold the text.
00116     Description : Get the size of the buffer required to read the text.
00117 */
00118 inline size_t gadget_w_text::get_text_size() const
00119 {
00120     return _get_text(NULL, 0);
00121 }
00122 
00123 /*
00124     Parameters  : text      - Pointer to buffer to hold the text.
00125                   size      - The size of the buffer.
00126     Returns     : size_t    - Number of bytes written to the buffer.
00127     Description : Get the text of this gadget.
00128 */
00129 inline size_t gadget_w_text::get_text(char *text, size_t size) const
00130 {
00131     return _get_text(text, size);
00132 }
00133 
00134 #endif

Generated on Sun Jan 26 10:18:43 2025 for NBLib by doxygen 1.3.3