diff -r a5343ffaee9348b73724f22d91a71ff346ac250a -r 209d6fa3805c6cba93dbefa51a42f02fed6dd82a include/ptypes.h --- a/include/ptypes.h Fri May 10 23:40:01 2013 -0500 +++ b/include/ptypes.h Sat May 11 21:57:33 2013 -0500 @@ -18,6 +18,7 @@ #endif #include +#include PTYPES_BEGIN @@ -1084,17 +1085,24 @@ { protected: int tag; - tpodlist _keys; - tpodlist _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 _keys; + //std::vector _vals; + variant _keys; + variant _vals; + //tpodlist _keys; + //tpodlist _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 @@ -1107,10 +1115,10 @@ 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); diff -r a5343ffaee9348b73724f22d91a71ff346ac250a -r 209d6fa3805c6cba93dbefa51a42f02fed6dd82a src/ptparray.cpp --- a/src/ptparray.cpp Fri May 10 23:40:01 2013 -0500 +++ b/src/ptparray.cpp Sat May 11 21:57:33 2013 -0500 @@ -3,26 +3,39 @@ #include #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; } @@ -33,7 +46,11 @@ 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 @@ -44,30 +61,36 @@ 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]; } diff -r a5343ffaee9348b73724f22d91a71ff346ac250a -r 209d6fa3805c6cba93dbefa51a42f02fed6dd82a src/pvariant.cxx --- a/src/pvariant.cxx Fri May 10 23:40:01 2013 -0500 +++ b/src/pvariant.cxx Sat May 11 21:57:33 2013 -0500 @@ -15,6 +15,7 @@ #include #include "ptypes.h" +#include "pstreams.h" PTYPES_BEGIN @@ -141,8 +142,10 @@ 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"); } @@ -194,7 +197,7 @@ initialize(v.value.o); break; default: - vfatal(); + vfatal(v.tag); } } @@ -220,7 +223,7 @@ release(value.o); break; default: - vfatal(); + vfatal(tag); } } tag = VAR_NULL; @@ -294,7 +297,7 @@ assign(v.value.o); break; default: - vfatal(); + vfatal(v.tag); } } @@ -364,7 +367,7 @@ } case VAR_ARRAY: return value.a->count != 0; case VAR_OBJECT: return 0; - default: vfatal(); + default: vfatal(tag); } return 0; } @@ -381,7 +384,7 @@ 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; } @@ -406,7 +409,7 @@ } case VAR_ARRAY: return int(value.a->count != 0); case VAR_OBJECT: return 0; - default: vfatal(); + default: vfatal(tag); } return 0; } @@ -429,7 +432,7 @@ 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); } } @@ -473,7 +476,7 @@ 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; } }