SuperTuxKart
Loading...
Searching...
No Matches
utf_writer.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2010-2015 Marianne Gagnon
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 3
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19#ifndef HEADER_UTF_WRITER_HPP
20#define HEADER_UTF_WRITER_HPP
21
22#include "utils/string_utils.hpp"
23
24#include <irrString.h>
25
26#include <fstream>
27
35{
36 std::ofstream m_base;
37
39 bool m_wide;
40public:
41
42 UTFWriter(const char* dest, bool wide);
43 void close();
44
45 UTFWriter& operator<< (const irr::core::stringw& txt);
46 UTFWriter& operator<< (const wchar_t* txt);
47 // ------------------------------------------------------------------------
48 UTFWriter& operator<< (const char *txt)
49 {
50 if (m_wide)
51 {
52 return operator<<(irr::core::stringw(txt));
53 }
54 else
55 {
56 m_base.write((char *)txt, strlen(txt));
57 return *this;
58 }
59
60 } // operator<<(char*)
61 // ------------------------------------------------------------------------
62 UTFWriter& operator<< (const std::string &txt)
63 {
64 if (m_wide)
65 return operator<<(irr::core::stringw(txt.c_str()));
66 else
67 return operator<<(txt.c_str());
68 } // operator<<(std::string)
69 // ------------------------------------------------------------------------
70 UTFWriter& operator<< (const bool &b)
71 {
72 return operator<<(StringUtils::toString(b));
73 }
74 // ------------------------------------------------------------------------
75 template<typename T>
76 UTFWriter& operator<< (const T &t)
77 {
78 return operator<<(StringUtils::toString<T>(t));
79 } // operator<< (template)
80 // ------------------------------------------------------------------------
81 bool is_open() { return m_base.is_open(); }
82};
83
84#endif
utility class used to write wide (UTF-16 or UTF-32, depending of size of wchar_t) XML files
Definition: utf_writer.hpp:35
bool m_wide
If true, use utf-16/32 (obsolete)
Definition: utf_writer.hpp:39