Skip to content

Commit

Permalink
Abstraction of field not found code for better control of error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Jay Rush committed Jun 24, 2017
1 parent e9c326e commit 85a1afa
Show file tree
Hide file tree
Showing 49 changed files with 54 additions and 169 deletions.
2 changes: 1 addition & 1 deletion src/libs/abilib/abi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ SFString nextAbiChunk(const SFString& fieldIn, bool& force, const void *data) {
return ret;
}

return "Field not found: [{" + fieldIn + "}]\n";
return fldNotFound(fieldIn);
}

//---------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/libs/abilib/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ SFString nextFunctionChunk(const SFString& fieldIn, bool& force, const void *dat
return ret;
}

return "Field not found: [{" + fieldIn + "}]\n";
return fldNotFound(fieldIn);
}

//---------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/libs/abilib/parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ SFString nextParameterChunk(const SFString& fieldIn, bool& force, const void *da
return ret;
}

return "Field not found: [{" + fieldIn + "}]\n";
return fldNotFound(fieldIn);
}

//---------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/libs/acctlib/infix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ SFString nextInfixChunk(const SFString& fieldIn, bool& force, const void *data)
return ret;
}

return "Field not found: [{" + fieldIn + "}]\n";
return fldNotFound(fieldIn);
}

//---------------------------------------------------------------------------------------------------
Expand Down
109 changes: 1 addition & 108 deletions src/libs/acctlib/leaf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,8 @@ SFString nextLeafChunk(const SFString& fieldIn, bool& force, const void *data) {

switch (tolower(fieldIn[0])) {
case 'm':
#ifdef OLD_LEAF
if ( fieldIn % "m_leafValue" ) return lea->m_leafValue;
#else
if ( fieldIn % "m_first" ) return asStringU(lea->m_first);
if ( fieldIn % "m_last" ) return asStringU(lea->m_last);
#endif
break;
}

Expand All @@ -68,7 +64,7 @@ SFString nextLeafChunk(const SFString& fieldIn, bool& force, const void *data) {
return ret;
}

return "Field not found: [{" + fieldIn + "}]\n";
return fldNotFound(fieldIn);
}

//---------------------------------------------------------------------------------------------------
Expand All @@ -81,12 +77,8 @@ bool CLeaf::setValueByName(const SFString& fieldName, const SFString& fieldValue

switch (tolower(fieldName[0])) {
case 'm':
#ifdef OLD_LEAF
if ( fieldName % "m_leafValue" ) { m_leafValue = fieldValue; return true; }
#else
if ( fieldName % "m_first" ) { m_first = toUnsigned(fieldValue); return true; }
if ( fieldName % "m_last" ) { m_last = toUnsigned(fieldValue); return true; }
#endif
break;
default:
break;
Expand All @@ -107,12 +99,8 @@ bool CLeaf::Serialize(SFArchive& archive) {

CTreeNode::Serialize(archive);

#ifdef OLD_LEAF
archive >> m_leafValue;
#else
archive >> m_first;
archive >> m_last;
#endif
finishParse();
return true;
}
Expand All @@ -121,12 +109,8 @@ bool CLeaf::Serialize(SFArchive& archive) {
bool CLeaf::SerializeC(SFArchive& archive) const {
CTreeNode::SerializeC(archive);

#ifdef OLD_LEAF
archive << m_leafValue;
#else
archive << m_first;
archive << m_last;
#endif

return true;
}
Expand All @@ -142,12 +126,8 @@ void CLeaf::registerClass(void) {
uint32_t fieldNum = 1000;
ADD_FIELD(CLeaf, "schema", T_NUMBER|TS_LABEL, ++fieldNum);
ADD_FIELD(CLeaf, "deleted", T_BOOL|TS_LABEL, ++fieldNum);
#ifdef OLD_LEAF
ADD_FIELD(CLeaf, "m_leafValue", T_TEXT, ++fieldNum);
#else
ADD_FIELD(CLeaf, "m_first", T_NUMBER, ++fieldNum);
ADD_FIELD(CLeaf, "m_last", T_NUMBER, ++fieldNum);
#endif

// Hide our internal fields, user can turn them on if they like
HIDE_FIELD(CLeaf, "schema");
Expand Down Expand Up @@ -195,92 +175,6 @@ bool CLeaf::readBackLevel(SFArchive& archive) {

//---------------------------------------------------------------------------
// EXISTING_CODE
#ifdef OLD_LEAF
//-----------------------------------------------------------------------------
CLeaf::CLeaf(const SFString& _key, const SFString& _value) {
m_leafValue = _value;
m_prefix = _key;
if (verbose == 2) cerr << "\t\tCreating leaf " << _key << " at " << _value << endl;
}

//-----------------------------------------------------------------------------
SFString CLeaf::at(const SFString& _key) const {
return contains(_key) ? m_leafValue : "";
}

//-----------------------------------------------------------------------------
bool CLeaf::contains(const SFString& _key) const {
size_t l1 = _key.length();
size_t l2 = m_prefix.length();
const char *s1 = (const char*)_key;
const char *s2 = (const char*)m_prefix;
bool found = !memcmp(s1, s2, l1);

return l1 == l2 && found;
}

//-----------------------------------------------------------------------------
CTreeNode* CLeaf::insert(const SFString& _key, const SFString& _value) {
if (contains(_key)) {
// If the leaf exists, we reset the value
// We've reached the end of the key, so store the value here
// if (m_leafValue.empty()) {
// // store the first encountered block
// if (verbose) cerr << "\t\tStoring first contents " << _key << " at " << _value << "\n";
// m_leafValue = _value;
//
// } else
{
// preserve the most recent block encountered
if (verbose) cerr << "\t\tReplacing leaf contents " << _key << " at " << _value
// << " (" << m_leafValue << ")"
<< "\n";
m_leafValue = nextTokenClear(m_leafValue, '|');
m_leafValue += "|" + _value;
}
return this;

} else {
// If the leaf is not the key, delete convert to a branch
if (verbose == 2) { cerr << "\tleaf branching " << _key << " at " << _value << "\n"; }
CTreeNode *n = CTreeNode::newBranch(_key, _value, m_prefix, m_leafValue);
delete this;
return n;
}
}

//-----------------------------------------------------------------------------
CTreeNode* CLeaf::remove(const SFString& _key) {
if (verbose)
cerr << endl<< endl<< endl
<< idnt << SFString('-', 80) << endl
<< idnt << SFString('-', 80) << endl
<< idnt << "remove infix at [" << _key << "]: ";

if (contains(_key)) {
if (verbose)
cerr << endl << idnt << "removed leaf node at" << _key << endl;
delete this;
return NULL;
}
if (verbose)
cerr << endl << idnt << "no node removed at" << _key << endl;
return this;
}

//------------------------------------------------------------------
bool CLeaf::visitItems(ACCTVISITOR func, void *data) const {
ASSERT(func);
CVisitData *vd = reinterpret_cast<CVisitData*>(data);
uint32_t save = vd->type;
vd->type = T_LEAF;
vd->strs = vd->strs + "+" + (cMagenta+m_prefix + cOff + "|" + cBlue + m_leafValue + cOff);
(*func)(this, data);
nextTokenClearReverse(vd->strs, '+');
vd->type = save;
return true;
}
#else
//-----------------------------------------------------------------------------
CLeaf::CLeaf(const SFString& _key, const SFString& _value) {
SFString last = _value;
Expand Down Expand Up @@ -368,7 +262,6 @@ bool CLeaf::readBackLevel(SFArchive& archive) {
vd->type = save;
return true;
}
#endif
// EXISTING_CODE
} // namespace qblocks

13 changes: 0 additions & 13 deletions src/libs/acctlib/leaf.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,13 @@ typedef SFList<CLeaf*> CLeafList;
typedef SFUniqueList<CLeaf*> CLeafListU;

// EXISTING_CODE
//#define OLD_LEAF 1
// EXISTING_CODE

//--------------------------------------------------------------------------
class CLeaf : public CTreeNode {
public:
#ifdef OLD_LEAF
SFString m_leafValue;
#else
SFUint32 m_first;
SFUint32 m_last;
#endif

public:
CLeaf(void);
Expand Down Expand Up @@ -98,12 +93,8 @@ inline void CLeaf::Clear(void) {
inline void CLeaf::Init(void) {
CTreeNode::Init();

#ifdef OLD_LEAF
// m_leafValue = EMPTY;
#else
m_first = 0;
m_last = 0;
#endif

// EXISTING_CODE
// EXISTING_CODE
Expand All @@ -114,12 +105,8 @@ inline void CLeaf::Copy(const CLeaf& le) {
Clear();
CTreeNode::Copy(le);

#ifdef OLD_LEAF
m_leafValue = le.m_leafValue;
#else
m_first = le.m_first;
m_last = le.m_last;
#endif

// EXISTING_CODE
// EXISTING_CODE
Expand Down
2 changes: 1 addition & 1 deletion src/libs/acctlib/treenode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ SFString nextTreenodeChunk(const SFString& fieldIn, bool& force, const void *dat
return ret;
}

return "Field not found: [{" + fieldIn + "}]\n";
return fldNotFound(fieldIn);
}

//---------------------------------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion src/libs/acctlib/treenode.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* This file was generated with makeClass. Edit only those parts of the code inside
* of 'EXISTING_CODE' tags.
*/
#include <algorithm>
#include "etherlib.h"

namespace qblocks {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/acctlib/treeroot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ SFString nextTreerootChunk(const SFString& fieldIn, bool& force, const void *dat
return ret;
}

return "Field not found: [{" + fieldIn + "}]\n";
return fldNotFound(fieldIn);
}

//---------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/libs/etherlib/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ SFString nextAccountChunk(const SFString& fieldIn, bool& force, const void *data
return ret;
}

return "Field not found: [{" + fieldIn + "}]\n";
return fldNotFound(fieldIn);
}

//---------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/libs/etherlib/balhistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ SFString nextBalhistoryChunk(const SFString& fieldIn, bool& force, const void *d
return ret;
}

return "Field not found: [{" + fieldIn + "}]\n";
return fldNotFound(fieldIn);
}

//---------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/libs/etherlib/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ SFString nextBlockChunk(const SFString& fieldIn, bool& force, const void *data)
return ret;
}

return "Field not found: [{" + fieldIn + "}]\n";
return fldNotFound(fieldIn);
}

//---------------------------------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/libs/etherlib/incomestatement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ SFString nextIncomestatementChunk(const SFString& fieldIn, bool& force, const vo
return ret;
}

return "Field not found: [{" + fieldIn + "}]\n";
return fldNotFound(fieldIn);
}

//---------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -237,6 +237,7 @@ ostream& operator<<(ostream& os, const CIncomeStatement& is) {
}
return os;
}
//---------------------------------------------------------------------------
bool CIncomeStatement::reconcile(const SFAddress& addr, blknum_t blockNum) {
nodeBal = getBalance(addr, blockNum, false);
return balanced();
Expand Down
5 changes: 2 additions & 3 deletions src/libs/etherlib/logentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ SFString nextLogentryChunk(const SFString& fieldIn, bool& force, const void *dat
if ( fieldIn % "logIndex" ) return asStringU(log->logIndex);
break;
case 't':
if ( fieldIn % "topics" )
{
if ( fieldIn % "topics" ) {
uint32_t cnt = log->topics.getCount();
if (!cnt) return EMPTY;
SFString ret;
Expand Down Expand Up @@ -88,7 +87,7 @@ SFString nextLogentryChunk(const SFString& fieldIn, bool& force, const void *dat
return ret;
}

return "Field not found: [{" + fieldIn + "}]\n";
return fldNotFound(fieldIn);
}

//---------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/libs/etherlib/pricequote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ SFString nextPricequoteChunk(const SFString& fieldIn, bool& force, const void *d
return ret;
}

return "Field not found: [{" + fieldIn + "}]\n";
return fldNotFound(fieldIn);
}

//---------------------------------------------------------------------------------------------------
Expand Down
5 changes: 2 additions & 3 deletions src/libs/etherlib/receipt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ SFString nextReceiptChunk(const SFString& fieldIn, bool& force, const void *data
if ( fieldIn % "gasUsed" ) return asStringU(rec->gasUsed);
break;
case 'l':
if ( fieldIn % "logs" )
{
if ( fieldIn % "logs" ) {
uint32_t cnt = rec->logs.getCount();
if (!cnt) return EMPTY;
SFString ret;
Expand Down Expand Up @@ -86,7 +85,7 @@ SFString nextReceiptChunk(const SFString& fieldIn, bool& force, const void *data
return ret;
}

return "Field not found: [{" + fieldIn + "}]\n";
return fldNotFound(fieldIn);
}

//---------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/libs/etherlib/rpcresult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ SFString nextRpcresultChunk(const SFString& fieldIn, bool& force, const void *da
return ret;
}

return "Field not found: [{" + fieldIn + "}]\n";
return fldNotFound(fieldIn);
}

//---------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/libs/etherlib/traceaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ SFString nextTraceactionChunk(const SFString& fieldIn, bool& force, const void *
return ret;
}

return "Field not found: [{" + fieldIn + "}]\n";
return fldNotFound(fieldIn);
}

//---------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/libs/etherlib/traceresult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ SFString nextTraceresultChunk(const SFString& fieldIn, bool& force, const void *
return ret;
}

return "Field not found: [{" + fieldIn + "}]\n";
return fldNotFound(fieldIn);
}

//---------------------------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 85a1afa

Please sign in to comment.