Flow123d  3.9.0-a1b607a85
ostream.cc
Go to the documentation of this file.
1 /*
2  Formatting library for C++ - std::ostream support
3 
4  Copyright (c) 2012 - 2016, Victor Zverovich
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without
8  modification, are permitted provided that the following conditions are met:
9 
10  1. Redistributions of source code must retain the above copyright notice, this
11  list of conditions and the following disclaimer.
12  2. Redistributions in binary form must reproduce the above copyright notice,
13  this list of conditions and the following disclaimer in the documentation
14  and/or other materials provided with the distribution.
15 
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include "system/fmt/ostream.h"
29 #include "system/fmt/printf.h"
30 
31 namespace fmt {
32 
33 namespace {
34 // Write the content of w to os.
35 void write(std::ostream &os, Writer &w) {
36  const char *data = w.data();
37  typedef internal::MakeUnsigned<std::streamsize>::Type UnsignedStreamSize;
38  UnsignedStreamSize size = w.size();
39  UnsignedStreamSize max_size =
40  internal::to_unsigned((std::numeric_limits<std::streamsize>::max)());
41  do {
42  UnsignedStreamSize n = size <= max_size ? size : max_size;
43  os.write(data, static_cast<std::streamsize>(n));
44  data += n;
45  size -= n;
46  } while (size != 0);
47 }
48 }
49 
50 FMT_FUNC void print(std::ostream &os, CStringRef format_str, ArgList args) {
51  MemoryWriter w;
52  w.write(format_str, args);
53  write(os, w);
54 }
55 
56 FMT_FUNC int fprintf(std::ostream &os, CStringRef format, ArgList args) {
57  MemoryWriter w;
58  printf(w, format, args);
59  write(os, w);
60  return static_cast<int>(w.size());
61 }
62 } // namespace fmt
ostream.h
fmt::BasicMemoryWriter
Definition: format.h:2985
fmt::fprintf
FMT_FUNC int fprintf(std::ostream &os, CStringRef format, ArgList args)
Definition: ostream.cc:56
fmt::internal::MakeUnsigned::Type
T Type
Definition: format.h:546
fmt::Writer
BasicWriter< char > Writer
Definition: format.h:376
fmt::internal::to_unsigned
MakeUnsigned< Int >::Type to_unsigned(Int value)
Definition: format.h:561
fmt::format
std::string format(CStringRef format_str, ArgList args)
Definition: format.h:3141
json_spirit::write
void write(const mValue &value, std::ostream &os, unsigned int options=0)
Definition: json_spirit_writer.cpp:33
printf.h
fmt::BasicCStringRef
Definition: format.h:512
fmt::print
FMT_API void print(std::FILE *f, CStringRef format_str, ArgList args)
Definition: format.cc:489
fmt::printf
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
Definition: printf.h:444
FMT_FUNC
#define FMT_FUNC
Definition: format.h:3799
fmt
Definition: format.cc:82
fmt::BasicWriter::write
void write(BasicCStringRef< Char > format, ArgList args)
Definition: format.h:2480
fmt::BasicWriter::size
std::size_t size() const
Definition: format.h:2427
fmt::ArgList
Definition: format.h:1329