1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef CSV_TPLTOOLS_HXX
21 #define CSV_TPLTOOLS_HXX
33 template <class COLLECTION
>
34 inline void erase_container(
35 COLLECTION
& o_rCollection
);
37 /// Version for other containers than std::map, with non-pair value_type.
38 template <class COLLECTION
>
39 void erase_container_of_heap_ptrs(
40 COLLECTION
& o_rCollection
);
43 template <class KEY
, class VAL
>
44 const VAL
* find_in_map( /// Usable for all kinds of values
45 const std::map
< KEY
, VAL
> &
50 /** @return the value in the map, if it is in there, else 0.
51 @precond VAL has to be convertible to "0".
53 template <class KEY
, class VAL
>
55 const std::map
< KEY
, VAL
> &
59 /** @return the value in the map, if it is in there, else i_notFound.
61 template <class KEY
, class VAL
>
63 const std::map
< KEY
, VAL
> &
68 template <class COLLECTION
, class VALUE
>
70 const COLLECTION
& i_collection
,
71 const VALUE
& i_value
);
77 template <class COLLECTION
>
79 erase_container( COLLECTION
& o_rCollection
)
81 o_rCollection
.erase( o_rCollection
.begin(),
82 o_rCollection
.end() );
85 template <class COLLECTION
>
87 erase_container_of_heap_ptrs( COLLECTION
& o_rCollection
)
89 typename
COLLECTION::iterator itEnd
= o_rCollection
.end();
90 for ( typename
COLLECTION::iterator it
= o_rCollection
.begin();
97 o_rCollection
.erase( o_rCollection
.begin(),
98 o_rCollection
.end() );
101 template <class KEY
, class VAL
>
103 find_in_map( const std::map
< KEY
, VAL
> & i_rMap
,
106 typename
std::map
< KEY
, VAL
>::const_iterator
107 ret
= i_rMap
.find(i_rKey
);
108 return ret
!= i_rMap
.end()
113 template <class KEY
, class VAL
>
115 value_from_map( const std::map
< KEY
, VAL
> & i_rMap
,
118 typename
std::map
< KEY
, VAL
>::const_iterator
119 ret
= i_rMap
.find(i_rKey
);
120 return ret
!= i_rMap
.end()
125 template <class KEY
, class VAL
>
127 value_from_map( const std::map
< KEY
, VAL
> & i_rMap
,
131 typename
std::map
< KEY
, VAL
>::const_iterator
132 ret
= i_rMap
.find(i_rKey
);
133 return ret
!= i_rMap
.end()
138 template <class COLLECTION
, class VALUE
>
140 contains( const COLLECTION
& i_collection
,
141 const VALUE
& i_value
)
143 return std::find(i_collection
.begin(), i_collection
.end(), i_value
)
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */