Commit 6128a87d authored by gabime's avatar gabime

Fix issue #300

parent 69878386
...@@ -56,13 +56,13 @@ ...@@ -56,13 +56,13 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset> <PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset> <PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
......
This diff is collapsed.
This diff is collapsed.
/* /*
Formatting library for C++ - std::ostream support Formatting library for C++ - std::ostream support
Copyright (c) 2012 - 2016, Victor Zverovich Copyright (c) 2012 - 2016, Victor Zverovich
All rights reserved. All rights reserved.
For the license information refer to format.h. For the license information refer to format.h.
*/ */
// Commented out by spdlog to use header only #include "ostream.h"
// #include "fmt/ostream.h"
namespace fmt {
namespace fmt {
namespace internal {
namespace internal { FMT_FUNC void write(std::ostream &os, Writer &w) {
FMT_FUNC void write(std::ostream &os, Writer &w) { const char *data = w.data();
const char *data = w.data(); typedef internal::MakeUnsigned<std::streamsize>::Type UnsignedStreamSize;
typedef internal::MakeUnsigned<std::streamsize>::Type UnsignedStreamSize; UnsignedStreamSize size = w.size();
UnsignedStreamSize size = w.size(); UnsignedStreamSize max_size =
UnsignedStreamSize max_size = internal::to_unsigned((std::numeric_limits<std::streamsize>::max)());
internal::to_unsigned((std::numeric_limits<std::streamsize>::max)()); do {
do { UnsignedStreamSize n = size <= max_size ? size : max_size;
UnsignedStreamSize n = size <= max_size ? size : max_size; os.write(data, static_cast<std::streamsize>(n));
os.write(data, static_cast<std::streamsize>(n)); data += n;
data += n; size -= n;
size -= n; } while (size != 0);
} while (size != 0); }
} }
}
FMT_FUNC void print(std::ostream &os, CStringRef format_str, ArgList args) {
FMT_FUNC void print(std::ostream &os, CStringRef format_str, ArgList args) { MemoryWriter w;
MemoryWriter w; w.write(format_str, args);
w.write(format_str, args); internal::write(os, w);
internal::write(os, w); }
} } // namespace fmt
} // namespace fmt \ No newline at end of file
/* /*
Formatting library for C++ - std::ostream support Formatting library for C++ - std::ostream support
Copyright (c) 2012 - 2016, Victor Zverovich Copyright (c) 2012 - 2016, Victor Zverovich
All rights reserved. All rights reserved.
For the license information refer to format.h. For the license information refer to format.h.
*/ */
#ifndef FMT_OSTREAM_H_ #ifndef FMT_OSTREAM_H_
#define FMT_OSTREAM_H_ #define FMT_OSTREAM_H_
// Commented out by spdlog to use header only // commented out by spdlog
// #include "fmt/format.h" //#include "format.h"
#include <ostream> #include <ostream>
namespace fmt namespace fmt {
{
namespace internal {
namespace internal
{ template <class Char>
class FormatBuf : public std::basic_streambuf<Char> {
template <class Char> private:
class FormatBuf : public std::basic_streambuf<Char> typedef typename std::basic_streambuf<Char>::int_type int_type;
{ typedef typename std::basic_streambuf<Char>::traits_type traits_type;
private:
typedef typename std::basic_streambuf<Char>::int_type int_type; Buffer<Char> &buffer_;
typedef typename std::basic_streambuf<Char>::traits_type traits_type; Char *start_;
Buffer<Char> &buffer_; public:
Char *start_; FormatBuf(Buffer<Char> &buffer) : buffer_(buffer), start_(&buffer[0]) {
this->setp(start_, start_ + buffer_.capacity());
public: }
FormatBuf(Buffer<Char> &buffer) : buffer_(buffer), start_(&buffer[0])
{ int_type overflow(int_type ch = traits_type::eof()) {
this->setp(start_, start_ + buffer_.capacity()); if (!traits_type::eq_int_type(ch, traits_type::eof())) {
} size_t buf_size = size();
buffer_.resize(buf_size);
int_type overflow(int_type ch = traits_type::eof()) buffer_.reserve(buf_size * 2);
{
if (!traits_type::eq_int_type(ch, traits_type::eof())) start_ = &buffer_[0];
{ start_[buf_size] = traits_type::to_char_type(ch);
size_t buf_size = size(); this->setp(start_ + buf_size + 1, start_ + buf_size * 2);
buffer_.resize(buf_size); }
buffer_.reserve(buf_size * 2); return ch;
}
start_ = &buffer_[0];
start_[buf_size] = traits_type::to_char_type(ch); size_t size() const {
this->setp(start_+ buf_size + 1, start_ + buf_size * 2); return to_unsigned(this->pptr() - start_);
} }
return ch; };
}
Yes &convert(std::ostream &);
size_t size() const
{ struct DummyStream : std::ostream {
return to_unsigned(this->pptr() - start_); DummyStream(); // Suppress a bogus warning in MSVC.
} // Hide all operator<< overloads from std::ostream.
}; void operator<<(Null<>);
};
Yes &convert(std::ostream &);
No &operator<<(std::ostream &, int);
struct DummyStream : std::ostream
{ template<typename T>
DummyStream(); // Suppress a bogus warning in MSVC. struct ConvertToIntImpl<T, true> {
// Hide all operator<< overloads from std::ostream. // Convert to int only if T doesn't have an overloaded operator<<.
void operator<<(Null<>); enum {
}; value = sizeof(convert(get<DummyStream>() << get<T>())) == sizeof(No)
};
No &operator<<(std::ostream &, int); };
template<typename T> // Write the content of w to os.
struct ConvertToIntImpl<T, true> void write(std::ostream &os, Writer &w);
{ } // namespace internal
// Convert to int only if T doesn't have an overloaded operator<<.
enum // Formats a value.
{ template <typename Char, typename ArgFormatter, typename T>
value = sizeof(convert(get<DummyStream>() << get<T>())) == sizeof(No) void format_arg(BasicFormatter<Char, ArgFormatter> &f,
}; const Char *&format_str, const T &value) {
}; internal::MemoryBuffer<Char, internal::INLINE_BUFFER_SIZE> buffer;
// Write the content of w to os. internal::FormatBuf<Char> format_buf(buffer);
void write(std::ostream &os, Writer &w); std::basic_ostream<Char> output(&format_buf);
} // namespace internal output << value;
// Formats a value. BasicStringRef<Char> str(&buffer[0], format_buf.size());
template <typename Char, typename ArgFormatter, typename T> typedef internal::MakeArg< BasicFormatter<Char> > MakeArg;
void format_arg(BasicFormatter<Char, ArgFormatter> &f, format_str = f.format(format_str, MakeArg(str));
const Char *&format_str, const T &value) }
{
internal::MemoryBuffer<Char, internal::INLINE_BUFFER_SIZE> buffer; /**
\rst
internal::FormatBuf<Char> format_buf(buffer); Prints formatted data to the stream *os*.
std::basic_ostream<Char> output(&format_buf);
output << value; **Example**::
BasicStringRef<Char> str(&buffer[0], format_buf.size()); print(cerr, "Don't {}!", "panic");
typedef internal::MakeArg< BasicFormatter<Char> > MakeArg; \endrst
format_str = f.format(format_str, MakeArg(str)); */
} FMT_API void print(std::ostream &os, CStringRef format_str, ArgList args);
FMT_VARIADIC(void, print, std::ostream &, CStringRef)
/** } // namespace fmt
\rst
Prints formatted data to the stream *os*. #ifdef FMT_HEADER_ONLY
# include "ostream.cc"
**Example**:: #endif
print(cerr, "Don't {}!", "panic"); #endif // FMT_OSTREAM_H_
\endrst \ No newline at end of file
*/
FMT_API void print(std::ostream &os, CStringRef format_str, ArgList args);
FMT_VARIADIC(void, print, std::ostream &, CStringRef)
} // namespace fmt
#ifdef FMT_HEADER_ONLY
# include "ostream.cc"
#endif
#endif // FMT_OSTREAM_H_
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment