libkeepass 0.2.0
KeePass key database importer/exporter library
Loading...
Searching...
No Matches
format.hh
Go to the documentation of this file.
1/*
2 * libkeepass - KeePass key database importer/exporter
3 * Copyright (C) 2014 Christian Kindahl
4 * Copyright (C) 2024 Dominik Krümpelmann
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
22#pragma once
23#include <ostream>
24#include <sstream>
25
32class Format {
33private:
34 std::stringstream str_;
35
36public:
38 Format(const Format& rhs) = delete;
39
41 Format& operator=(const Format& rhs) = delete;
42
44 Format() = default;
45
47 template <typename T> Format& operator<<(const T& val) {
48 str_ << val;
49 return *this;
50 }
51
53 explicit operator std::string() const { return str_.str(); }
54
56 friend std::ostream& operator<<(std::ostream& os, const Format& format) {
57 os << format.str_.str();
58 return os;
59 }
60};
Streams values into a built-in string builder.
Definition format.hh:32
Format & operator<<(const T &val)
Appends a value to the builder.
Definition format.hh:47
Format()=default
Creates an empty builder.
Format & operator=(const Format &rhs)=delete
Non-copyable.
friend std::ostream & operator<<(std::ostream &os, const Format &format)
Writes the builder's contents to an output stream.
Definition format.hh:56
Format(const Format &rhs)=delete
Non-copyable.