~ubuntu-branches/ubuntu/trusty/hugin/trusty-proposed

« back to all changes in this revision

Viewing changes to src/hugin_base/makefilelib/StringAdapter.h

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Metzler
  • Date: 2011-01-06 14:28:24 UTC
  • mfrom: (1.1.9 upstream) (0.1.21 experimental)
  • Revision ID: james.westby@ubuntu.com-20110106142824-zn9lxylg5z44dynn
* Drop Cyril Brulebois from Uploaders. Thank you very much for your work.
* Bump package version. (rc3 was re-released as 2010.4.0).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
This file is part of hugin.
 
3
 
 
4
hugin is free software: you can redistribute it and/or modify
 
5
it under the terms of the GNU General Public License as published by
 
6
the Free Software Foundation, either version 2 of the License, or
 
7
(at your option) any later version.
 
8
 
 
9
hugin is distributed in the hope that it will be useful,
 
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
GNU General Public License for more details.
 
13
 
 
14
You should have received a copy of the GNU General Public License
 
15
along with hugin.  If not, see <http://www.gnu.org/licenses/>.
 
16
*/
 
17
 
 
18
/**
 
19
 * @file StringAdapter.h
 
20
 * @brief
 
21
 *  Created on: Jul 23, 2010
 
22
 * @author Florian Achleitner <florian.achleitner.2.6.31@gmail.com>
 
23
 */
 
24
 
 
25
#ifndef STRINGADAPTER_H_
 
26
#define STRINGADAPTER_H_
 
27
 
 
28
#include <string>
 
29
#include <sstream>
 
30
 
 
31
 
 
32
namespace makefile
 
33
{
 
34
/**
 
35
 * Adapts a string of wide or narrow characters to a narrow character std::string.
 
36
 * It uses the narrow method of standard iostreams, it doesn't do any code conversion.
 
37
 * It's purpose is to allow exception texts to contain wide strings, regardless of
 
38
 * USE_WCHAR.
 
39
 */
 
40
class MAKEIMPEX StringAdapter : public std::string
 
41
{
 
42
        void use_narrow(const wchar_t* ws)
 
43
        {
 
44
                std::ostringstream ostr;
 
45
                for(const wchar_t* i = ws; *i; i++)
 
46
                {
 
47
                        ostr.put(ostr.narrow(*i, '?'));
 
48
                }
 
49
                assign(ostr.str());
 
50
        }
 
51
public:
 
52
        StringAdapter(std::wstring& ws)
 
53
        {
 
54
                use_narrow(ws.c_str());
 
55
        }
 
56
        StringAdapter(const std::string& s)
 
57
        : std::string(s)
 
58
        {}
 
59
        StringAdapter(const wchar_t* ws)
 
60
        {
 
61
                use_narrow(ws);
 
62
        }
 
63
        StringAdapter(const char* s)
 
64
        : std::string(s)
 
65
        {}
 
66
        virtual ~StringAdapter()
 
67
        {
 
68
        }
 
69
};
 
70
 
 
71
}
 
72
 
 
73
#endif /* STRINGADAPTER_H_ */