Skip to content
Snippets Groups Projects
Commit c68ed079 authored by Podhorszki, Norbert's avatar Podhorszki, Norbert
Browse files

Move some dimension checks into separate function so Write() can check them as well.

parent 2a56236d
No related branches found
No related tags found
1 merge request!224Fix the variable definition initialization rules and add test for Def…
...@@ -29,7 +29,7 @@ void Engine::Write(Variable<T> &variable, const T *values) ...@@ -29,7 +29,7 @@ void Engine::Write(Variable<T> &variable, const T *values)
{ {
if (m_DebugMode) if (m_DebugMode)
{ {
variable.CheckDims("in call to Write"); variable.CheckDimsBeforeWrite("Write(" + variable.m_Name + ")");
} }
DoWrite(variable, values); DoWrite(variable, values);
......
...@@ -168,14 +168,6 @@ void VariableBase::InitShapeType() ...@@ -168,14 +168,6 @@ void VariableBase::InitShapeType()
} }
m_ShapeID = ShapeID::JoinedArray; m_ShapeID = ShapeID::JoinedArray;
} }
else if (std::count(m_Shape.begin(), m_Shape.end(), JoinedDim) > 1)
{
throw std::invalid_argument(
"ERROR: variable can't have more than one "
"JoinedDim in shape argument, in call to "
"DefineVariable " +
m_Name + "\n");
}
else if (m_Start.empty() && m_Count.empty()) else if (m_Start.empty() && m_Count.empty())
{ {
if (m_Shape.size() == 1 && m_Shape.front() == LocalValueDim) if (m_Shape.size() == 1 && m_Shape.front() == LocalValueDim)
...@@ -265,6 +257,12 @@ void VariableBase::InitShapeType() ...@@ -265,6 +257,12 @@ void VariableBase::InitShapeType()
} }
/* Extra checks for invalid settings */ /* Extra checks for invalid settings */
if (m_DebugMode)
CheckDimsCommon("DefineVariable(" + m_Name + ")");
}
void VariableBase::CheckDimsCommon(const std::string hint) const
{
if (m_ShapeID != ShapeID::LocalValue) if (m_ShapeID != ShapeID::LocalValue)
{ {
if ((!m_Shape.empty() && if ((!m_Shape.empty() &&
...@@ -276,14 +274,26 @@ void VariableBase::InitShapeType() ...@@ -276,14 +274,26 @@ void VariableBase::InitShapeType()
{ {
throw std::invalid_argument("ERROR: LocalValueDim is only " throw std::invalid_argument("ERROR: LocalValueDim is only "
"allowed in a {LocalValueDim} " "allowed in a {LocalValueDim} "
"shape in call to " "shape in call to " +
"DefineVariable " + hint + "\n");
m_Name + "\n");
} }
} }
if ((!m_Shape.empty() &&
std::count(m_Shape.begin(), m_Shape.end(), JoinedDim) > 1) ||
(!m_Start.empty() &&
std::count(m_Start.begin(), m_Start.end(), JoinedDim) > 0) ||
(!m_Count.empty() &&
std::count(m_Count.begin(), m_Count.end(), JoinedDim) > 0))
{
throw std::invalid_argument("ERROR: JoinedDim is only allowed once in "
"Shape and cannot appear in Start/Count in "
"call to " +
hint + "\n");
}
} }
void VariableBase::CheckDims(const std::string hint) const void VariableBase::CheckDimsBeforeWrite(const std::string hint) const
{ {
if (m_ShapeID == ShapeID::GlobalArray) if (m_ShapeID == ShapeID::GlobalArray)
{ {
...@@ -292,10 +302,12 @@ void VariableBase::CheckDims(const std::string hint) const ...@@ -292,10 +302,12 @@ void VariableBase::CheckDims(const std::string hint) const
throw std::invalid_argument( throw std::invalid_argument(
"ERROR: GlobalArray variable " + m_Name + "ERROR: GlobalArray variable " + m_Name +
" start and count dimensions must be defined by either " " start and count dimensions must be defined by either "
"DefineVariable or a Selection " + "DefineVariable or a Selection in call to " +
hint + "\n"); hint + "\n");
} }
} }
CheckDimsCommon(hint);
// TODO need to think more exceptions here // TODO need to think more exceptions here
} }
......
...@@ -137,9 +137,14 @@ public: ...@@ -137,9 +137,14 @@ public:
/** Registered transforms */ /** Registered transforms */
std::vector<TransformInfo> m_TransformsInfo; std::vector<TransformInfo> m_TransformsInfo;
/** Self-check dims according to type, called right after DefineVariable and
* SetSelection.
* @param hint extra debugging info for the exception */
void CheckDimsCommon(const std::string hint) const;
/** Self-check dims according to type, called from Engine before Write /** Self-check dims according to type, called from Engine before Write
* @param hint extra debugging info for the exception */ * @param hint extra debugging info for the exception */
void CheckDims(const std::string hint) const; void CheckDimsBeforeWrite(const std::string hint) const;
private: private:
const bool m_DebugMode = false; const bool m_DebugMode = false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment