1 /****************************************************************************
3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
4 ** Copyright 2005 Roberto Raggi <roberto@kdevelop.org>
6 ** This file is part of $PRODUCT$.
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_ENVIRONMENT_H
16 #define PP_ENVIRONMENT_H
26 typedef std::vector
<pp_macro
*>::const_iterator const_iterator
;
33 _M_base
= (pp_macro
**) memset (new pp_macro
* [_M_hash_size
], 0, _M_hash_size
* sizeof (pp_macro
*));
38 for (std::size_t i
= 0; i
< _M_macros
.size (); ++i
)
44 const_iterator
first_macro () const { return _M_macros
.begin (); }
45 const_iterator
last_macro () const { return _M_macros
.end (); }
47 inline void bind (pp_fast_string
const *__name
, pp_macro
const &__macro
)
49 std::size_t h
= hash_code (*__name
) % _M_hash_size
;
50 pp_macro
*m
= new pp_macro (__macro
);
52 m
->next
= _M_base
[h
];
56 _M_macros
.push_back (m
);
58 if (_M_macros
.size() == _M_hash_size
)
62 inline void unbind (pp_fast_string
const *__name
)
64 if (pp_macro
*m
= resolve (__name
))
68 inline void unbind (char const *__s
, std::size_t __size
)
70 pp_fast_string
__tmp (__s
, __size
);
74 inline pp_macro
*resolve (pp_fast_string
const *__name
) const
76 std::size_t h
= hash_code (*__name
) % _M_hash_size
;
77 pp_macro
*it
= _M_base
[h
];
79 while (it
&& it
->name
&& it
->hash_code
== h
&& (*it
->name
!= *__name
|| it
->f
.hidden
))
85 inline pp_macro
*resolve (char const *__data
, std::size_t __size
) const
87 pp_fast_string
const __tmp (__data
, __size
);
88 return resolve (&__tmp
);
91 std::string current_file
;
95 inline std::size_t hash_code (pp_fast_string
const &s
) const
97 std::size_t hash_value
= 0;
99 for (std::size_t i
= 0; i
< s
.size (); ++i
)
100 hash_value
= (hash_value
<< 5) - hash_value
+ s
.at (i
);
111 _M_base
= (pp_macro
**) memset (new pp_macro
* [_M_hash_size
], 0, _M_hash_size
* sizeof(pp_macro
*));
112 for (std::size_t index
= 0; index
< _M_macros
.size (); ++index
)
114 pp_macro
*elt
= _M_macros
[index
];
115 std::size_t h
= hash_code (*elt
->name
) % _M_hash_size
;
116 elt
->next
= _M_base
[h
];
123 std::vector
<pp_macro
*> _M_macros
;
125 std::size_t _M_hash_size
;
130 #endif // PP_ENVIRONMENT_H
132 // kate: space-indent on; indent-width 2; replace-tabs on;