cmCursesCacheEntryComposite.cxx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCursesCacheEntryComposite.h"
  14. #include "cmCursesStringWidget.h"
  15. #include "cmCursesLabelWidget.h"
  16. #include "cmCursesBoolWidget.h"
  17. #include "cmCursesPathWidget.h"
  18. #include "cmCursesFilePathWidget.h"
  19. #include "cmCursesDummyWidget.h"
  20. #include "../cmSystemTools.h"
  21. cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(const char* key,
  22. int labelwidth,
  23. int entrywidth) :
  24. m_Key(key), m_LabelWidth(labelwidth), m_EntryWidth(entrywidth)
  25. {
  26. m_Label = new cmCursesLabelWidget(m_LabelWidth, 1, 1, 1, key);
  27. m_IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
  28. m_Entry = 0;
  29. }
  30. cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
  31. const char* key, const cmCacheManager::CacheEntry& value, bool isNew,
  32. int labelwidth, int entrywidth)
  33. : m_Key(key), m_LabelWidth(labelwidth), m_EntryWidth(entrywidth)
  34. {
  35. m_Label = new cmCursesLabelWidget(m_LabelWidth, 1, 1, 1, key);
  36. if (isNew)
  37. {
  38. m_IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, "*");
  39. }
  40. else
  41. {
  42. m_IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
  43. }
  44. m_Entry = 0;
  45. switch ( value.m_Type )
  46. {
  47. case cmCacheManager::BOOL:
  48. m_Entry = new cmCursesBoolWidget(m_EntryWidth, 1, 1, 1);
  49. if (cmSystemTools::IsOn(value.m_Value.c_str()))
  50. {
  51. static_cast<cmCursesBoolWidget*>(m_Entry)->SetValueAsBool(true);
  52. }
  53. else
  54. {
  55. static_cast<cmCursesBoolWidget*>(m_Entry)->SetValueAsBool(false);
  56. }
  57. break;
  58. case cmCacheManager::PATH:
  59. m_Entry = new cmCursesPathWidget(m_EntryWidth, 1, 1, 1);
  60. static_cast<cmCursesPathWidget*>(m_Entry)->SetString(
  61. value.m_Value.c_str());
  62. break;
  63. case cmCacheManager::FILEPATH:
  64. m_Entry = new cmCursesFilePathWidget(m_EntryWidth, 1, 1, 1);
  65. static_cast<cmCursesFilePathWidget*>(m_Entry)->SetString(
  66. value.m_Value.c_str());
  67. break;
  68. case cmCacheManager::STRING:
  69. m_Entry = new cmCursesStringWidget(m_EntryWidth, 1, 1, 1);
  70. static_cast<cmCursesStringWidget*>(m_Entry)->SetString(
  71. value.m_Value.c_str());
  72. break;
  73. default:
  74. // TODO : put warning message here
  75. break;
  76. }
  77. }
  78. cmCursesCacheEntryComposite::~cmCursesCacheEntryComposite()
  79. {
  80. delete m_Label;
  81. delete m_IsNewLabel;
  82. delete m_Entry;
  83. }
  84. const char* cmCursesCacheEntryComposite::GetValue()
  85. {
  86. if (m_Label)
  87. {
  88. return m_Label->GetValue();
  89. }
  90. else
  91. {
  92. return 0;
  93. }
  94. }