Fix warnings on FreeBSD
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Basic / Buffer.hh
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*
24  * $XConsortium: Buffer.hh /main/3 1996/06/11 16:18:01 cde-hal $
25  *
26  * Copyright (c) 1992 HaL Computer Systems, Inc.  All rights reserved.
27  * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
28  * States.  Use of a copyright notice is precautionary only and does not
29  * imply publication or disclosure.
30  * 
31  * This software contains confidential information and trade secrets of HaL
32  * Computer Systems, Inc.  Use, disclosure, or reproduction is prohibited
33  * without the prior express written permission of HaL Computer Systems, Inc.
34  * 
35  *                         RESTRICTED RIGHTS LEGEND
36  * Use, duplication, or disclosure by the Government is subject to
37  * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
38  * Technical Data and Computer Software clause at DFARS 252.227-7013.
39  *                        HaL Computer Systems, Inc.
40  *                  1315 Dell Avenue, Campbell, CA  95008
41  * 
42  */
43
44
45 class Buffer
46 {
47 public:
48   Buffer (u_int initial_size = 1024);
49   ~Buffer();
50
51   void init (u_int initial_size = 1024);
52
53   char *point() const
54     { return (f_point); }
55   // Might want to add assert to make sure point is valid.  15:07 01/12/93 DJB 
56   void point (char *new_point)
57     { f_point = new_point; }
58   const char *data() const
59     { return (f_start); }
60   u_int length() const
61     { return (f_end_of_data - f_start); }
62   // Methods for saving buffer independent position inforation, since
63   // the buffer can be dynamically reallocated.  You must save offsets
64   // if you want to get an existing string out of the buffer after a
65   // write. 
66   int offset (const char *point) const
67     { return (point - f_start); }
68   char *position (int offset)
69     { return (f_start + offset); }
70   // Return the number of bytes of real data remaining after the point. 
71   u_int remaining() const
72     { return (f_end_of_data - f_point); }
73   void reset()
74     { f_point = f_start; }
75
76   void write (const int integer);
77
78   void write (const unsigned int integer)
79     { write ((int) (integer)); }
80
81   void write (const char *string);
82   void write (const char *bytes, u_int size, u_int length);
83
84   void read (int *integer);
85   void read (unsigned int *integer)
86     { read ((int *) integer); }
87   // Versions to get copy (space must exist!): 
88   u_int read (char *const string);
89   void read (char *const bytes, u_int size, u_int length);
90   // Versions to point into buffer memory:
91   u_int read (char **string);
92   void read (char **bytes, u_int size, u_int length);
93
94 private:
95   void check_space (u_int);
96
97 private:
98   static char *f_start;
99   char        *f_point;
100   static char *f_end;
101   char        *f_end_of_data;
102   static int   f_reference_count;
103 };