Skip to content

Commit

Permalink
Turn on NDebuggable support for NString, NData, NArray, and NDictionary.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dair Grant authored and Dair Grant committed Jul 17, 2013
1 parent 21f3be4 commit a981035
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 41 deletions.
1 change: 1 addition & 0 deletions Library/Source/Nano/Core/Nano.h
Expand Up @@ -141,6 +141,7 @@
#include "NData.h"
#include "NDate.h"
#include "NDateFormatter.h"
#include "NDebuggable.h"
#include "NDictionary.h"
#include "NEncodable.h"
#include "NEncoder.h"
Expand Down
38 changes: 38 additions & 0 deletions Library/Source/Nano/Types/NArray.cpp
Expand Up @@ -137,6 +137,10 @@ NArray::NArray(const NStringList &theValues)
//----------------------------------------------------------------------------
NArray::NArray(void)
{


// Initialise ourselves
ValueChanged(NULL);
}


Expand Down Expand Up @@ -218,6 +222,8 @@ void NArray::Join(const NArray &theValue)

// Join the arrays
append(*theArray, *(theValue.GetImmutable()));

ValueChanged(theArray);
}


Expand All @@ -244,8 +250,10 @@ void NArray::Sort(const NArrayCompareFunctor &theFunctor, const NRange &theRange
iterLast = theArray->begin() + finalRange.GetNext();



// Sort the array
std::sort(iterFirst, iterLast, NSortArray(compareWith));
ValueChanged(theArray);
}


Expand Down Expand Up @@ -357,6 +365,8 @@ void NArray::SetValue(NIndex theIndex, const NVariant &theValue)
// Set the value
theArray = GetMutable();
theArray->at(theIndex) = theValue;

ValueChanged(theArray);
}


Expand All @@ -379,6 +389,8 @@ void NArray::AppendValue(const NVariant &theValue)
// Append the value
theArray = GetMutable();
theArray->push_back(theValue);

ValueChanged(theArray);
}


Expand Down Expand Up @@ -976,6 +988,32 @@ void NArray::DecodeSelf(const NEncoder &theEncoder)


#pragma mark private
//============================================================================
// NArray::ValueChanged : Our value has been changed.
//----------------------------------------------------------------------------
void NArray::ValueChanged(NArrayValue *theValue)
{ NIndex theSize;



// Compiler warnings
NN_UNUSED(theSize);
NN_UNUSED(theValue);



// Update the debug summary
#if NN_DEBUG
theSize = (theValue == NULL) ? 0 : (theValue->size());

UpdateSummary("%ld %s", theSize, theSize == 1 ? "value" : "values");
#endif
}





//============================================================================
// NArray::GetCompareFunctor : Get a comparison functor.
//----------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions Library/Source/Nano/Types/NArray.h
Expand Up @@ -21,6 +21,7 @@
#include "NContainer.h"
#include "NVariant.h"
#include "NComparable.h"
#include "NDebuggable.h"
#include "NEncodable.h"
#include "NRange.h"
#include "NPoint.h"
Expand Down Expand Up @@ -66,6 +67,7 @@ typedef NSharedValue<NArrayValue> NSharedValueArray;
//----------------------------------------------------------------------------
class NArray : public NContainer,
public NEncodable,
public NDebuggable,
public NComparable<NArray>,
public NSharedValueArray {
public:
Expand Down Expand Up @@ -167,6 +169,8 @@ class NArray : public NContainer,


private:
void ValueChanged(NArrayValue *theValue);

NArrayCompareFunctor GetCompareFunctor(const NArrayCompareFunctor &theFunctor) const;
NString GetDebugID(NIndex theIndex) const;

Expand Down
84 changes: 51 additions & 33 deletions Library/Source/Nano/Types/NData.cpp
Expand Up @@ -65,6 +65,8 @@ NData::NData(NIndex theSize, const void *thePtr, bool makeCopy)
mExternalSize = 0;
mExternalPtr = NULL;

ValueChanged(NULL);



// Assign the data
Expand All @@ -86,6 +88,8 @@ NData::NData(void)
// Initialize ourselves
mExternalSize = 0;
mExternalPtr = NULL;

ValueChanged(NULL);
}


Expand All @@ -112,11 +116,12 @@ void NData::Clear(void)

// Clear the value
NSharedValueData::Clear();
ClearHash();

mSlice = NRange(0, 0);
mExternalSize = 0;
mExternalPtr = NULL;

ValueChanged(NULL);
}


Expand Down Expand Up @@ -196,7 +201,7 @@ bool NData::SetSize(NIndex theSize)
newSize = GetSize();

if (newSize != oldSize)
ClearHash();
ValueChanged(NULL);

return(newSize == theSize);
}
Expand Down Expand Up @@ -397,7 +402,8 @@ void NData::SetData(NIndex theSize, const void *thePtr, bool makeCopy)
mSlice = NRange(0, theSize);
mExternalSize = theSize;
mExternalPtr = thePtr;
ClearHash();

ValueChanged(NULL);
}
}

Expand Down Expand Up @@ -449,7 +455,7 @@ UInt8 *NData::InsertData(NIndex beforeIndex, const NData &theData)
// Inserting via iterators allows us to avoid manually resizing our
// value, which saves a redundant initialisation of the new area.
dstValue->insert(dstInsert, srcBegin, srcEnd);
ResizedValue(dstValue);
ValueChanged(dstValue);



Expand Down Expand Up @@ -494,7 +500,7 @@ UInt8 *NData::InsertData(NIndex beforeIndex, NIndex theSize, const void *thePtr)
//
// Since insert will zero-fill we can skip the copy if our source is NULL.
dstValue->insert(dstInsert, theSize, 0x00);
ResizedValue(dstValue);
ValueChanged(dstValue);

if (thePtr != NULL)
{
Expand Down Expand Up @@ -540,7 +546,7 @@ void NData::RemoveData(const NRange &theRange)

// Remove the data
theValue->erase(removeFirst, removeLast);
ResizedValue(theValue);
ValueChanged(theValue);
}


Expand Down Expand Up @@ -695,11 +701,12 @@ const NData& NData::operator = (const NData &theValue)
if (this != &theValue)
{
NSharedValueData::operator=(theValue);
ClearHash();

mSlice = theValue.mSlice;
mExternalSize = theValue.mExternalSize;
mExternalPtr = theValue.mExternalPtr;

ValueChanged(NULL);
}

return(*this);
Expand Down Expand Up @@ -890,6 +897,42 @@ void NData::DecodeSelf(const NEncoder &theEncoder)


#pragma mark private
//============================================================================
// NData::ValueChanged : Our value has been changed.
//----------------------------------------------------------------------------
void NData::ValueChanged(NDataValue *theValue)
{


// Update the slice
//
// If we have a mutable value then we have the only copy of the data,
// so by definition our slice spans the whole range.
if (theValue != NULL)
{
mSlice = NRange(0, (NIndex) theValue->size());
NN_ASSERT(IsValidSlice());
}



// Update the debug summary
#if NN_DEBUG
UpdateSummary("%ld %s", mSlice.GetSize(), mSlice.GetSize() == 1 ? "byte" : "bytes");
#endif



// Reset our state
ClearHash();

NN_ASSERT(IsValidSlice());
}





//============================================================================
// NData::IsValidSlice : Is our slice valid?
//----------------------------------------------------------------------------
Expand Down Expand Up @@ -945,34 +988,9 @@ void NData::ResizeValue(NDataValue *theValue, NIndex theSize)


// Update our state
ResizedValue(theValue);
ValueChanged(theValue);
}





//============================================================================
// NData::ResizedValue : The value has been resized.
//----------------------------------------------------------------------------
void NData::ResizedValue(NDataValue *theValue)
{


// Reset our state
//
// If we have a mutable value then we have the only copy of the data,
// so by definition our slice spans the whole range.
mSlice = NRange(0, (NIndex) theValue->size());
NN_ASSERT(IsValidSlice());

ClearHash();



// Check our state
NN_ASSERT(IsValidSlice());
}



9 changes: 6 additions & 3 deletions Library/Source/Nano/Types/NData.h
Expand Up @@ -18,6 +18,8 @@
//----------------------------------------------------------------------------
#include "NStringFormatter.h"
#include "NSharedValue.h"
#include "NComparable.h"
#include "NDebuggable.h"
#include "NEncodable.h"
#include "NContainer.h"
#include "NHashable.h"
Expand Down Expand Up @@ -52,6 +54,7 @@ typedef NSharedValue<NDataValue> NSharedValueData;
class NData : public NContainer,
public NHashable,
public NEncodable,
public NDebuggable,
public NComparable<NData>,
public NSharedValueData {
public:
Expand Down Expand Up @@ -162,10 +165,10 @@ class NData : public NContainer,


private:
bool IsValidSlice(void) const;
void ValueChanged(NDataValue *theValue);

void ResizeValue( NDataValue *theValue, NIndex theSize);
void ResizedValue(NDataValue *theValue);
bool IsValidSlice(void) const;
void ResizeValue(NDataValue *theValue, NIndex theSize);


private:
Expand Down
35 changes: 35 additions & 0 deletions Library/Source/Nano/Types/NDictionary.cpp
Expand Up @@ -38,6 +38,10 @@ NENCODABLE_DEFINE(NDictionary);
//----------------------------------------------------------------------------
NDictionary::NDictionary(void)
{


// Initialise ourselves
ValueChanged(NULL);
}


Expand Down Expand Up @@ -239,6 +243,8 @@ void NDictionary::RemoveKey(const NString &theKey)

// Remove the key
theDict->erase(theKey);

ValueChanged(theDict);
}


Expand Down Expand Up @@ -323,6 +329,8 @@ void NDictionary::SetValue(const NString &theKey, const NVariant &theValue)
// Set the value
theDict = GetMutable();
(*theDict)[theKey] = theValue;

ValueChanged(theDict);
}


Expand Down Expand Up @@ -700,6 +708,33 @@ void NDictionary::DecodeSelf(const NEncoder &theEncoder)



#pragma mark private
//============================================================================
// NDictionary::ValueChanged : Our value has been changed.
//----------------------------------------------------------------------------
void NDictionary::ValueChanged(NDictionaryValue *theValue)
{ NIndex theSize;



// Compiler warnings
NN_UNUSED(theSize);
NN_UNUSED(theValue);



// Update the debug summary
#if NN_DEBUG
theSize = (theValue == NULL) ? 0 : (theValue->size());

UpdateSummary("%ld %s", theSize, theSize == 1 ? "value" : "values");
#endif
}





//============================================================================
// NDictionary::GetDebugID : Get the debug ID for a value.
//----------------------------------------------------------------------------
Expand Down

0 comments on commit a981035

Please sign in to comment.