ptypes

ptypes Commit Details


Date:2013-05-14 23:38:00 (11 years 7 months ago)
Author:Natalie Adams
Branch:default
Commit:8176df673244
Parents: 0b1d6c529eda
Message:Removing commented code

Remove tag parameter from vfatal
Modfying next parameter for variant to be smarter when the variant is an object
First use of typeinfo for component
Changes:
Minclude/ptypes.h (2 diffs)
Msrc/ptparray.cxx (3 diffs)
Msrc/pvariant.cxx (10 diffs)

File differences

include/ptypes.h
990990
991991
992992
993
993994
994995
995996
......
11041105
11051106
11061107
1107
1108
1109
11081110
11091111
11101112
ptpublic friend void ptdecl apack(variant&);
ptpublic friend bool ptdecl anext(const variant& a, int&, variant& item);
ptpublic friend bool ptdecl anext(const variant& a, int&, variant& item, string& key);
ptpublic friend bool ptdecl anext(const variant& array, int& index, variant& item, variant & key);
ptpublic friend int ptdecl aadd(variant&, const variant& item);
ptpublic friend void ptdecl aput(variant&, int index, const variant& item);
ptpublic friend void ptdecl ains(variant&, int index, const variant& item);
//tpodlist<variant> _keys;
//tpodlist<variant> _vals;
public:
tparray() { tag = ARR_NULL; }
static const void * TYPE; //declared in ptparray.cxx - http://stackoverflow.com/questions/1639154/how-to-declare-a-static-const-char-in-your-header-file
tparray() { typeinfo = const_cast<void*>(TYPE); tag = ARR_NULL; }
//anext function acts similar for variants and loops through elements
// This is allowed for both types
src/ptparray.cxx
88
99
1010
11
12
1113
1214
1315
......
4648
4749
4850
49
50
5151
52
53
5452
5553
5654
......
6361
6462
6563
66
67
68
69
7064
7165
7266
PTYPES_BEGIN
const void * tparray::TYPE = (void*)1;
bool ptdecl anext(const tparray& a, int& i, variant& val)
{
//if (a._vals.size() == i)
if (t.tag == ARR_NULL || t.tag == ARR_LIST)
{
t.tag = ARR_LIST;
//pout.put("here1");
//t._vals.push_back(val);
add(t._vals, val);
//t._vals.add(val);
//pout.put("here2");
}
//else drop it
t.tag = ARR_ASSOCIATIVE;
add(t._vals, val);
add(t._keys, key);
//t._vals.add(val);
//t._keys.add(key);
//t._vals.push_back(val);
//t._keys.push_back(key);
}
}
src/pvariant.cxx
142142
143143
144144
145
145
146146
147
148
149147
150148
151149
......
197195
198196
199197
200
198
201199
202200
203201
......
223221
224222
225223
226
224
227225
228226
229227
......
297295
298296
299297
300
298
301299
302300
303301
......
367365
368366
369367
370
368
371369
372370
373371
......
384382
385383
386384
387
385
388386
389387
390388
......
409407
410408
411409
412
410
413411
414412
415413
......
432430
433431
434432
435
433
436434
437435
438436
......
476474
477475
478476
479
477
480478
481479
482480
......
572570
573571
574572
573
574
575
576
577
578
579
580
581
582
583
584
585
575586
576587
577588
578589
579590
591
592
593
594
595
596
597
598
599
600
580601
581602
582603
static void vconverr(large v);
static void vfatal(int tag = -1)
static void vfatal()
{
//pout.put("tag = ");
//pout.put(tag);
fatal(CRIT_FIRST + 60, "Variant data corrupt");
}
initialize(v.value.o);
break;
default:
vfatal(v.tag);
vfatal();
}
}
release(value.o);
break;
default:
vfatal(tag);
vfatal();
}
}
tag = VAR_NULL;
assign(v.value.o);
break;
default:
vfatal(v.tag);
vfatal();
}
}
}
case VAR_ARRAY: return value.a->count != 0;
case VAR_OBJECT: return 0;
default: vfatal(tag);
default: vfatal();
}
return 0;
}
case VAR_STRING: return !isempty((PTR_TO_STRING(value.s)));
case VAR_ARRAY: return value.a->count != 0;
case VAR_OBJECT: return value.o != nil;
default: vfatal(tag);
default: vfatal();
}
return false;
}
}
case VAR_ARRAY: return int(value.a->count != 0);
case VAR_OBJECT: return 0;
default: vfatal(tag);
default: vfatal();
}
return 0;
}
case VAR_STRING: initialize(PTR_TO_STRING(v.value.s)); break;
case VAR_ARRAY: initialize(); break;
case VAR_OBJECT: initialize(); break;
default: vfatal(v.tag);
default: vfatal();
}
}
case VAR_STRING: return strcmp(value.s, v.value.s) == 0;
case VAR_ARRAY: return value.a == v.value.a;
case VAR_OBJECT: return value.o == v.value.o;
default: vfatal(tag); return false;
default: vfatal(); return false;
}
}
return anext(array, index, item, key);
}
bool ptdecl anext(const variant& array, int& index, variant& item, variant & key)
{
if (array.tag == VAR_OBJECT)
{
void * type = ((component*)array)->get_typeinfo();
if (type == tparray::TYPE) //tparray
{
return anext(*((tparray*)(component*)array), index, item, key);
}
}
return false;
}
bool ptdecl anext(const variant& array, int& index, variant& item, string & key)
{
if (array.tag != VAR_ARRAY)
{
if (array.tag == VAR_OBJECT)
{
void * type = ((component*)array)->get_typeinfo();
if (type == tparray::TYPE) //tparray
{
return anext(*((tparray*)(component*)array), index, item);
} else {
return false;
}
}
clear(item);
return false;
}

Archive Download the corresponding diff file

Branches

Tags

Page rendered in 0.63729s using 14 queries.