2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
24 * $XConsortium: buffer.h /main/6 1996/08/15 14:21:05 cde-hal $
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
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
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.
44 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
56 #include "utility/funcs.h"
62 buffer(const int sz = 1024) : v_swap_order(false) { _alloc(sz); };
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) {
71 v_eptr = v_aptr = v_base = ptr;
73 }; // set buffer chunk
74 void set_content_sz(const int sz) {v_eptr = v_base + sz;} ;
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'
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
91 buffer& getusc(int& y); // get unsigned char to intr.
92 // no boundary checking
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
104 buffer& skip(int i) ; // skip i chars
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; };
110 friend Boolean operator ==(buffer&, buffer&);
113 friend ostream& operator <<(ostream&, buffer&);
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;
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
129 Boolean v_swap_order;
132 void _alloc(const int sz);
135 typedef buffer* bufferPtr;