00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "w_defines.h"
00031
00032
00033
00034 #include <w.h>
00035 #include <vtable.h>
00036
00037 #include <w_strstream.h>
00038
00039
00040 void
00041 vtable_row_t::set_uint(int a, unsigned int v) {
00042
00043 w_assert1(a < N);
00044
00045 w_assert3(strlen(_get_const(a)) == 0);
00046
00047
00048 w_ostrstream o(_insert_attribute(a), value_size());
00049
00050 o << v << ends;
00051 _inserted(a);
00052 }
00053
00054 void
00055 vtable_row_t::set_base(int a, w_base_t::base_float_t v) {
00056
00057 w_assert1(a < N);
00058
00059 w_assert9(strlen(_get_const(a)) == 0);
00060 w_ostrstream o(_insert_attribute(a), value_size());
00061 o << v << ends;
00062 _inserted(a);
00063 }
00064
00065 void
00066 vtable_row_t::set_base(int a, w_base_t::base_stat_t v) {
00067
00068 w_assert1(a < N);
00069
00070 w_assert9(strlen(_get_const(a)) == 0);
00071 w_ostrstream o(_insert_attribute(a), value_size());
00072 o << v << ends;
00073 _inserted(a);
00074 }
00075
00076 void
00077 vtable_row_t::set_int(int a, int v) {
00078 w_assert1(a < N);
00079 w_assert9(strlen(_get_const(a)) == 0);
00080 w_ostrstream o(_insert_attribute(a), value_size());
00081 o << v << ends;
00082 _inserted(a);
00083 }
00084
00085 void
00086 vtable_row_t::set_string(int a, const char *v) {
00087
00088 w_assert1(a < N);
00089 w_assert1((int)strlen(v) < value_size());
00090
00091 w_assert9(strlen(_get_const(a)) == 0);
00092 strcpy(_insert_attribute(a), v);
00093 w_assert9(_get_const(a)[strlen(v)] == '\0');
00094 _inserted(a);
00095 }
00096
00097 void
00098 vtable_row_t::dump(const char *msg) const
00099 {
00100 fprintf(stderr, "vtable_row_t (%s) at %p {\n", msg, this );
00101 fprintf(stderr, "N %d M %d _in_use %d\n", N, M, _in_use);
00102 fprintf(stderr, "_list %p -> _list_end %p\n", _list, _list_end);
00103
00104 for(int i=0; i<=_in_use; i++) {
00105 const char *not_yet_set = "Not yet set";
00106 const char *p = _entry[i];
00107 const char *A = "";
00108 if(p < _list) {
00109 A = "BOGUS: addr too low";
00110 }
00111 const char *B = "";
00112 if(p > _list_end) {
00113 B = "BOGUS: addr too high";
00114 }
00115 fprintf(stderr, "%s %s _entry[%d] = %p, string= %s \n" ,
00116 A, B, i, p, (i==_in_use?not_yet_set:p));
00117 }
00118 fprintf(stderr, "}\n");
00119 }
00120
00121 void
00122 vtable_row_t::_inserted(int a) {
00123 w_assert0(a < N);
00124 w_assert0(a == _in_use);
00125 int l = strlen(_entry[a]);
00126 w_assert0(*(_entry[a] + l +1) == '\0');
00127 if(a == N-1) {
00128
00129 if(l==0) l++;
00130 _list_end = _entry[a] + l;
00131 } else {
00132 _entry[a+1] = _entry[a] + l + 1;
00133 _list_end = _entry[a+1];
00134 }
00135
00136
00137 _in_use++;
00138 w_assert0(_in_use <= N);
00139 }
00140
00141 ostream&
00142 vtable_row_t::operator<<(ostream &o)
00143 {
00144
00145 for(int i=0; i<_in_use; i++) {
00146 if(strlen(_get_const(i)) > 0) {
00147 o << i << ": " << _get_const(i) <<endl;
00148 }
00149 }
00150 o << endl;
00151 return o;
00152 }
00153
00154
00155 int
00156 vtable_t::init(int R, int A, int S) {
00157
00158 _rows_filled = 0;
00159 _rows = R;
00160 _rowsize_attributes = A;
00161
00162
00163
00164
00165 _rowsize_bytes = align(vtable_row_t::bytes_required_for(A, S));
00166
00167 _array_alias = new char [_rows * _rowsize_bytes];
00168
00169 if(_array_alias) {
00170
00171 memset(_array_alias, '\0', _rows * _rowsize_bytes);
00172
00173 for(int i=0; i<_rows; i++) {
00174 vtable_row_t *row = _get_row(i);
00175 row->init_for_attributes(_rowsize_attributes, S);
00176 w_assert1(row->size_in_bytes() <= _rowsize_bytes);
00177 }
00178 return 0;
00179 } else {
00180 return -1;
00181 }
00182 }
00183
00184 void
00185 vtable_t::filled_one()
00186 {
00187 W_IFDEBUG1(vtable_row_t *t = _get_row(_rows_filled);)
00188 w_assert1(t->size_in_bytes() <= _rowsize_bytes);
00189
00190 _rows_filled++;
00191 w_assert9(_rows_filled <= _rows);
00192 }
00193
00194 ostream&
00195 vtable_t::operator<<(ostream &o) const {
00196
00197 for(int i=0; i<_rows; i++) {
00198 _get_row(i)->operator<<(o) ;
00199 }
00200 o << endl;
00201 return o;
00202 }
00203
00204 vtable_row_t*
00205 vtable_t::_get_row(int i) const {
00206 w_assert9(i >= 0);
00207 w_assert9(i <= _rows);
00208 w_assert9(_rows_filled <= _rows);
00209 vtable_row_t* v =
00210 (vtable_row_t *)&_array_alias[i * _rowsize_bytes];
00211 return v;
00212 }
00213
00214 int
00215 vtable_t::realloc()
00216 {
00217 W_FATAL_MSG(fcINTERNAL, <<"vtable_t::realloc is not implemented");
00218 return 0;
00219 }