NGL  6.5
The NCCA Graphics Library
string.h
Go to the documentation of this file.
1 /*
2  Formatting library for C++ - string utilities
3 
4  Copyright (c) 2012 - 2016, Victor Zverovich
5  All rights reserved.
6 
7  For the license information refer to format.h.
8  */
9 
10 #ifndef FMT_STRING_H_
11 #define FMT_STRING_H_
12 
13 #include "fmt/format.h"
14 
15 namespace fmt {
16 
17 namespace internal {
18 
19 // A buffer that stores data in ``std::string``.
20 template <typename Char>
21 class StringBuffer : public Buffer<Char> {
22  private:
23  std::basic_string<Char> data_;
24 
25  protected:
26  virtual void grow(std::size_t size) {
27  data_.resize(size);
28  this->ptr_ = &data_[0];
29  this->capacity_ = size;
30  }
31 
32  public:
33  // Moves the data to ``str`` clearing the buffer.
34  void move_to(std::basic_string<Char> &str) {
35  data_.resize(this->size_);
36  str.swap(data_);
37  this->capacity_ = this->size_ = 0;
38  this->ptr_ = 0;
39  }
40 };
41 } // namespace internal
42 
74 template <typename Char>
75 class BasicStringWriter : public BasicWriter<Char> {
76  private:
78 
79  public:
85  BasicStringWriter() : BasicWriter<Char>(buffer_) {}
86 
92  void move_to(std::basic_string<Char> &str) {
93  buffer_.move_to(str);
94  }
95 };
96 
99 
111 template <typename T>
114  w << value;
115  return w.str();
116 }
117 }
118 
119 #endif // FMT_STRING_H_
void move_to(std::basic_string< Char > &str)
Definition: string.h:92
GLsizei const GLfloat * value
Definition: glew.h:1852
std::size_t size_
Definition: format.h:597
std::string to_string(const T &value)
Definition: string.h:112
void move_to(std::basic_string< Char > &str)
Definition: string.h:34
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1893
std::basic_string< Char > data_
Definition: string.h:23
internal::StringBuffer< Char > buffer_
Definition: string.h:77
BasicStringWriter< wchar_t > WStringWriter
Definition: string.h:98
GLsizeiptr size
Definition: glew.h:1684
BasicStringWriter< char > StringWriter
Definition: string.h:97
std::size_t capacity_
Definition: format.h:598
virtual void grow(std::size_t size)
Definition: string.h:26
Definition: format.cc:82
std::size_t size() const
Definition: format.h:615
std::basic_string< Char > str() const
Definition: format.h:2486
GLsizei const GLchar *const * string
Definition: glew.h:1847