PageRenderTime 52ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/cv/of_preRelease_v0062_osxSL_FAT/libs/poco/include/Poco/Format.h

https://bitbucket.org/shamid/kinect-wallboards/
C Header | 157 lines | 21 code | 18 blank | 118 comment | 0 complexity | 292f0bb91a00114f17799965ec17bbc3 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0, BSD-3-Clause
  1. //
  2. // Format.h
  3. //
  4. // $Id: //poco/1.3/Foundation/include/Poco/Format.h#5 $
  5. //
  6. // Library: Foundation
  7. // Package: Core
  8. // Module: Format
  9. //
  10. // Definition of the format freestanding function.
  11. //
  12. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
  13. // All rights reserved.
  14. //
  15. // Redistribution and use in source and binary forms, with or without
  16. // modification, are permitted provided that the following conditions
  17. // are met:
  18. //
  19. // 1. Redistributions of source code must retain the above copyright
  20. // notice, this list of conditions and the following disclaimer.
  21. //
  22. // 2. Redistributions in binary form must reproduce the above copyright
  23. // notice, this list of conditions and the following disclaimer in the
  24. // documentation and/or other materials provided with the distribution.
  25. //
  26. // 3. Redistributions in any form must be accompanied by information on
  27. // how to obtain complete source code for this software and any
  28. // accompanying software that uses this software. The source code
  29. // must either be included in the distribution or be available for no
  30. // more than the cost of distribution plus a nominal fee, and must be
  31. // freely redistributable under reasonable conditions. For an
  32. // executable file, complete source code means the source code for all
  33. // modules it contains. It does not include source code for modules or
  34. // files that typically accompany the major components of the operating
  35. // system on which the executable file runs.
  36. //
  37. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  38. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  39. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  40. // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  41. // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  42. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  43. // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  44. // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  45. // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  46. // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  47. // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  48. // POSSIBILITY OF SUCH DAMAGE.
  49. //
  50. #ifndef Foundation_Format_INCLUDED
  51. #define Foundation_Format_INCLUDED
  52. #include "Poco/Foundation.h"
  53. #include "Poco/Any.h"
  54. #include <vector>
  55. namespace Poco {
  56. std::string Foundation_API format(const std::string& fmt, const Any& value);
  57. /// This function implements sprintf-style formatting in a typesafe way.
  58. /// Various variants of the function are available, supporting a
  59. /// different number of arguments (up to six).
  60. ///
  61. /// The formatting is controlled by the format string in fmt.
  62. /// Format strings are quite similar to those of the std::printf() function, but
  63. /// there are some minor differences.
  64. ///
  65. /// The format string can consist of any sequence of characters; certain
  66. /// characters have a special meaning. Characters without a special meaning
  67. /// are copied verbatim to the result. A percent sign (%) marks the beginning
  68. /// of a format specification. Format specifications have the following syntax:
  69. ///
  70. /// %[<flags>][<width>][.<precision>][<modifier>]<type>
  71. ///
  72. /// Flags, width, precision and prefix are optional. The only required part of
  73. /// the format specification, apart from the percent sign, is the type.
  74. ///
  75. /// Following are valid type specifications and their meaning:
  76. ///
  77. /// * b boolean (true = 1, false = 0)
  78. /// * c character
  79. /// * d signed decimal integer
  80. /// * i signed decimal integer
  81. /// * o unsigned octal integer
  82. /// * u unsigned decimal integer
  83. /// * x unsigned hexadecimal integer (lower case)
  84. /// * X unsigned hexadecimal integer (upper case)
  85. /// * e signed floating-point value in the form [-]d.dddde[<sign>]dd[d]
  86. /// * E signed floating-point value in the form [-]d.ddddE[<sign>]dd[d]
  87. /// * f signed floating-point value in the form [-]dddd.dddd
  88. /// * s std::string
  89. /// * z std::size_t
  90. ///
  91. /// The following flags are supported:
  92. ///
  93. /// * - left align the result within the given field width
  94. /// * + prefix the output value with a sign (+ or –) if the output value is of a signed type
  95. /// * 0 if width is prefixed with 0, zeros are added until the minimum width is reached
  96. /// * # For o, x, X, the # flag prefixes any nonzero output value with 0, 0x, or 0X, respectively;
  97. /// for e, E, f, the # flag forces the output value to contain a decimal point in all cases.
  98. ///
  99. /// The following modifiers are supported:
  100. ///
  101. /// * (none) argument is char (c), int (d, i), unsigned (o, u, x, X) double (e, E, f, g, G) or string (s)
  102. /// * l argument is long (d, i), unsigned long (o, u, x, X) or long double (e, E, f, g, G)
  103. /// * L argument is long long (d, i), unsigned long long (o, u, x, X)
  104. /// * h argument is short (d, i), unsigned short (o, u, x, X) or float (e, E, f, g, G)
  105. /// * ? argument is any signed or unsigned int, short, long, or 64-bit integer (d, i, o, x, X)
  106. ///
  107. /// The width argument is a nonnegative decimal integer controlling the minimum number of characters printed.
  108. /// If the number of characters in the output value is less than the specified width, blanks or
  109. /// leading zeros are added, according to the specified flags (-, +, 0).
  110. ///
  111. /// Precision is a nonnegative decimal integer, preceded by a period (.), which specifies the number of characters
  112. /// to be printed, the number of decimal places, or the number of significant digits.
  113. ///
  114. /// Throws a BadCastException if an argument does not correspond to the type of its format specification.
  115. ///
  116. /// If there are more format specifiers than values, the format specifiers without a corresponding value
  117. /// are copied verbatim to output.
  118. ///
  119. /// If there are more values than format specifiers, the superfluous values are ignored.
  120. ///
  121. /// Usage Example:
  122. /// std::string s = format("The answer to life, the universe, and everything is %d", 42);
  123. std::string Foundation_API format(const std::string& fmt, const Any& value1, const Any& value2);
  124. std::string Foundation_API format(const std::string& fmt, const Any& value1, const Any& value2, const Any& value3);
  125. std::string Foundation_API format(const std::string& fmt, const Any& value1, const Any& value2, const Any& value3, const Any& value4);
  126. std::string Foundation_API format(const std::string& fmt, const Any& value1, const Any& value2, const Any& value3, const Any& value4, const Any& value5);
  127. std::string Foundation_API format(const std::string& fmt, const Any& value1, const Any& value2, const Any& value3, const Any& value4, const Any& value5, const Any& value6);
  128. void Foundation_API format(std::string& result, const std::string& fmt, const Any& value);
  129. /// Appends the formatted string to result.
  130. void Foundation_API format(std::string& result, const std::string& fmt, const Any& value1, const Any& value2);
  131. void Foundation_API format(std::string& result, const std::string& fmt, const Any& value1, const Any& value2, const Any& value3);
  132. void Foundation_API format(std::string& result, const std::string& fmt, const Any& value1, const Any& value2, const Any& value3, const Any& value4);
  133. void Foundation_API format(std::string& result, const std::string& fmt, const Any& value1, const Any& value2, const Any& value3, const Any& value4, const Any& value5);
  134. void Foundation_API format(std::string& result, const std::string& fmt, const Any& value1, const Any& value2, const Any& value3, const Any& value4, const Any& value5, const Any& value6);
  135. void Foundation_API format(std::string& result, const std::string& fmt, const std::vector<Any>& values);
  136. /// Supports a variable number of arguments and is used by
  137. /// all other variants of format().
  138. } // namespace Poco
  139. #endif // Foundation_Format_INCLUDED