Pallas Solver  0.1
C++ Global Optimization Algorithms
stringprintf.h
1 // Ceres Solver - A fast non-linear least squares minimizer
2 // Copyright 2015 Google Inc. All rights reserved.
3 // http://ceres-solver.org/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 // * Neither the name of Google Inc. nor the names of its contributors may be
14 // used to endorse or promote products derived from this software without
15 // specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Author: Sanjay Ghemawat
30 //
31 // Printf variants that place their output in a C++ string.
32 //
33 // Usage:
34 // string result = StringPrintf("%d %s\n", 10, "hello");
35 // SStringPrintf(&result, "%d %s\n", 10, "hello");
36 // StringAppendF(&result, "%d %s\n", 20, "there");
37 
38 #ifndef PALLAS_INTERNAL_STRINGPRINTF_H_
39 #define PALLAS_INTERNAL_STRINGPRINTF_H_
40 
41 #include <cstdarg>
42 #include <string>
43 
44 namespace pallas {
45  namespace internal {
46 
47 #if (defined(__GNUC__) || defined(__clang__))
48 // Tell the compiler to do printf format string checking if the compiler
49 // supports it; see the 'format' attribute in
50 // <http://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Function-Attributes.html>.
51 //
52 // N.B.: As the GCC manual states, "[s]ince non-static C++ methods
53 // have an implicit 'this' argument, the arguments of such methods
54 // should be counted from two, not one."
55 #define CERES_PRINTF_ATTRIBUTE(string_index, first_to_check) \
56  __attribute__((__format__ (__printf__, string_index, first_to_check)))
57 #define CERES_SCANF_ATTRIBUTE(string_index, first_to_check) \
58  __attribute__((__format__ (__scanf__, string_index, first_to_check)))
59 #else
60 #define CERES_PRINTF_ATTRIBUTE(string_index, first_to_check)
61 #endif
62 
63 // Return a C++ string.
64  extern std::string StringPrintf(const char* format, ...)
65  // Tell the compiler to do printf format string checking.
66  CERES_PRINTF_ATTRIBUTE(1, 2);
67 
68 // Store result into a supplied string and return it.
69  extern const std::string& SStringPrintf(std::string* dst, const char* format, ...)
70  // Tell the compiler to do printf format string checking.
71  CERES_PRINTF_ATTRIBUTE(2, 3);
72 
73 // Append result to a supplied string.
74  extern void StringAppendF(std::string* dst, const char* format, ...)
75  // Tell the compiler to do printf format string checking.
76  CERES_PRINTF_ATTRIBUTE(2, 3);
77 
78 // Lower-level routine that takes a va_list and appends to a specified string.
79 // All other routines are just convenience wrappers around it.
80  extern void StringAppendV(std::string* dst, const char* format, va_list ap);
81 
82 #undef CERES_PRINTF_ATTRIBUTE
83 
84  } // namespace internal
85 } // namespace pallas
86 
87 #endif // PALLAS_INTERNAL_STRINGPRINTF_H_
Definition: basinhopping.h:51