ptypes

ptypes Commit Details


Date:2013-05-11 21:57:00 (11 years 7 months ago)
Author:Natalie Adams
Branch:default
Commit:209d6fa3805c
Parents: a5343ffaee93
Message:Updating tparray to use variants as array because tpodlist was causing variant data corruption

Changes:
Minclude/ptypes.h (3 diffs)
Msrc/ptparray.cpp (3 diffs)
Msrc/pvariant.cxx (10 diffs)

File differences

include/ptypes.h
1818
1919
2020
21
2122
2223
2324
......
10841085
10851086
10861087
1087
1088
1088
1089
1090
1091
1092
1093
1094
1095
1096
10891097
10901098
10911099
10921100
10931101
1094
1102
10951103
10961104
1097
1105
10981106
10991107
11001108
......
11071115
11081116
11091117
1110
1118
11111119
11121120
1113
1121
11141122
11151123
11161124
#endif
#include <string.h>
#include <vector>
PTYPES_BEGIN
{
protected:
int tag;
tpodlist<variant> _keys;
tpodlist<variant> _vals;
// using a tpodlist was causing variant data corrupt errors
// perhaps it has to do with the issue of the converting to pointers
// TODO: Write dynamic array class
//std::vector<variant> _keys;
//std::vector<variant> _vals;
variant _keys;
variant _vals;
//tpodlist<variant> _keys;
//tpodlist<variant> _vals;
public:
tparray() { tag = ARR_NULL; }
//anext function acts similar for variants and loops through elements
// This is allowed for both types
ptpublic friend bool ptdecl anext(const tparray& a, int&, variant& val);
ptpublic friend bool ptdecl anext(const tparray& a, int& i, variant& val);
// This is only allowed for Associative arrays as a list doesn't have keys
ptpublic friend bool ptdecl anext(const tparray& a, int&, variant& val, variant & key);
ptpublic friend bool ptdecl anext(const tparray& a, int& i, variant& val, variant & key);
/*
Initialy the object will be NULL - but calling one of these functions
ptpublic friend variant ptdecl get(tparray & t, const variant & val);
// This will return the value at the given index
ptpublic friend variant ptdecl at(tparray & t, int index);
ptpublic friend variant ptdecl at(tparray & t, large index);
// This will return the key at the given index
ptpublic friend variant ptdecl keyat(tparray & t, int index);
ptpublic friend variant ptdecl keyat(tparray & t, large index);
friend bool isassoc(const tparray& t);
friend bool islist(const tparray& t);
src/ptparray.cpp
33
44
55
6
67
78
89
910
1011
1112
12
13
14
15
16
17
18
13
14
15
1916
2017
2118
2219
2320
24
25
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
2639
2740
2841
......
3346
3447
3548
36
49
50
51
52
53
3754
3855
3956
......
4461
4562
4663
47
48
64
65
66
67
68
69
4970
5071
5172
5273
5374
5475
55
76
77
78
5679
57
80
5881
59
82
6083
6184
6285
6386
6487
65
88
6689
6790
6891
6992
70
93
7194
7295
7396
#include <limits.h>
#include "ptypes.h"
#include "pstreams.h"
PTYPES_BEGIN
bool ptdecl anext(const tparray& a, int& i, variant& val)
{
variant t;
return anext(a, i, val, t);
}
bool ptdecl anext(const tparray& a, int& i, variant& val, variant & key)
{
if (a._keys.get_count() == i)
//if (a._vals.size() == i)
//if (a._vals.get_count() == i)
if (alength(a._vals) == i)
{
return false;
}
else
{
val = a._vals[i];
key = a._keys[i];
val = a._vals[(large)i];
i++;
return true;
}
}
bool ptdecl anext(const tparray& a, int& i, variant& val, variant & key)
{
//if (a._keys.size() == i)
//if (a._keys.get_count() == i)
if (alength(a._keys) == i)
{
return false;
}
else
{
val = a._vals[(large)i];
key = a._keys[(large)i];
i++;
return true;
}
if (t.tag == ARR_NULL || t.tag == ARR_LIST)
{
t.tag = ARR_LIST;
t._vals.add(val);
//pout.put("here1");
//t._vals.push_back(val);
add(t._vals, val);
//t._vals.add(val);
//pout.put("here2");
}
//else drop it
if (t.tag == ARR_NULL || t.tag == ARR_ASSOCIATIVE)
{
t.tag = ARR_ASSOCIATIVE;
t._vals.add(val);
t._keys.add(key);
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);
}
}
variant ptdecl get(tparray & t, const variant & val)
{
for(int i = 0; i < t._keys.get_count(); i++)
//for(int i = 0; i < t._keys.size(); i++)
//for(int i = 0; i < t._keys.get_count(); i++)
for(int i = 0; i < alength(t._keys); i++)
{
if (t._keys[i] == val)
if (t._keys[(large)i] == val)
{
return t._vals[i];
return t._vals[(large)i];
}
}
return NULL;
}
variant ptdecl at(tparray & t, int index)
variant ptdecl at(tparray & t, large index)
{
return t._vals[index];
}
variant ptdecl keyat(tparray & t, int index)
variant ptdecl keyat(tparray & t, large index)
{
return t._keys[index];
}
src/pvariant.cxx
1515
1616
1717
18
1819
1920
2021
......
141142
142143
143144
144
145
145146
147
148
146149
147150
148151
......
194197
195198
196199
197
200
198201
199202
200203
......
220223
221224
222225
223
226
224227
225228
226229
......
294297
295298
296299
297
300
298301
299302
300303
......
364367
365368
366369
367
370
368371
369372
370373
......
381384
382385
383386
384
387
385388
386389
387390
......
406409
407410
408411
409
412
410413
411414
412415
......
429432
430433
431434
432
435
433436
434437
435438
......
473476
474477
475478
476
479
477480
478481
479482
#include <limits.h>
#include "ptypes.h"
#include "pstreams.h"
PTYPES_BEGIN
static void vconverr(large v);
static void vfatal()
static void vfatal(int tag = -1)
{
//pout.put("tag = ");
//pout.put(tag);
fatal(CRIT_FIRST + 60, "Variant data corrupt");
}
initialize(v.value.o);
break;
default:
vfatal();
vfatal(v.tag);
}
}
release(value.o);
break;
default:
vfatal();
vfatal(tag);
}
}
tag = VAR_NULL;
assign(v.value.o);
break;
default:
vfatal();
vfatal(v.tag);
}
}
}
case VAR_ARRAY: return value.a->count != 0;
case VAR_OBJECT: return 0;
default: vfatal();
default: vfatal(tag);
}
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();
default: vfatal(tag);
}
return false;
}
}
case VAR_ARRAY: return int(value.a->count != 0);
case VAR_OBJECT: return 0;
default: vfatal();
default: vfatal(tag);
}
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();
default: vfatal(v.tag);
}
}
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(); return false;
default: vfatal(tag); return false;
}
}

Archive Download the corresponding diff file

Branches

Tags

Page rendered in 0.66266s using 14 queries.