Disable all code related to libXp
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / utility / buffer.h
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 librararies 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.h /main/6 1996/08/15 14:21:05 cde-hal $
25  *
26  * Copyright (c) 1993 HAL Computer Systems International, Ltd.
27  * All rights reserved.  Unpublished -- rights reserved under
28  * the Copyright Laws of the United States.  USE OF A COPYRIGHT
29  * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
30  * OR DISCLOSURE.
31  * 
32  * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
33  * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.  USE,
34  * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
35  * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
36  * INTERNATIONAL, LTD.
37  * 
38  *                         RESTRICTED RIGHTS LEGEND
39  * Use, duplication, or disclosure by the Government is subject
40  * to the restrictions as set forth in subparagraph (c)(l)(ii)
41  * of the Rights in Technical Data and Computer Software clause
42  * at DFARS 252.227-7013.
43  *
44  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
45  *                  1315 Dell Avenue
46  *                  Campbell, CA  95008
47  * 
48  */
49
50
51 #ifndef _buffer_h
52 #define _buffer_h 1
53
54 #include <ctype.h>
55 #include <iomanip>
56 #include "utility/funcs.h"
57
58 class buffer 
59 {
60
61 public:
62    buffer(const int sz = 1024) : v_swap_order(false) { _alloc(sz); };
63    buffer(buffer&);
64    virtual ~buffer();
65
66 // buffer management functions
67    virtual void reset(); // clean the buffer
68    int expand_chunk(const int);       // expand buffer chunk
69    void set_chunk(char* ptr, const int sz) { 
70       v_bufsz = sz;
71       v_eptr = v_aptr = v_base = ptr;
72       v_allocated = 0;
73    };  // set buffer chunk
74    void set_content_sz(const int sz) {v_eptr = v_base + sz;} ;
75
76 // buffer status functions
77    int buf_sz() const { return v_bufsz; };           // chunk length
78    int content_sz() const { return v_eptr - v_aptr; }; // content length 
79    int remaining_sz() const { return v_bufsz - int(v_eptr - v_aptr); }; // remaining space
80    char* get_base() const { return v_base; };  // get 'base'
81
82 // get items 
83    buffer& get(char& y);                     // get current char
84    buffer& get(unsigned short& y);           // get a short
85    buffer& get(unsigned int& y);             // get a unsigned int
86    buffer& get(int& y);                      // get an int
87    buffer& get(long& y);                     // get a long
88    buffer& get(float & y);                   // get a float 
89    buffer& get(char*, int) ;                 // get a string
90
91    buffer& getusc(int& y);                   // get unsigned char to intr. 
92                                              // no boundary checking
93
94 // put items 
95    buffer& put(const char content, Boolean exp_buf = false) ; // append char 
96    buffer& put(const unsigned char, Boolean exp_buf = false) ; //append unsigned char 
97    buffer& put(const int, Boolean exp_buf = false) ;           // append an int
98    buffer& put(const unsigned int, Boolean exp_buf = false) ;  // append a unsigned int
99    buffer& put(const long, Boolean exp_buf = false) ;          // append a long
100    buffer& put(const unsigned short, Boolean exp_buf = false) ; //append a short
101    buffer& put(const float y, Boolean exp_buf = false);       // put a float 
102    buffer& put(const char*, int, Boolean exp_buf = false) ;   // append a string
103
104    buffer& skip(int i) ;                       // skip i chars
105
106 // set and get byte order 
107    void set_swap_order(Boolean x) { v_swap_order = x; };
108    Boolean get_swap_order() { return v_swap_order; };
109
110    friend Boolean operator ==(buffer&, buffer&);
111
112 // show the buffer
113    friend ostream& operator <<(ostream&, buffer&);
114
115    friend class abs_storage;
116    friend class unixf_storage;
117    friend class page_storage;
118    friend class mem_storage;
119    friend class page_cache_global_part;
120
121 protected:
122    char v_allocated;
123    unsigned int  v_bufsz ;   // allocated chunk size
124    char *v_base ;  // base address of the chunk
125    char *v_eptr ;  // end address of the buf content
126    char *v_aptr ;  // beginning address of the buf content
127    int  v_align_offset; // memory align offset
128
129    Boolean v_swap_order;
130
131 protected:
132    void _alloc(const int sz);
133 };
134
135 typedef buffer* bufferPtr;
136    
137 #endif