Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
iosdata.h
Go to the documentation of this file.
1
29#ifndef _RWSTD_IOSDATA_H_INCLUDED
30#define _RWSTD_IOSDATA_H_INCLUDED
31
32
33#include <string.h>
34
35#include <rw/_iosbase.h>
36#include <rw/_defs.h>
37
38
40
41// POD-type
42struct ios_base::_C_usr_data
43{
44 struct _C_event_cb {
45 int _C_index;
46 ios_base::event_callback _C_fn;
47 };
48
49 typedef void (ios_base::*_C_fire_fun)(ios_base::event, bool);
50
51 // allocates a 0-initialized chunk of storage
52 static _C_usr_data* _C_alloc (_C_fire_fun);
53 static void _C_dealloc (_C_usr_data*);
54
55 void *_C_tie; // tied stream object
56 long *_C_iarray; // user long data
57 void* *_C_parray; // user void* data
58 _C_event_cb *_C_cbarray; // array of user-registered callbacks
59 _RWSTD_SIZE_T _C_isize; // size of _C_iarray in elements
60 _RWSTD_SIZE_T _C_psize; // size of _C_parray in elements
61 _RWSTD_SIZE_T _C_cbsize; // size of _C_cbarray in elements
62
63 // set to point to ios_base::_C_fire_event, used to eliminate
64 // the dependency of the translation unit that defines common
65 // ios_base members on the one that defines rarely used ones
66 _C_fire_fun _C_fire;
67
68 static _C_usr_data _C_std_usr_data [2];
69};
70
71
72inline /* static */ ios_base::_C_usr_data*
73ios_base::_C_usr_data::_C_alloc (_C_fire_fun pfire)
74{
75 _TRY {
76 // rely on 0-initialization of PODs
77 _C_usr_data* const pdata = new _C_usr_data ();
78
79#ifdef _RWSTD_NO_NEW_THROWS
80
81 if (!pdata)
82 return 0;
83
84#endif // _RWSTD_NO_NEW_THROWS
85
86 _RWSTD_ASSERT (0 != pdata);
87
88#ifndef _RWSTD_NO_POD_ZERO_INIT
89
90 // assert that the POD ctor above zeroed out all members
91 _RWSTD_ASSERT (!pdata->_C_tie);
92 _RWSTD_ASSERT (!pdata->_C_iarray);
93 _RWSTD_ASSERT (!pdata->_C_parray);
94 _RWSTD_ASSERT (!pdata->_C_cbarray);
95 _RWSTD_ASSERT (!pdata->_C_isize);
96 _RWSTD_ASSERT (!pdata->_C_psize);
97 _RWSTD_ASSERT (!pdata->_C_cbsize);
98
99#else // if defined (_RWSTD_NO_POD_ZERO_INIT)
100
101 memset (pdata, 0, sizeof *pdata);
102
103#endif // _RWSTD_NO_POD_ZERO_INIT
104
105 pdata->_C_fire = pfire;
106
107 return pdata;
108 }
109 _CATCH (...) {
110 return 0;
111 }
112}
113
114
115inline /* static */ void
116ios_base::_C_usr_data::_C_dealloc (_C_usr_data *ptr)
117{
118 if (ptr) {
119 operator delete (ptr->_C_iarray);
120 operator delete (ptr->_C_parray);
121 operator delete (ptr->_C_cbarray);
122
123 if ( ptr != _C_usr_data::_C_std_usr_data
124 && ptr != _C_usr_data::_C_std_usr_data + 1)
125 delete ptr;
126 }
127}
128
129
130} // namespace std
131
132
133#endif // _RWSTD_IOSDATA_H_INCLUDED
#define ptr
Definition 17.names.cpp:525
#define _TRY
Definition _defs.h:850
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _RWSTD_ASSERT(ignore)
Definition _defs.h:1108
#define _CATCH(ex)
Definition _defs.h:851
Definition json.h:5363