support for creating template instance classes
[lqt/mk.git] / cpptoxml / parser / rpp / pp-symbol.h
blobde646df7d41e7cb007d2f747fcce33230ffa064e
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_SYMBOL_H
16 #define PP_SYMBOL_H
18 namespace rpp {
20 class pp_symbol
22 static rxx_allocator<char> &allocator_instance ()
24 static rxx_allocator<char>__allocator;
25 return __allocator;
28 public:
29 static int &N()
31 static int __N;
32 return __N;
35 static pp_fast_string const *get (char const *__data, std::size_t __size)
37 ++N();
38 char *data = allocator_instance ().allocate (__size + 1);
39 memcpy(data, __data, __size);
40 data[__size] = '\0';
42 char *where = allocator_instance ().allocate (sizeof (pp_fast_string));
43 return new (where) pp_fast_string (data, __size);
46 template <typename _InputIterator>
47 static pp_fast_string const *get (_InputIterator __first, _InputIterator __last)
49 ++N();
50 std::ptrdiff_t __size;
51 #if defined(__SUNPRO_CC)
52 std::distance (__first, __last, __size);
53 #else
54 __size = std::distance (__first, __last);
55 #endif
56 assert (__size >= 0 && __size < 512);
58 char *data = allocator_instance ().allocate (__size + 1);
59 std::copy (__first, __last, data);
60 data[__size] = '\0';
62 char *where = allocator_instance ().allocate (sizeof (pp_fast_string));
63 return new (where) pp_fast_string (data, __size);
66 static pp_fast_string const *get(std::string const &__s)
67 { return get (__s.c_str (), __s.size ()); }
70 } // namespace rpp
72 #endif // PP_SYMBOL_H
74 // kate: space-indent on; indent-width 2; replace-tabs on;