1 /**
2  * @file str.hh
3  * C++ wrapper for Str (ddstring_t).
4  *
5  * @authors Copyright © 2012-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
6  *
7  * @par License
8  * GPL: http://www.gnu.org/licenses/gpl.html
9  *
10  * <small>This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by the
12  * Free Software Foundation; either version 2 of the License, or (at your
13  * option) any later version. This program is distributed in the hope that it
14  * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details. You should have received a copy of the GNU
17  * General Public License along with this program; if not, write to the Free
18  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19  * 02110-1301 USA</small>
20  */
21 
22 #ifndef LIBDENG_DDSTRING_CPP_WRAPPER_HH
23 #define LIBDENG_DDSTRING_CPP_WRAPPER_HH
24 
25 #include "liblegacy.h"
26 #include "str.h"
27 
28 #include <QString>
29 
30 namespace de {
31 
32 /**
33  * Minimal C++ wrapper for ddstring_t. @ingroup legacyData
34  */
35 class Str {
36 public:
Str(const char * text=0)37     Str(const char *text = 0) {
38         Str_InitStd(&str);
39         if (text) {
40             Str_Set(&str, text);
41         }
42     }
Str(const QString & text)43     Str(const QString &text) {
44         Str_InitStd(&str);
45         Str_Set(&str, text.toUtf8());
46     }
~Str()47     ~Str() {
48         // This should never be called directly.
49         Str_Free(&str);
50     }
operator const char*(void) const51     operator const char *(void) const {
52         return str.str;
53     }
operator ddstring_t*(void)54     operator ddstring_t *(void) {
55         return &str;
56     }
operator const ddstring_t*(void) const57     operator const ddstring_t *(void) const {
58         return &str;
59     }
60 private:
61     ddstring_t str;
62 };
63 
64 } // namespace de
65 
66 #endif // LIBDENG_DDSTRING_CPP_WRAPPER_HH
67