fd1c4af325da741c43ce985662db4006a105f21b
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Basic / Buffer.hh
1 /*
2  * $XConsortium: Buffer.hh /main/3 1996/06/11 16:18:01 cde-hal $
3  *
4  * Copyright (c) 1992 HaL Computer Systems, Inc.  All rights reserved.
5  * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
6  * States.  Use of a copyright notice is precautionary only and does not
7  * imply publication or disclosure.
8  * 
9  * This software contains confidential information and trade secrets of HaL
10  * Computer Systems, Inc.  Use, disclosure, or reproduction is prohibited
11  * without the prior express written permission of HaL Computer Systems, Inc.
12  * 
13  *                         RESTRICTED RIGHTS LEGEND
14  * Use, duplication, or disclosure by the Government is subject to
15  * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
16  * Technical Data and Computer Software clause at DFARS 252.227-7013.
17  *                        HaL Computer Systems, Inc.
18  *                  1315 Dell Avenue, Campbell, CA  95008
19  * 
20  */
21
22
23 class Buffer
24 {
25 public:
26   Buffer (u_int initial_size = 1024);
27   ~Buffer();
28
29   void init (u_int initial_size = 1024);
30
31   char *point() const
32     { return (f_point); }
33   // Might want to add assert to make sure point is valid.  15:07 01/12/93 DJB 
34   void point (char *new_point)
35     { f_point = new_point; }
36   const char *data() const
37     { return (f_start); }
38   u_int length() const
39     { return (f_end_of_data - f_start); }
40   // Methods for saving buffer independent position inforation, since
41   // the buffer can be dynamically reallocated.  You must save offsets
42   // if you want to get an existing string out of the buffer after a
43   // write. 
44   int offset (const char *point) const
45     { return (point - f_start); }
46   char *position (int offset)
47     { return (f_start + offset); }
48   // Return the number of bytes of real data remaining after the point. 
49   u_int remaining() const
50     { return (f_end_of_data - f_point); }
51   void reset()
52     { f_point = f_start; }
53
54   void write (const int integer);
55
56 #ifndef __osf__
57   void write (const size_t integer)
58     { write ((size_t) ((void *) integer)); }
59 #else
60   void write (const unsigned int integer)
61     { write ((int) integer); }
62 #endif
63
64   void write (const char *string);
65   void write (const char *bytes, u_int size, u_int length);
66
67   void read (int *integer);
68   void read (unsigned int *integer)
69     { read ((int *) integer); }
70   // Versions to get copy (space must exist!): 
71   u_int read (char *const string);
72   void read (char *const bytes, u_int size, u_int length);
73   // Versions to point into buffer memory:
74   u_int read (char **string);
75   void read (char **bytes, u_int size, u_int length);
76
77 private:
78   void check_space (u_int);
79
80 private:
81   static char *f_start;
82   char        *f_point;
83   static char *f_end;
84   char        *f_end_of_data;
85   static int   f_reference_count;
86 };