Line data Source code
1 : /*************************************************************************
2 : *
3 : * Copyright (c) 2010-2012 Kohei Yoshida
4 : *
5 : * Permission is hereby granted, free of charge, to any person
6 : * obtaining a copy of this software and associated documentation
7 : * files (the "Software"), to deal in the Software without
8 : * restriction, including without limitation the rights to use,
9 : * copy, modify, merge, publish, distribute, sublicense, and/or sell
10 : * copies of the Software, and to permit persons to whom the
11 : * Software is furnished to do so, subject to the following
12 : * conditions:
13 : *
14 : * The above copyright notice and this permission notice shall be
15 : * included in all copies or substantial portions of the Software.
16 : *
17 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 : * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 : * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 : * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 : * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 : * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 : * OTHER DEALINGS IN THE SOFTWARE.
25 : *
26 : ************************************************************************/
27 :
28 : #ifndef __ORCUS_GLOBAL_HPP__
29 : #define __ORCUS_GLOBAL_HPP__
30 :
31 : #include "types.hpp"
32 : #include "env.hpp"
33 :
34 : #include <string>
35 : #include <functional>
36 : #include <boost/interprocess/smart_ptr/unique_ptr.hpp>
37 :
38 : namespace orcus {
39 :
40 : class tokens;
41 :
42 : void print_element(xmlns_token_t ns, xml_token_t name);
43 :
44 : /**
45 : * Print attributes to stdout for debugging purposes.
46 : */
47 : void print_attrs(const tokens& tokens, const xml_attrs_t& attrs);
48 :
49 : /**
50 : * Load the content of a file into a file stream.
51 : *
52 : * @param filepath file to open
53 : * @param strm content of the file
54 : */
55 : ORCUS_DLLPUBLIC void load_file_content(const char* filepath, std::string& strm);
56 :
57 : template<typename _T>
58 0 : struct default_deleter : public std::unary_function<_T*, void>
59 : {
60 0 : void operator() (_T* p)
61 : {
62 0 : delete p;
63 0 : }
64 : };
65 :
66 : /**
67 : * Function object for deleting objects that are stored in map container as
68 : * pointers.
69 : */
70 : template<typename T>
71 : struct map_object_deleter : public ::std::unary_function<typename T::value_type, void>
72 : {
73 0 : void operator() (typename T::value_type& v)
74 : {
75 0 : delete v.second;
76 0 : }
77 : };
78 :
79 : template<typename _T, typename _Deleter = default_deleter<_T> >
80 0 : class unique_ptr : public boost::interprocess::unique_ptr<_T, _Deleter>
81 : {
82 : public:
83 0 : unique_ptr(_T* p) : boost::interprocess::unique_ptr<_T, _Deleter>(p) {}
84 : };
85 :
86 : }
87 :
88 : #endif
|