Some DebugRec fixes

stable-5.3
Sven Eberhardt 2012-10-14 14:39:22 +02:00
parent 9c1496178b
commit ec22028640
4 changed files with 25 additions and 4 deletions

View File

@ -93,6 +93,7 @@ enum C4RecordChunkType // record file chunk type
RCT_OCF = 0xA3, // OCF setting of updating
RCT_DirectExec = 0xA4, // a DirectExec-script
RCT_Definition = 0xA5, // Definition callback
RCT_SetProperty= 0xA6, // set a property in a proplist
RCT_Custom = 0xc0, // varies

View File

@ -25,6 +25,9 @@
#include <C4GameObjects.h>
#include <C4Game.h>
#include <C4Object.h>
#ifdef DEBUGREC
#include <C4Record.h>
#endif
void C4PropList::AddRef(C4Value *pRef)
{
@ -327,13 +330,15 @@ void C4PropList::AppendDataString(StdStrBuf * out, const char * delim, int depth
DataString.Append("...");
return;
}
const C4Property * p = Properties.First();
C4Set<C4Property> sorted_props = Properties;
sorted_props.Sort();
const C4Property * p = sorted_props.First();
while (p)
{
DataString.Append(p->Key->GetData());
DataString.Append(" = ");
DataString.Append(p->Value.GetDataString(depth - 1));
p = Properties.Next(p);
p = sorted_props.Next(p);
if (p) DataString.Append(delim);
}
}
@ -588,6 +593,9 @@ void C4PropList::SetPropertyByS(C4String * k, const C4Value & to)
{
//C4Property p(k, to);
//Properties.Add(p);
#ifdef DEBUGREC_SCRIPT
if (k->GetCStr()) AddDbgRec(RCT_SetProperty, k->GetCStr(), strlen(k->GetCStr())+1);
#endif
Properties.Add(C4Property(k, to));
}
}

View File

@ -37,11 +37,11 @@ public:
{ assert(Key); Key->IncRef(); /*assert(Strings.Set.Has(Key));*/ }
C4Property(const C4Property &o) : Key(o.Key), Value(o.Value) { if (Key) Key->IncRef(); }
C4Property & operator = (const C4Property &o)
{ assert(o.Key); o.Key->IncRef(); if (Key) Key->DecRef(); Key = o.Key; Value = o.Value; return *this; }
{ if(o.Key) o.Key->IncRef(); if (Key) Key->DecRef(); Key = o.Key; Value = o.Value; return *this; }
#ifdef HAVE_RVALUE_REF
C4Property(C4Property && o) : Key(o.Key), Value(std::move(o.Value)) { o.Key = 0; }
C4Property & operator = (C4Property && o)
{ assert(o.Key); if (Key) Key->DecRef(); Key = o.Key; o.Key = 0; Value = std::move(o.Value); return *this; }
{ if (Key) Key->DecRef(); Key = o.Key; o.Key = 0; Value = std::move(o.Value); return *this; }
#endif
~C4Property() { if (Key) Key->DecRef(); }
void CompileFunc(StdCompiler *pComp, C4ValueNumbers *);
@ -50,6 +50,8 @@ public:
operator const void * () const { return Key; }
C4Property & operator = (void * p)
{ assert(!p); if (Key) Key->DecRef(); Key = 0; Value.Set0(); return *this; }
bool operator < (const C4Property &cmp) const { return strcmp(GetSafeKey(), cmp.GetSafeKey())<0; }
const char *GetSafeKey() const { if (Key && Key->GetCStr()) return Key->GetCStr(); return ""; } // get key as C string; return "" if undefined. never return NULL
};
class C4PropListNumbered;
class C4PropList

View File

@ -169,6 +169,7 @@ public:
Table = new T[Capacity];
for (unsigned int i = 0; i < Capacity; ++i)
Table[i] = b.Table[i];
return *this;
}
void CompileFunc(StdCompiler *pComp, C4ValueNumbers *);
void Clear()
@ -253,6 +254,15 @@ public:
Size = Size2;
Table = Table2;
}
static bool SortFunc(T &v1, T &v2)
{
return v1<v2;
}
void Sort()
{
// sort by keys
std::sort(&Table[0], &Table[Capacity-1], C4Set<T>::SortFunc);
}
};
template<> template<>