1 //=============================================================================
2 //
3 //   File : KviKvsTreeNodeHashReferenceAssert.cpp
4 //   Creation date : Thu 16 Oct 2003 23:43:06 by Szymon Stefanek
5 //
6 //   This file is part of the KVIrc IRC client distribution
7 //   Copyright (C) 2003-2010 Szymon Stefanek <pragma at kvirc dot net>
8 //
9 //   This program is FREE software. You can redistribute it and/or
10 //   modify it under the terms of the GNU General Public License
11 //   as published by the Free Software Foundation; either version 2
12 //   of the License, or (at your option) any later version.
13 //
14 //   This program is distributed in the HOPE that it will be USEFUL,
15 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
16 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 //   See the GNU General Public License for more details.
18 //
19 //   You should have received a copy of the GNU General Public License
20 //   along with this program. If not, write to the Free Software Foundation,
21 //   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 //=============================================================================
24 
25 #include "KviKvsTreeNodeHashReferenceAssert.h"
26 #include "KviKvsRWEvaluationResult.h"
27 #include "KviKvsRunTimeContext.h"
28 #include "KviKvsVariant.h"
29 #include "KviLocale.h"
30 
KviKvsTreeNodeHashReferenceAssert(const QChar * pLocation,KviKvsTreeNodeData * pSource)31 KviKvsTreeNodeHashReferenceAssert::KviKvsTreeNodeHashReferenceAssert(const QChar * pLocation, KviKvsTreeNodeData * pSource)
32     : KviKvsTreeNodeIndirectData(pLocation, pSource)
33 {
34 }
35 
36 KviKvsTreeNodeHashReferenceAssert::~KviKvsTreeNodeHashReferenceAssert()
37     = default;
38 
isReadOnly()39 bool KviKvsTreeNodeHashReferenceAssert::isReadOnly()
40 {
41 	return m_pSource->isReadOnly();
42 }
43 
contextDescription(QString & szBuffer)44 void KviKvsTreeNodeHashReferenceAssert::contextDescription(QString & szBuffer)
45 {
46 	szBuffer = "Hash Reference Assert";
47 }
48 
dump(const char * prefix)49 void KviKvsTreeNodeHashReferenceAssert::dump(const char * prefix)
50 {
51 	qDebug("%s HashReferenceAssert", prefix);
52 }
53 
evaluateReadOnlyInObjectScope(KviKvsObject * o,KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)54 bool KviKvsTreeNodeHashReferenceAssert::evaluateReadOnlyInObjectScope(KviKvsObject * o, KviKvsRunTimeContext * c, KviKvsVariant * pBuffer)
55 {
56 	if(o)
57 	{
58 		if(!m_pSource->evaluateReadOnlyInObjectScope(o, c, pBuffer))
59 			return false;
60 	}
61 	else
62 	{
63 		if(!m_pSource->evaluateReadOnly(c, pBuffer))
64 			return false;
65 	}
66 
67 	if(!pBuffer->isHash())
68 	{
69 		if(!pBuffer->isNothing())
70 		{
71 			QString szType;
72 			pBuffer->getTypeName(szType);
73 			c->error(this, __tr2qs_ctx("Hash reference assert failed: the variable evaluated to type '%Q'", "kvs"), &szType);
74 			return false;
75 		}
76 	}
77 	return true;
78 }
79 
evaluateReadWriteInObjectScope(KviKvsObject * o,KviKvsRunTimeContext * c)80 KviKvsRWEvaluationResult * KviKvsTreeNodeHashReferenceAssert::evaluateReadWriteInObjectScope(KviKvsObject * o, KviKvsRunTimeContext * c)
81 {
82 	KviKvsRWEvaluationResult * r;
83 	if(o)
84 		r = m_pSource->evaluateReadWriteInObjectScope(o, c);
85 	else
86 		r = m_pSource->evaluateReadWrite(c);
87 	if(!r)
88 		return nullptr;
89 
90 	return r;
91 }
92 
evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)93 bool KviKvsTreeNodeHashReferenceAssert::evaluateReadOnly(KviKvsRunTimeContext * c, KviKvsVariant * pBuffer)
94 {
95 	return evaluateReadOnlyInObjectScope(nullptr, c, pBuffer);
96 }
97 
evaluateReadWrite(KviKvsRunTimeContext * c)98 KviKvsRWEvaluationResult * KviKvsTreeNodeHashReferenceAssert::evaluateReadWrite(KviKvsRunTimeContext * c)
99 {
100 	return evaluateReadWriteInObjectScope(nullptr, c);
101 }
102