optionconverter.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /******************************************************************************
  2. *
  3. * package: Log4Qt
  4. * file: optionconverter.h
  5. * created: September 2007
  6. * author: Martin Heinrich
  7. *
  8. *
  9. * Copyright 2007 Martin Heinrich
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. *
  23. ******************************************************************************/
  24. #ifndef LOG4QT_OPTIONCONVERTER_H
  25. #define LOG4QT_OPTIONCONVERTER_H
  26. /******************************************************************************
  27. * Dependencies
  28. ******************************************************************************/
  29. #include <QtCore/QString>
  30. #include "log4qt/level.h"
  31. namespace Log4Qt
  32. {
  33. class Properties;
  34. /*!
  35. * \brief The class OptionConverter provides functions to convert strings
  36. * to property values.
  37. */
  38. class OptionConverter
  39. {
  40. private:
  41. OptionConverter();
  42. OptionConverter(const OptionConverter &rOther); // Not implemented
  43. // virtual ~OptionConverter(); // Use compiler default
  44. OptionConverter &operator=(const OptionConverter &rOther); // Not implemented
  45. public:
  46. static QString findAndSubst(const Properties &rProperties,
  47. const QString &rKey);
  48. /*!
  49. * Returns the JAVA class name \a rClassName as C++ class name by
  50. * replacing all . characters with ::.
  51. */
  52. static QString classNameJavaToCpp(const QString &rClassName);
  53. /*!
  54. * Converts the option \a rOption to a boolean value. Valid strings
  55. * for true are "true", "enabled" and "1". Valid strings
  56. * for false are "false", "disabled" and "0". If the conversion is
  57. * successful, the target is returned and \a p_ok is set to true.
  58. * Otherwise an error is written to the log, \a p_ok is set to false
  59. * and false is returned.
  60. */
  61. static bool toBoolean(const QString &rOption,
  62. bool *p_ok = 0);
  63. static bool toBoolean(const QString &rOption,
  64. bool default_value);
  65. /*!
  66. * Converts the option string \a rOption to a file size. The string can
  67. * be a positive integer followed by an optional unit suffix "KB", "MB"
  68. * or "GB". If a unit suffix is specified the the integer is
  69. * interpreted as kilobytes, megabytes or gigabytes. If the conversion
  70. * is successful, the size is returned and \a p_ok is set to true.
  71. * Otherwise an error is written to the log, \a p_ok is set to false
  72. * and 0 is returned.
  73. */
  74. static qint64 toFileSize(const QString &rOption,
  75. bool *p_ok = 0);
  76. /*!
  77. * Converts the option \a rOption to a integer value using
  78. * QString::toInt(). If the conversion is successful, the integer is
  79. * returned and \a p_ok is set to true. Otherwise an error is written
  80. * to the log, \a p_ok is set to false and 0 is returned.
  81. */
  82. static int toInt(const QString &rOption,
  83. bool *p_ok = 0);
  84. /*!
  85. * Converts the option \a rOption to a qint64 value using
  86. * QString::toLongLong(). If the conversion is successful, the qint64 is
  87. * returned and \a p_ok is set to true. Otherwise an error is written
  88. * to the log, \a p_ok is set to false and 0 is returned.
  89. */
  90. static qint64 toQInt64(const QString &rOption,
  91. bool *p_ok = 0);
  92. /*!
  93. * Converts the option \a rOption to a level value using
  94. * Level::fromString(). If the conversion is successful, the level
  95. * is returned and \a p_ok is set to true. Otherwise an error is
  96. * written to the log, \a p_ok is set to false and a level with
  97. * the value Level::NULL_INT is returned.
  98. *
  99. * \sa Level::fromString()
  100. */
  101. static Level toLevel(const QString &rOption,
  102. bool *p_ok = 0);
  103. static Level toLevel(const QString &rOption,
  104. const Level &rDefaultValue);
  105. /*!
  106. * Converts the option \a rOption to a ConsoleAppender::Target value.
  107. * Valid strings for \a rOption are "System.out", "STDOUT_TARGET",
  108. * "System.err" and "STDERR_TARGET". If the conversion is successful,
  109. * the target is returned and \a p_ok is set to true. Otherwise an
  110. * error is written to the log, \a p_ok is set to false and
  111. * ConsoleAppender::STDOUT_TARGET is returned.
  112. */
  113. static int toTarget(const QString &rOption,
  114. bool *p_ok = 0);
  115. };
  116. /**************************************************************************
  117. * Operators, Helper
  118. **************************************************************************/
  119. /**************************************************************************
  120. * Inline
  121. **************************************************************************/
  122. } // namespace Log4Qt
  123. Q_DECLARE_TYPEINFO(Log4Qt::OptionConverter, Q_MOVABLE_TYPE);
  124. #endif // LOG4QT_OPTIONCONVERTER_H