149 " numVariables=\"%d\"\n"
150 " numClauses=\"%d\"\n"
152 " numCallbacks=\"%d\"\n"
153 " language=\"%s\" >\n\n",
155 m_mapVariables.size(),
158 m_mapCallbacks.size(),
159 m_strLanguage.
Get());
161 for (
auto& it : m_mapVariables) {
165 pVar->
Serialize(strAppend, bCalculatingID);
172 for (
auto& it : m_mapClauses) {
179 for (
auto& it : m_mapHooks) {
180 const std::string& str_hook_name = it.first;
181 const std::string& str_clause_name = it.second;
184 " clause=\"%s\" />\n\n",
185 str_hook_name.c_str(), str_clause_name.c_str());
188 for (
auto& it : m_mapCallbacks) {
189 const std::string& str_callback_name = it.first;
190 const std::string& str_clause_name = it.second;
193 " clause=\"%s\" />\n\n",
194 str_callback_name.c_str(),
195 str_clause_name.c_str());
206 bool bIsDirty =
false;
208 for (
const auto& it : m_mapVariables) {
224 otErr <<
"OTBylaw::IsDirty: Error: Why is it that a variable "
225 "is CONSTANT, yet DIRTY at the same time?\n";
237 bool bIsDirty =
false;
239 for (
const auto& it : m_mapVariables) {
264 for (
auto& it : m_mapVariables) {
278 for (
auto& it : m_mapVariables) {
279 const std::string str_var_name = it.first;
281 OT_ASSERT((
nullptr != pVar) && (str_var_name.size() > 0));
293 otOut <<
"OTBylaw::Compare: The variable count doesn't match for "
294 "bylaw: " << m_strName <<
"\n";
298 otOut <<
"OTBylaw::Compare: The clause count doesn't match for "
299 "bylaw: " << m_strName <<
"\n";
304 <<
"OTBylaw::Compare: The hook count doesn't match for bylaw: "
305 << m_strName <<
"\n";
309 otOut <<
"OTBylaw::Compare: The callback count doesn't match for "
310 "bylaw: " << m_strName <<
"\n";
316 for (
const auto& it : m_mapVariables) {
322 if (
nullptr == pVar2) {
323 otOut <<
"OTBylaw::Compare: Failed: Variable not found: "
328 otOut <<
"OTBylaw::Compare: Failed comparison between 2 "
329 "variables named " << pVar->
GetName() <<
".\n";
334 for (
const auto& it : m_mapClauses) {
340 if (
nullptr == pClause2) {
341 otOut <<
"OTBylaw::Compare: Failed: Clause not found: "
342 << pClause->
GetName() <<
".\n";
345 if (!pClause->
Compare(*pClause2)) {
346 otOut <<
"OTBylaw::Compare: Failed comparison between 2 "
347 "clauses named " << pClause->
GetName() <<
".\n";
352 for (
const auto& it : m_mapCallbacks) {
353 const std::string& str_callback_name = it.first;
354 const std::string& str_clause_name = it.second;
359 if (
nullptr == pCallbackClause) {
360 otOut <<
"OTBylaw::Compare: Failed: Callback ("
361 << str_callback_name <<
") clause (" << str_clause_name
362 <<
") not found on this bylaw: " << m_strName <<
".\n";
365 else if (
nullptr == pCallbackClause2) {
366 otOut <<
"OTBylaw::Compare: Failed: Callback ("
367 << str_callback_name <<
") clause (" << str_clause_name
368 <<
") not found on rhs bylaw: " << rhs.
GetName() <<
".\n";
372 pCallbackClause2->
GetName()))) {
373 otOut <<
"OTBylaw::Compare: Failed: Callback ("
374 << str_callback_name <<
") clause (" << str_clause_name
375 <<
") on rhs has a different name ("
377 <<
") than *this bylaw: " << m_strName <<
".\n";
389 std::set<std::string> theHookSet;
393 for (
const auto& it : m_mapHooks) {
394 const std::string& str_hook_name = it.first;
395 theHookSet.insert(str_hook_name);
399 for (
const auto& it_hook : theHookSet) {
400 const std::string& str_hook_name = it_hook;
404 if (!
GetHooks(str_hook_name, theHookClauses) ||
405 !rhs.
GetHooks(str_hook_name, theHookClauses2)) {
406 otOut <<
"OTBylaw::Compare: Failed finding hook ("
408 <<
") clauses on this bylaw or rhs bylaw: " << m_strName
413 if (theHookClauses.size() != theHookClauses2.size()) {
414 otOut <<
"OTBylaw::Compare: Hook (" << str_hook_name
415 <<
") clauses count doesn't match between this bylaw and "
416 "the rhs bylaw named: " << m_strName <<
"\n";
420 for (
auto& it : theHookClauses) {
421 const std::string str_clause_name = it.first;
425 auto it_rhs = theHookClauses2.find(str_clause_name);
427 if (theHookClauses2.end() == it_rhs) {
428 otOut <<
"OTBylaw::Compare: Unable to find hook clause ("
430 <<
") on rhs that was definitely present on *this. "
431 "Bylaw: " << m_strName <<
"\n";
453 (nIndex >= static_cast<int64_t>(m_mapCallbacks.size()))) {
454 otErr << __FUNCTION__ <<
": Index out of bounds: " << nIndex <<
"\n";
457 int32_t nLoopIndex = -1;
459 for (
auto& it : m_mapCallbacks) {
460 const std::string& str_callback_name = it.first;
462 if (nLoopIndex == nIndex)
return str_callback_name;
473 (str_CallbackName.compare(0, 9,
"callback_") !=
476 otErr <<
"OTBylaw::GetCallback: Callback name MUST begin with "
477 "callback_ but value passed in was: " << str_CallbackName
482 for (
auto& it : m_mapCallbacks) {
483 const std::string& str_callback_name = it.first;
484 const std::string& str_clause_name = it.second;
489 if (0 == (str_callback_name.compare(str_CallbackName))) {
492 if (
nullptr != pClause)
497 otOut <<
"OTBylaw::GetCallback: Couldn't find clause ("
499 <<
") that was registered for callback ("
500 << str_callback_name <<
")\n";
513 std::string str_ClauseName)
517 auto it = m_mapCallbacks.find(str_CallbackName);
519 if (m_mapCallbacks.end() != it)
521 const std::string str_existing_clause = it->second;
522 otOut <<
"OTBylaw::AddCallback: Failed to add callback ("
523 << str_CallbackName <<
") to bylaw " << m_strName
524 <<
", already there as " << str_existing_clause <<
".\n";
531 otErr <<
"OTBylaw::AddCallback: Error: empty name (" << str_CallbackName
532 <<
") or clause (" << str_ClauseName <<
").";
533 else if (str_CallbackName.compare(0, 9,
"callback_") !=
536 otOut <<
"OTBylaw::AddCallback: Callback name MUST begin with "
537 "callback_ in order to be accepted: Failure. (callback name "
538 << str_CallbackName <<
") (clause name " << str_ClauseName
540 else if (m_mapCallbacks.end() ==
541 m_mapCallbacks.insert(
542 m_mapCallbacks.begin(),
543 std::pair<std::string, std::string>(str_CallbackName.c_str(),
544 str_ClauseName.c_str())))
545 otErr <<
"OTBylaw::AddCallback: Failed inserting to m_mapCallbacks: "
546 << str_CallbackName <<
" / " << str_ClauseName <<
" \n";
560 otErr <<
"OTBylaw::AddHook: Error: empty hook name (" << str_HookName
561 <<
") or clause name (" << str_ClauseName <<
").";
562 else if ((str_HookName.compare(0, 5,
"cron_") != 0) &&
563 (str_HookName.compare(0, 5,
"hook_") != 0))
564 otOut <<
"OTBylaw::AddHook: hook name MUST begin with either hook_ or "
565 "cron_ in order to be accepted: Failure."
566 " (hook name " << str_HookName <<
") (clause name "
567 << str_ClauseName <<
") \n";
568 else if (m_mapHooks.end() ==
569 m_mapHooks.insert(std::pair<std::string, std::string>(
570 str_HookName.c_str(), str_ClauseName.c_str())))
571 otErr <<
"OTBylaw::AddHook: Failed inserting to m_mapHooks: "
572 << str_HookName <<
" / " << str_ClauseName <<
" \n";
586 otErr <<
"OTBylaw::GetVariable: Error: invalid str_var_name.\n";
590 auto it = m_mapVariables.find(str_var_name);
592 if (m_mapVariables.end() == it)
return nullptr;
604 if (!((nIndex >= 0) &&
605 (nIndex < static_cast<int64_t>(m_mapVariables.size())))) {
606 otErr << __FUNCTION__ <<
": Index out of bounds: " << nIndex <<
"\n";
609 int32_t nLoopIndex = -1;
611 for (
auto& it : m_mapVariables) {
617 if (nLoopIndex == nIndex)
return pVar;
626 otErr <<
"OTBylaw::GetClause: Error: empty str_clause_name.\n";
630 auto it = m_mapClauses.find(str_clause_name);
632 if (m_mapClauses.end() == it)
return nullptr;
644 if (!((nIndex >= 0) &&
645 (nIndex < static_cast<int64_t>(m_mapClauses.size())))) {
646 otErr << __FUNCTION__ <<
": Index out of bounds: " << nIndex <<
"\n";
649 int32_t nLoopIndex = -1;
651 for (
auto& it : m_mapClauses) {
657 if (nLoopIndex == nIndex)
return pClause;
665 if ((nIndex < 0) || (nIndex >= static_cast<int64_t>(m_mapHooks.size()))) {
666 otErr << __FUNCTION__ <<
": Index out of bounds: " << nIndex <<
"\n";
669 int32_t nLoopIndex = -1;
671 for (
auto& it : m_mapHooks) {
672 const std::string& str_hook_name = it.first;
675 if (nLoopIndex == nIndex)
return str_hook_name;
689 otErr << __FUNCTION__ <<
": Error: invalid str_HookName.\n";
693 if ((str_HookName.compare(0, 5,
"cron_") != 0) &&
694 (str_HookName.compare(0, 5,
"hook_") != 0)) {
695 otOut << __FUNCTION__ <<
": hook name MUST begin with either hook_ or "
696 "cron_ in order to be accepted: Failure."
697 " (hook name " << str_HookName <<
")\n";
701 bool bReturnVal =
false;
703 for (
auto& it : m_mapHooks) {
704 const std::string& str_hook_name = it.first;
705 const std::string& str_clause_name = it.second;
710 if (0 == (str_hook_name.compare(str_HookName))) {
713 if (
nullptr != pClause)
725 if (theResults.end() !=
726 theResults.insert(theResults.begin(),
727 std::pair<std::string, OTClause*>(
728 str_clause_name, pClause)))
732 otOut << __FUNCTION__ <<
": Couldn't find clause ("
733 << str_clause_name <<
") that was registered for hook ("
734 << str_hook_name <<
")\n";
745 const std::string str_name = theVariable.
GetName().
Get();
748 otErr <<
"OTBylaw::AddVariable: Failed due to invalid variable name. "
749 "In Bylaw: " << m_strName <<
"\n";
755 if (str_name.compare(0, 6,
"param_") == 0) {
756 otErr <<
"OTBylaw::AddVariable: Failed due to invalid variable name ("
757 << str_name <<
"). In Bylaw: " << m_strName
758 <<
". (param_ is reserved.)\n";
761 if (str_name.compare(0, 7,
"return_") == 0) {
762 otErr <<
"OTBylaw::AddVariable: Failed due to invalid variable name ("
763 << str_name <<
"). In Bylaw: " << m_strName
764 <<
". (return_ is reserved.)\n";
770 auto it = m_mapVariables.find(str_name);
774 if (m_mapVariables.end() == it)
778 m_mapVariables.insert(
779 std::pair<std::string, OTVariable*>(str_name, &theVariable));
787 otOut <<
"OTBylaw::AddVariable: Failed -- A variable was already there "
788 "named: " << str_name <<
"\n";
857 otErr <<
"OTBylaw::AddClause: Failed attempt to add a clause with a "
865 const std::string str_clause_name = theClause.
GetName().
Get();
868 otErr <<
"OTBylaw::AddClause: Failed due to invalid clause name. In "
869 "Bylaw: " << m_strName <<
"\n";
873 if (str_clause_name.compare(0, 5,
"cron_") == 0)
875 otOut <<
"OTBylaw::AddClause: Clauses may not be added with a name "
876 "beginning in cron_\n";
880 if (str_clause_name.compare(0, 5,
"hook_") == 0)
882 otOut <<
"OTBylaw::AddClause: Clauses may not be added with a name "
883 "beginning in hook_\n";
887 if (str_clause_name.compare(0, 9,
"callback_") == 0)
889 otOut <<
"OTBylaw::AddClause: Clauses may not be added with a name "
890 "beginning in callback_\n";
895 auto it = m_mapClauses.find(str_clause_name);
897 if (m_mapClauses.end() == it)
902 std::pair<std::string, OTClause*>(str_clause_name, &theClause));
910 otOut <<
"OTBylaw::AddClause: Failed -- Clause was already there named "
911 << str_clause_name <<
".\n";
918 return m_strLanguage.
Exists() ? m_strLanguage.
Get()
924 : m_pOwnerAgreement(nullptr)
929 : m_pOwnerAgreement(nullptr)
931 if (
nullptr != szName)
932 m_strName.
Set(szName);
934 otErr <<
"nullptr szName passed in to OTBylaw::OTBylaw \n";
936 if (
nullptr != szLanguage)
937 m_strLanguage = szLanguage;
939 otErr <<
"nullptr szLanguage passed in to OTBylaw::OTBylaw \n";
941 const std::string str_bylaw_name = m_strName.
Get();
942 const std::string str_language = m_strLanguage.
Get();
949 otErr <<
"Failed validation in to OTBylaw::OTBylaw \n";
957 while (!m_mapClauses.empty()) {
958 OTClause* pClause = m_mapClauses.begin()->second;
961 m_mapClauses.erase(m_mapClauses.begin());
967 while (!m_mapVariables.empty()) {
968 OTVariable* pVar = m_mapVariables.begin()->second;
971 m_mapVariables.erase(m_mapVariables.begin());
static bool ValidateName(std::string str_name)
EXPORT int32_t GetHookCount() const
EXPORT bool AddClause(OTClause &theClause)
EXPORT void RegisterForExecution(OTScript &theScript)
EXPORT OTClause * GetClauseByIndex(int32_t nIndex)
void Serialize(OTString &strAppend) const
EXPORT void RegisterVariablesForExecution(OTScript &theScript)
EXPORT OTClause * GetCallback(std::string str_CallbackName)
OTLOG_IMPORT OTLogStream otOut
void SetBylaw(OTBylaw &theBylaw)
EXPORT bool Compare(OTBylaw &rhs)
EXPORT bool GetHooks(std::string str_HookName, mapOfClauses &theResults)
EXPORT int32_t GetClauseCount() const
std::map< std::string, OTClause * > mapOfClauses
EXPORT bool IsDirty() const
EXPORT const OTString & GetName() const
EXPORT void Concatenate(const char *arg,...)
EXPORT int32_t GetCallbackCount() const
EXPORT bool Exists() const
EXPORT const std::string GetHookNameByIndex(int32_t nIndex)
EXPORT OTClause * GetClause(std::string str_Name) const
void SetBylaw(OTBylaw &theBylaw)
EXPORT const std::string GetCallbackNameByIndex(int32_t nIndex)
EXPORT const OTString & GetName() const
EXPORT bool Compare(const char *compare) const
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
void Serialize(OTString &strAppend, bool bCalculatingID=false) const
EXPORT bool AddVariable(OTVariable &theVariable)
EXPORT bool IsDirtyImportant() const
EXPORT void Serialize(OTString &strAppend, bool bCalculatingID=false) const
EXPORT OTVariable * GetVariable(std::string str_Name)
EXPORT bool AddCallback(std::string str_CallbackName, std::string str_ClauseName)
EXPORT const char * Get() const
OTLOG_IMPORT OTLogStream otErr
EXPORT const OTString & GetName() const
EXPORT const char * GetLanguage() const
EXPORT int32_t GetVariableCount() const
EXPORT bool AddHook(std::string str_HookName, std::string str_ClauseName)
bool Compare(const OTClause &rhs) const
EXPORT OTVariable * GetVariableByIndex(int32_t nIndex)
bool IsPersistent() const
bool Compare(OTVariable &rhs)