support for creating template instance classes
[lqt/mk.git] / cpptoxml / parser / rpp / pp-internal.h
blob29a4b4a3f71b04b254d5e255de37b04325344c24
1 /****************************************************************************
2 **
3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
4 ** Copyright 2005 Roberto Raggi <roberto@kdevelop.org>
5 **
6 ** This file is part of $PRODUCT$.
7 **
8 ** $CPP_LICENSE$
9 **
10 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 ****************************************************************************/
15 #ifndef PP_INTERNAL_H
16 #define PP_INTERNAL_H
18 #include <stdio.h>
19 #include <algorithm>
21 namespace rpp {
23 namespace _PP_internal
26 inline void extract_file_path (const std::string &__filename, std::string *__filepath)
28 std::size_t __index = __filename.rfind (PATH_SEPARATOR);
30 if (__index == std::string::npos)
31 *__filepath = "/";
33 else
34 __filepath->assign (__filename, 0, __index + 1);
37 template <typename _OutputIterator>
38 void output_line(const std::string &__filename, int __line, _OutputIterator __result)
40 std::string __msg;
42 __msg += "# ";
44 char __line_descr[16];
45 pp_snprintf (__line_descr, 16, "%d", __line);
46 __msg += __line_descr;
48 __msg += " \"";
50 if (__filename.empty ())
51 __msg += "<internal>";
52 else
53 __msg += __filename;
55 __msg += "\"\n";
56 std::copy (__msg.begin (), __msg.end (), __result);
59 template <typename _InputIterator>
60 inline bool comment_p (_InputIterator __first, _InputIterator __last) /*const*/
62 if (__first == __last)
63 return false;
65 if (*__first != '/')
66 return false;
68 if (++__first == __last)
69 return false;
71 return (*__first == '/' || *__first == '*');
74 struct _Compare_string: public std::binary_function<bool, pp_fast_string const *, pp_fast_string const *>
76 inline bool operator () (pp_fast_string const *__lhs, pp_fast_string const *__rhs) const
77 { return *__lhs < *__rhs; }
80 struct _Equal_to_string: public std::binary_function<bool, pp_fast_string const *, pp_fast_string const *>
82 inline bool operator () (pp_fast_string const *__lhs, pp_fast_string const *__rhs) const
83 { return *__lhs == *__rhs; }
86 struct _Hash_string: public std::unary_function<std::size_t, pp_fast_string const *>
88 inline std::size_t operator () (pp_fast_string const *__s) const
90 char const *__ptr = __s->begin ();
91 std::size_t __size = __s->size ();
92 std::size_t __h = 0;
94 for (std::size_t i = 0; i < __size; ++i)
95 __h = (__h << 5) - __h + __ptr [i];
97 return __h;
101 } // _PP_internal
103 } // namespace rpp
105 #endif // PP_INTERNAL_H
107 // kate: space-indent on; indent-width 2; replace-tabs on;