Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
opentxs::OTSettings Class Reference

#include <OTSettings.hpp>

Classes

class  OTSettingsPvt
 

Public Member Functions

EXPORT OTSettings ()
 
EXPORT OTSettings (const OTString &strConfigFilePath)
 
EXPORT ~OTSettings ()
 
EXPORT void SetConfigFilePath (const OTString &strConfigFilePath)
 
EXPORT bool Load ()
 
EXPORT bool Save ()
 
EXPORT const bool & IsLoaded () const
 
EXPORT bool Reset ()
 
EXPORT bool IsEmpty () const
 
EXPORT bool Check_str (const OTString &strSection, const OTString &strKey, OTString &out_strResult, bool &out_bKeyExist) const
 
EXPORT bool Check_long (const OTString &strSection, const OTString &strKey, int64_t &out_lResult, bool &out_bKeyExist) const
 
EXPORT bool Check_bool (const OTString &strSection, const OTString &strKey, bool &out_bResult, bool &out_bKeyExist) const
 
EXPORT bool Set_str (const OTString &strSection, const OTString &strKey, const OTString &strValue, bool &out_bNewOrUpdate, const OTString &strComment="")
 
EXPORT bool Set_long (const OTString &strSection, const OTString &strKey, const int64_t &lValue, bool &out_bNewOrUpdate, const OTString &strComment="")
 
EXPORT bool Set_bool (const OTString &strSection, const OTString &strKey, const bool &bValue, bool &out_bNewOrUpdate, const OTString &strComment="")
 
EXPORT bool CheckSetSection (const OTString &strSection, const OTString &strComment, bool &out_bIsNewSection)
 
EXPORT bool CheckSet_str (const OTString &strSection, const OTString &strKey, const OTString &strDefault, OTString &out_strResult, bool &out_bIsNew, const OTString &strComment="")
 
EXPORT bool CheckSet_long (const OTString &strSection, const OTString &strKey, const int64_t &lDefault, int64_t &out_lResult, bool &out_bIsNew, const OTString &strComment="")
 
EXPORT bool CheckSet_bool (const OTString &strSection, const OTString &strKey, const bool &bDefault, bool &out_bResult, bool &out_bIsNew, const OTString &strComment="")
 
EXPORT bool SetOption_bool (const OTString &strSection, const OTString &strKey, bool &bVariableName)
 

Detailed Description

Definition at line 141 of file OTSettings.hpp.

Constructor & Destructor Documentation

opentxs::OTSettings::OTSettings ( )

Definition at line 265 of file OTSettings.cpp.

266  : pvt(new OTSettingsPvt())
267  , b_Loaded(false)
268 {
269 }
opentxs::OTSettings::OTSettings ( const OTString strConfigFilePath)

Definition at line 247 of file OTSettings.cpp.

248  : pvt(new OTSettingsPvt())
249  , b_Loaded(false)
250  , m_strConfigurationFileExactPath(strConfigFilePath)
251 {
252  if (!m_strConfigurationFileExactPath.Exists()) {
253  otErr << __FUNCTION__ << ": Error: "
254  << "m_strConfigurationFileExactPath"
255  << " is Empty!\n";
256  OT_FAIL;
257  }
258 }
EXPORT bool Exists() const
Definition: OTString.cpp:1035
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
opentxs::OTSettings::~OTSettings ( )

Definition at line 271 of file OTSettings.cpp.

272 {
273 }

Member Function Documentation

bool opentxs::OTSettings::Check_bool ( const OTString strSection,
const OTString strKey,
bool &  out_bResult,
bool &  out_bKeyExist 
) const

Definition at line 400 of file OTSettings.cpp.

402 {
403  if (!strSection.Exists()) {
404  otErr << __FUNCTION__ << ": Error: "
405  << "strSection"
406  << " is Empty!\n";
407  OT_FAIL;
408  }
409  if (strSection.Compare("")) {
410  otErr << __FUNCTION__ << ": Error: "
411  << "strSection"
412  << " is Blank!\n";
413  OT_FAIL;
414  }
415 
416  if (!strKey.Exists()) {
417  otErr << __FUNCTION__ << ": Error: "
418  << "strKey"
419  << " is Empty!\n";
420  OT_FAIL;
421  }
422  if (strKey.Compare("")) {
423  otErr << __FUNCTION__ << ": Error: "
424  << "strKey"
425  << " is Blank!\n";
426  OT_FAIL;
427  }
428 
429  const char* szVar =
430  pvt->iniSimple.GetValue(strSection.Get(), strKey.Get(), nullptr);
431  OTString strVar(szVar);
432 
433  if (strVar.Exists() &&
434  (strVar.Compare("false") || strVar.Compare("true"))) {
435  out_bKeyExist = true;
436  if (strVar.Compare("true"))
437  out_bResult = true;
438  else
439  out_bResult = false;
440  }
441  else {
442  out_bKeyExist = false;
443  out_bResult = false;
444  }
445 
446  return true;
447 }
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTSettings::Check_long ( const OTString strSection,
const OTString strKey,
int64_t &  out_lResult,
bool &  out_bKeyExist 
) const

Definition at line 354 of file OTSettings.cpp.

356 {
357  if (!strSection.Exists()) {
358  otErr << __FUNCTION__ << ": Error: "
359  << "strSection"
360  << " is Empty!\n";
361  OT_FAIL;
362  }
363  if (strSection.Compare("")) {
364  otErr << __FUNCTION__ << ": Error: "
365  << "strSection"
366  << " is Blank!\n";
367  OT_FAIL;
368  }
369 
370  if (!strKey.Exists()) {
371  otErr << __FUNCTION__ << ": Error: "
372  << "strKey"
373  << " is Empty!\n";
374  OT_FAIL;
375  }
376  if (strKey.Compare("")) {
377  otErr << __FUNCTION__ << ": Error: "
378  << "strKey"
379  << " is Blank!\n";
380  OT_FAIL;
381  }
382 
383  const char* szVar =
384  pvt->iniSimple.GetValue(strSection.Get(), strKey.Get(), nullptr);
385  OTString strVar(szVar);
386 
387  if (strVar.Exists() && !strVar.Compare("")) {
388  out_bKeyExist = true;
389  out_lResult =
390  pvt->iniSimple.GetLongValue(strSection.Get(), strKey.Get(), 0);
391  }
392  else {
393  out_bKeyExist = false;
394  out_lResult = 0;
395  }
396 
397  return true;
398 }
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTSettings::Check_str ( const OTString strSection,
const OTString strKey,
OTString out_strResult,
bool &  out_bKeyExist 
) const

Definition at line 309 of file OTSettings.cpp.

311 {
312  if (!strSection.Exists()) {
313  otErr << __FUNCTION__ << ": Error: "
314  << "strSection"
315  << " is Empty!\n";
316  OT_FAIL;
317  }
318  if (strSection.Compare("")) {
319  otErr << __FUNCTION__ << ": Error: "
320  << "strSection"
321  << " is Blank!\n";
322  OT_FAIL;
323  }
324 
325  if (!strKey.Exists()) {
326  otErr << __FUNCTION__ << ": Error: "
327  << "strKey"
328  << " is Empty!\n";
329  OT_FAIL;
330  }
331  if (strKey.Compare("")) {
332  otErr << __FUNCTION__ << ": Error: "
333  << "strKey"
334  << " is Blank!\n";
335  OT_FAIL;
336  }
337 
338  const char* szVar =
339  pvt->iniSimple.GetValue(strSection.Get(), strKey.Get(), nullptr);
340  OTString strVar(szVar);
341 
342  if (strVar.Exists() && !strVar.Compare("")) {
343  out_bKeyExist = true;
344  out_strResult = strVar;
345  }
346  else {
347  out_bKeyExist = false;
348  out_strResult = "";
349  }
350 
351  return true;
352 }
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTSettings::CheckSet_bool ( const OTString strSection,
const OTString strKey,
const bool &  bDefault,
bool &  out_bResult,
bool &  out_bIsNew,
const OTString strComment = "" 
)

Definition at line 766 of file OTSettings.cpp.

770 {
771  if (!strSection.Exists()) {
772  otErr << __FUNCTION__ << ": Error: "
773  << "strSection"
774  << " is Empty!\n";
775  OT_FAIL;
776  }
777  if (!strKey.Exists()) {
778  otErr << __FUNCTION__ << ": Error: "
779  << "strKey"
780  << " is Empty!\n";
781  OT_FAIL;
782  }
783 
784  bool bKeyExist, bTempResult;
785  if (!Check_bool(strSection, strKey, bTempResult, bKeyExist)) return false;
786 
787  if (bKeyExist) {
788  // Already have a key, lets use it's value.
789  out_bIsNew = false;
790  out_bResult = bTempResult;
791  return true;
792  }
793  else {
794  bool bNewKeyCheck;
795  if (!Set_bool(strSection, strKey, bDefault, bNewKeyCheck, strComment))
796  return false;
797  if (bNewKeyCheck) {
798  // Success
799  out_bIsNew = true;
800  out_bResult = bDefault;
801  return true;
802  }
803  }
804 
805  // If we get here, error!
806  OT_FAIL;
807 }
EXPORT bool Set_bool(const OTString &strSection, const OTString &strKey, const bool &bValue, bool &out_bNewOrUpdate, const OTString &strComment="")
Definition: OTSettings.cpp:607
#define OT_FAIL
Definition: Assert.hpp:139
EXPORT bool Check_bool(const OTString &strSection, const OTString &strKey, bool &out_bResult, bool &out_bKeyExist) const
Definition: OTSettings.cpp:400
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTSettings::CheckSet_long ( const OTString strSection,
const OTString strKey,
const int64_t &  lDefault,
int64_t &  out_lResult,
bool &  out_bIsNew,
const OTString strComment = "" 
)

Definition at line 722 of file OTSettings.cpp.

726 {
727  if (!strSection.Exists()) {
728  otErr << __FUNCTION__ << ": Error: "
729  << "strSection"
730  << " is Empty!\n";
731  OT_FAIL;
732  }
733  if (!strKey.Exists()) {
734  otErr << __FUNCTION__ << ": Error: "
735  << "strKey"
736  << " is Empty!\n";
737  OT_FAIL;
738  }
739 
740  int64_t lTempResult;
741  bool bKeyExist;
742  if (!Check_long(strSection, strKey, lTempResult, bKeyExist)) return false;
743 
744  if (bKeyExist) {
745  // Already have a key, lets use it's value.
746  out_bIsNew = false;
747  out_lResult = lTempResult;
748  return true;
749  }
750  else {
751  bool bNewKeyCheck;
752  if (!Set_long(strSection, strKey, lDefault, bNewKeyCheck, strComment))
753  return false;
754  if (bNewKeyCheck) {
755  // Success
756  out_bIsNew = true;
757  out_lResult = lDefault;
758  return true;
759  }
760  }
761 
762  // If we get here, error!
763  OT_FAIL;
764 }
EXPORT bool Set_long(const OTString &strSection, const OTString &strKey, const int64_t &lValue, bool &out_bNewOrUpdate, const OTString &strComment="")
Definition: OTSettings.cpp:534
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
EXPORT bool Check_long(const OTString &strSection, const OTString &strKey, int64_t &out_lResult, bool &out_bKeyExist) const
Definition: OTSettings.cpp:354
bool opentxs::OTSettings::CheckSet_str ( const OTString strSection,
const OTString strKey,
const OTString strDefault,
OTString out_strResult,
bool &  out_bIsNew,
const OTString strComment = "" 
)

Definition at line 664 of file OTSettings.cpp.

669 {
670  if (!strSection.Exists()) {
671  otErr << __FUNCTION__ << ": Error: "
672  << "strSection"
673  << " is Empty!\n";
674  OT_FAIL;
675  }
676  if (!strKey.Exists()) {
677  otErr << __FUNCTION__ << ": Error: "
678  << "strKey"
679  << " is Empty!\n";
680  OT_FAIL;
681  }
682 
683  const char* const szDefault =
684  (strDefault.Exists() && !strDefault.Compare("")) ? strDefault.Get()
685  : nullptr;
686 
687  OTString strTempResult;
688  bool bKeyExist;
689  if (!Check_str(strSection, strKey, strTempResult, bKeyExist)) return false;
690 
691  if (bKeyExist) {
692  // Already have a key, lets use it's value.
693  out_bIsNew = false;
694  out_strResult = strTempResult;
695  return true;
696  }
697  else {
698  bool bNewKeyCheck;
699  if (!Set_str(strSection, strKey, strDefault, bNewKeyCheck, strComment))
700  return false;
701 
702  if (nullptr == szDefault) // The Default is to have no key.
703  {
704  // Success
705  out_bIsNew = false;
706  out_strResult = "";
707  return true;
708  }
709 
710  if (bNewKeyCheck) {
711  // Success
712  out_bIsNew = true;
713  out_strResult = strDefault;
714  return true;
715  }
716  }
717 
718  // If we get here, error!
719  OT_FAIL;
720 }
EXPORT bool Check_str(const OTString &strSection, const OTString &strKey, OTString &out_strResult, bool &out_bKeyExist) const
Definition: OTSettings.cpp:309
EXPORT bool Set_str(const OTString &strSection, const OTString &strKey, const OTString &strValue, bool &out_bNewOrUpdate, const OTString &strComment="")
Definition: OTSettings.cpp:449
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTSettings::CheckSetSection ( const OTString strSection,
const OTString strComment,
bool &  out_bIsNewSection 
)

Definition at line 628 of file OTSettings.cpp.

631 {
632  if (!strSection.Exists()) {
633  otErr << __FUNCTION__ << ": Error: "
634  << "strSection"
635  << " is Empty!\n";
636  OT_FAIL;
637  }
638  if (!strComment.Exists()) {
639  otErr << __FUNCTION__ << ": Error: "
640  << "strComment"
641  << " is Empty!\n";
642  OT_FAIL;
643  }
644 
645  const char* const szComment =
646  (strComment.Exists() && !strComment.Compare("")) ? strComment.Get()
647  : nullptr;
648 
649  const int64_t lSectionSize =
650  pvt->iniSimple.GetSectionSize(strSection.Get());
651 
652  if (1 > lSectionSize) {
653  out_bIsNewSection = true;
654  SI_Error rc = pvt->iniSimple.SetValue(strSection.Get(), nullptr,
655  nullptr, szComment, false);
656  if (0 > rc) return false;
657  }
658  else {
659  out_bIsNewSection = false;
660  }
661  return true;
662 }
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTSettings::IsEmpty ( ) const

Definition at line 304 of file OTSettings.cpp.

305 {
306  return pvt->iniSimple.IsEmpty();
307 }
const bool & opentxs::OTSettings::IsLoaded ( ) const

Definition at line 292 of file OTSettings.cpp.

293 {
294  return b_Loaded;
295 }
bool opentxs::OTSettings::Load ( )

Definition at line 275 of file OTSettings.cpp.

276 {
277  b_Loaded = false;
278 
279  if (Load(m_strConfigurationFileExactPath)) {
280  b_Loaded = true;
281  return true;
282  }
283  else
284  return false;
285 }
EXPORT bool Load()
Definition: OTSettings.cpp:275
bool opentxs::OTSettings::Reset ( )

Definition at line 297 of file OTSettings.cpp.

298 {
299  b_Loaded = false;
300  pvt->iniSimple.Reset();
301  return true;
302 }
bool opentxs::OTSettings::Save ( )

Definition at line 287 of file OTSettings.cpp.

288 {
289  return Save(m_strConfigurationFileExactPath);
290 }
EXPORT bool Save()
Definition: OTSettings.cpp:287
bool opentxs::OTSettings::Set_bool ( const OTString strSection,
const OTString strKey,
const bool &  bValue,
bool &  out_bNewOrUpdate,
const OTString strComment = "" 
)

Definition at line 607 of file OTSettings.cpp.

610 {
611  if (!strSection.Exists()) {
612  otErr << __FUNCTION__ << ": Error: "
613  << "strSection"
614  << " is Empty!\n";
615  OT_FAIL;
616  }
617  if (!strKey.Exists()) {
618  otErr << __FUNCTION__ << ": Error: "
619  << "strKey"
620  << " is Empty!\n";
621  OT_FAIL;
622  }
623  const OTString strValue(bValue ? "true" : "false");
624 
625  return Set_str(strSection, strKey, strValue, out_bNewOrUpdate, strComment);
626 }
EXPORT bool Set_str(const OTString &strSection, const OTString &strKey, const OTString &strValue, bool &out_bNewOrUpdate, const OTString &strComment="")
Definition: OTSettings.cpp:449
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTSettings::Set_long ( const OTString strSection,
const OTString strKey,
const int64_t &  lValue,
bool &  out_bNewOrUpdate,
const OTString strComment = "" 
)

Definition at line 534 of file OTSettings.cpp.

537 {
538  if (!strSection.Exists()) {
539  otErr << __FUNCTION__ << ": Error: "
540  << "strSection"
541  << " is Empty!\n";
542  OT_FAIL;
543  }
544  if (strSection.Compare("")) {
545  otErr << __FUNCTION__ << ": Error: "
546  << "strSection"
547  << " is Blank!\n";
548  OT_FAIL;
549  }
550 
551  if (!strKey.Exists()) {
552  otErr << __FUNCTION__ << ": Error: "
553  << "strKey"
554  << " is Empty!\n";
555  OT_FAIL;
556  }
557  if (strKey.Compare("")) {
558  otErr << __FUNCTION__ << ": Error: "
559  << "strKey"
560  << " is Blank!\n";
561  OT_FAIL;
562  }
563 
564  OTString strValue;
565  strValue.Format("%lld", lValue);
566 
567  const char* const szComment =
568  (strComment.Exists() && !strComment.Compare("")) ? strComment.Get()
569  : nullptr;
570 
571  OTString strOldValue, strNewValue;
572  bool bOldKeyExist, bNewKeyExist;
573 
574  // Check if Old Key exists.
575  if (!Check_str(strSection, strKey, strOldValue, bOldKeyExist)) return false;
576 
577  if (bOldKeyExist) {
578  if (strValue.Compare(strOldValue)) {
579  out_bNewOrUpdate = false;
580  return true;
581  }
582  }
583 
584  // Log to Output Setting Change
585  if (!LogChange_str(strSection, strKey, strValue)) return false;
586 
587  // Set New Value
588  SI_Error rc = pvt->iniSimple.SetLongValue(strSection.Get(), strKey.Get(),
589  lValue, szComment, false, true);
590  if (0 > rc) return false;
591 
592  // Check if the new value is the same as intended.
593  if (!Check_str(strSection, strKey, strNewValue, bNewKeyExist)) return false;
594 
595  if (bNewKeyExist) {
596  if (strValue.Compare(strNewValue)) {
597  // Success
598  out_bNewOrUpdate = true;
599  return true;
600  }
601  }
602 
603  // If we get here, error!
604  OT_FAIL;
605 }
EXPORT bool Check_str(const OTString &strSection, const OTString &strKey, OTString &out_strResult, bool &out_bKeyExist) const
Definition: OTSettings.cpp:309
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTSettings::Set_str ( const OTString strSection,
const OTString strKey,
const OTString strValue,
bool &  out_bNewOrUpdate,
const OTString strComment = "" 
)

Definition at line 449 of file OTSettings.cpp.

452 {
453  if (!strSection.Exists()) {
454  otErr << __FUNCTION__ << ": Error: "
455  << "strSection"
456  << " is Empty!\n";
457  OT_FAIL;
458  }
459  if (strSection.Compare("")) {
460  otErr << __FUNCTION__ << ": Error: "
461  << "strSection"
462  << " is Blank!\n";
463  OT_FAIL;
464  }
465 
466  if (!strKey.Exists()) {
467  otErr << __FUNCTION__ << ": Error: "
468  << "strKey"
469  << " is Empty!\n";
470  OT_FAIL;
471  }
472  if (strKey.Compare("")) {
473  otErr << __FUNCTION__ << ": Error: "
474  << "strKey"
475  << " is Blank!\n";
476  OT_FAIL;
477  }
478 
479  // if (nullptr == m_strConfigurationFileExactPath){ otErr << "%s: Error:
480  // %s is a nullptr!\n", __FUNCTION__, "p_iniSimple"); OT_FAIL; }
481 
482  const char* const szValue =
483  (strValue.Exists() && !strValue.Compare("")) ? strValue.Get() : nullptr;
484  const char* const szComment =
485  (strComment.Exists() && !strComment.Compare("")) ? strComment.Get()
486  : nullptr;
487 
488  OTString strOldValue, strNewValue;
489  bool bOldKeyExist, bNewKeyExist;
490 
491  // Check if Old Key exists.
492  if (!Check_str(strSection, strKey, strOldValue, bOldKeyExist)) return false;
493 
494  if (bOldKeyExist) {
495  if (strValue.Compare(strOldValue)) {
496  out_bNewOrUpdate = false;
497  return true;
498  }
499  }
500 
501  // Log to Output Setting Change
502  if (!LogChange_str(strSection, strKey, strValue)) return false;
503 
504  // Set New Value
505  SI_Error rc = pvt->iniSimple.SetValue(strSection.Get(), strKey.Get(),
506  szValue, szComment, true);
507  if (0 > rc) return false;
508 
509  if (nullptr == szValue) // We set the key's value to null, thus removing it.
510  {
511  if (bOldKeyExist)
512  out_bNewOrUpdate = true;
513  else
514  out_bNewOrUpdate = false;
515 
516  return true;
517  }
518 
519  // Check if the new value is the same as intended.
520  if (!Check_str(strSection, strKey, strNewValue, bNewKeyExist)) return false;
521 
522  if (bNewKeyExist) {
523  if (strValue.Compare(strNewValue)) {
524  // Success
525  out_bNewOrUpdate = true;
526  return true;
527  }
528  }
529 
530  // If we get here, error!
531  OT_FAIL;
532 }
EXPORT bool Check_str(const OTString &strSection, const OTString &strKey, OTString &out_strResult, bool &out_bKeyExist) const
Definition: OTSettings.cpp:309
#define OT_FAIL
Definition: Assert.hpp:139
OTLOG_IMPORT OTLogStream otErr
void opentxs::OTSettings::SetConfigFilePath ( const OTString strConfigFilePath)

Definition at line 260 of file OTSettings.cpp.

261 {
262  m_strConfigurationFileExactPath.Set(strConfigFilePath.Get());
263 }
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
Definition: OTString.cpp:1055
bool opentxs::OTSettings::SetOption_bool ( const OTString strSection,
const OTString strKey,
bool &  bVariableName 
)

Definition at line 809 of file OTSettings.cpp.

811 {
812  bool bNewOrUpdate;
813  return CheckSet_bool(strSection, strKey, bVariableName, bVariableName,
814  bNewOrUpdate);
815 }
EXPORT bool CheckSet_bool(const OTString &strSection, const OTString &strKey, const bool &bDefault, bool &out_bResult, bool &out_bIsNew, const OTString &strComment="")
Definition: OTSettings.cpp:766

The documentation for this class was generated from the following files: