1 | #include <string>
|
---|
2 | #include <boost/config.hpp>
|
---|
3 | #include <boost/shared_ptr.hpp>
|
---|
4 | #include <boost/filesystem/path.hpp>
|
---|
5 |
|
---|
6 | // Make sure boost::filesystem::path invokes code conversion
|
---|
7 | #if defined(BOOST_WINDOWS)
|
---|
8 | typedef std::string path_string;
|
---|
9 | path_string foo_path = "foo.txt";
|
---|
10 | #else
|
---|
11 | typedef std::wstring path_string;
|
---|
12 | path_string foo_path = L"foo.txt";
|
---|
13 | #endif
|
---|
14 |
|
---|
15 | struct sink
|
---|
16 | {
|
---|
17 | path_string m_path;
|
---|
18 |
|
---|
19 | void foo()
|
---|
20 | {
|
---|
21 | boost::filesystem::path p(m_path);
|
---|
22 | }
|
---|
23 | };
|
---|
24 |
|
---|
25 | struct core
|
---|
26 | {
|
---|
27 | boost::shared_ptr< sink > m_sink;
|
---|
28 |
|
---|
29 | ~core()
|
---|
30 | {
|
---|
31 | if (m_sink)
|
---|
32 | m_sink->foo();
|
---|
33 | }
|
---|
34 |
|
---|
35 | static boost::shared_ptr< core > get_instance()
|
---|
36 | {
|
---|
37 | static boost::shared_ptr< core > instance;
|
---|
38 | if (!instance)
|
---|
39 | instance.reset(new core());
|
---|
40 | return instance;
|
---|
41 | }
|
---|
42 | };
|
---|
43 |
|
---|
44 | int main()
|
---|
45 | {
|
---|
46 | boost::shared_ptr< core > c = core::get_instance();
|
---|
47 | c->m_sink.reset(new sink());
|
---|
48 | // Initialize the path locale after the core instance
|
---|
49 | c->m_sink->m_path = boost::filesystem::path(foo_path).string< path_string >();
|
---|
50 | return 0;
|
---|
51 | }
|
---|