format_class.hpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // format_class.hpp : class interface
3 // ----------------------------------------------------------------------------
4 
5 // Copyright Samuel Krempp 2003. Use, modification, and distribution are
6 // subject to the Boost Software License, Version 1.0. (See accompanying
7 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 
9 // See http://www.boost.org/libs/format for library home page
10 
11 // ----------------------------------------------------------------------------
12 
13 #ifndef BOOST_FORMAT_CLASS_HPP
14 #define BOOST_FORMAT_CLASS_HPP
15 
16 
17 #include <vector>
18 #include <string>
19 
20 #include <boost/optional.hpp> // to store locale when needed
21 
26 
27 namespace boost {
28 
29  template<class Ch, class Tr, class Alloc>
30  class basic_format
31  {
33  public:
34  typedef Ch CharT; // borland fails in operator% if we use Ch and Tr directly
35  typedef std::basic_string<Ch, Tr, Alloc> string_type;
36  typedef typename string_type::size_type size_type;
39 
40 
41  explicit basic_format(const Ch* str=NULL);
42  explicit basic_format(const string_type& s);
43  basic_format(const basic_format& x);
45  void swap(basic_format& x);
46 
47 #if !defined(BOOST_NO_STD_LOCALE)
48  explicit basic_format(const Ch* str, const std::locale & loc);
49  explicit basic_format(const string_type& s, const std::locale & loc);
50 #endif
52 
53  basic_format& clear(); // empty all converted string buffers (except bound items)
54  basic_format& clear_binds(); // unbind all bound items, and call clear()
55  basic_format& parse(const string_type&); // resets buffers and parse a new format string
56 
57  // ** formatted result ** //
58  size_type size() const; // sum of the current string pieces sizes
59  string_type str() const; // final string
60 
61  // ** arguments passing ** //
62  template<class T>
64  { return io::detail::feed<CharT, Tr, Alloc, const T&>(*this,x); }
65 
66 #ifndef BOOST_NO_OVERLOAD_FOR_NON_CONST
67  template<class T> basic_format& operator%(T& x)
68  { return io::detail::feed<CharT, Tr, Alloc, T&>(*this,x); }
69 #endif
70 
71 #if defined(__GNUC__)
72  // GCC can't handle anonymous enums without some help
73  // ** arguments passing ** //
74  basic_format& operator%(const int& x)
75  { return io::detail::feed<CharT, Tr, Alloc, const int&>(*this,x); }
76 
77 #ifndef BOOST_NO_OVERLOAD_FOR_NON_CONST
78  basic_format& operator%(int& x)
79  { return io::detail::feed<CharT, Tr, Alloc, int&>(*this,x); }
80 #endif
81 #endif
82 
83  // The total number of arguments expected to be passed to the format objectt
84  int expected_args() const
85  { return num_args_; }
86  // The number of arguments currently bound (see bind_arg(..) )
87  int bound_args() const;
88  // The number of arguments currently fed to the format object
89  int fed_args() const;
90  // The index (1-based) of the current argument (i.e. next to be formatted)
91  int cur_arg() const;
92  // The number of arguments still required to be fed
93  int remaining_args() const; // same as expected_args() - bound_args() - fed_args()
94 
95 
96  // ** object modifying **//
97  template<class T>
98  basic_format& bind_arg(int argN, const T& val)
99  { return io::detail::bind_arg_body(*this, argN, val); }
100  basic_format& clear_bind(int argN);
101  template<class T>
102  basic_format& modify_item(int itemN, T manipulator)
103  { return io::detail::modify_item_body<Ch,Tr, Alloc, T> (*this, itemN, manipulator);}
104 
105  // Choosing which errors will throw exceptions :
106  unsigned char exceptions() const;
107  unsigned char exceptions(unsigned char newexcept);
108 
109 #if !defined( BOOST_NO_MEMBER_TEMPLATE_FRIENDS ) \
110  && !BOOST_WORKAROUND(__BORLANDC__, <= 0x570) \
111  && !BOOST_WORKAROUND( _CRAYC, != 0) \
112  && !BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590042))
113  // use friend templates and private members only if supported
114 
115 #ifndef BOOST_NO_TEMPLATE_STD_STREAM
116  template<class Ch2, class Tr2, class Alloc2>
117  friend std::basic_ostream<Ch2, Tr2> &
118  operator<<( std::basic_ostream<Ch2, Tr2> & ,
120 #else
121  template<class Ch2, class Tr2, class Alloc2>
122  friend std::ostream &
123  operator<<( std::ostream & ,
125 #endif
126 
127  template<class Ch2, class Tr2, class Alloc2, class T>
130 
131  template<class Ch2, class Tr2, class Alloc2, class T> friend
133 
134  template<class Ch2, class Tr2, class Alloc2, class T> friend
137 
138  template<class Ch2, class Tr2, class Alloc2, class T> friend
141 
142  private:
143 #endif
145  // flag bits, used for style_
146  enum style_values { ordered = 1, // set only if all directives are positional
148 
149  void make_or_reuse_data(std::size_t nbitems);// used for (re-)initialisation
150 
151  // member data --------------------------------------------//
152  std::vector<format_item_t> items_; // each '%..' directive leads to a format_item
153  std::vector<bool> bound_; // stores which arguments were bound. size() == 0 || num_args
154 
155  int style_; // style of format-string : positional or not, etc
156  int cur_arg_; // keep track of wich argument is current
157  int num_args_; // number of expected arguments
158  mutable bool dumped_; // true only after call to str() or <<
159  string_type prefix_; // piece of string to insert before first item
160  unsigned char exceptions_;
161  internal_streambuf_t buf_; // the internal stream buffer.
163  }; // class basic_format
164 
165 } // namespace boost
166 
167 
168 #endif // BOOST_FORMAT_CLASS_HPP
io::CompatTraits< Tr >::compatible_type compat_traits
basic_format & bind_arg(int argN, const T &val)
boost::optional< io::detail::locale_t > loc_
basic_format & clear_bind(int argN)
basic_format & modify_item(int itemN, T manipulator)
unsigned char exceptions() const
io::detail::format_item< Ch, Tr, Alloc > format_item_t
BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE.
GLdouble s
std::vector< bool > bound_
basic_format & operator%(T &x)
basic_format< Ch, Tr, Alloc > & bind_arg_body(basic_format< Ch, Tr, Alloc > &self, int argN, const T &val)
std::vector< format_item_t > items_
unsigned char exceptions_
GLuint GLfloat * val
internal_streambuf_t buf_
GLdouble x
basic_format & operator%(const T &x)
basic_format & operator=(const basic_format &x)
basic_format< Ch, Tr, Alloc > & feed_impl(basic_format< Ch, Tr, Alloc > &self, T x)
Definition: feed_args.hpp:293
string_type str() const
string_type::size_type size_type
io::detail::stream_format_state< Ch, Tr > stream_format_state
void distribute(basic_format< Ch, Tr, Alloc > &self, T x)
Definition: feed_args.hpp:276
friend std::basic_ostream< Ch2, Tr2 > & operator<<(std::basic_ostream< Ch2, Tr2 > &, const basic_format< Ch2, Tr2, Alloc2 > &)
io::detail::locale_t getloc() const
std::basic_string< Ch, Tr, Alloc > string_type
void make_or_reuse_data(std::size_t nbitems)
basic_format< Ch, Tr, Alloc > & modify_item_body(basic_format< Ch, Tr, Alloc > &self, int itemN, T manipulator)
BOOST_IO_STD locale locale_t
int expected_args() const
#define NULL
Definition: tinycthread.c:47
basic_format & parse(const string_type &)
Definition: parsing.hpp:406
void swap(basic_format &x)
io::basic_altstringbuf< Ch, Tr, Alloc > internal_streambuf_t
basic_format(const Ch *str=NULL)


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:14