update credits
[LibreOffice.git] / include / o3tl / enumrange.hxx
blob395b870db21a36663e17801f80d4c18f56340cac
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 INCLUDED_O3TL_ENUMRANGE_HXX
21 #define INCLUDED_O3TL_ENUMRANGE_HXX
23 #include <sal/config.h>
25 namespace o3tl {
27 ///
28 /// This is a container convenience class iterating over scoped enumerations.
29 ///
30 /// This assumes that the 'enum class' definition
31 /// - starts at zero
32 /// - has no holes in it's sequence of values
33 /// - defines a value called LAST which refers to the greatest constant.
34 ///
35 /// Use like this:
36 /// enum class COLOR { RED, GREEN, BLUE, LAST=BLUE };
37 /// for( auto e : o3tl::enumrange<Color>() )
38 /// .....;
39 ///
40 /// \param T the 'enum class' type.
41 template< typename T>
42 class enumrange
44 public:
45 class Iterator
47 public:
48 Iterator( int value ) :
49 m_value( value )
53 T operator*( void ) const
55 return static_cast<T>(m_value);
58 void operator++( void )
60 ++m_value;
63 bool operator!=( Iterator rhs )
65 return m_value != rhs.m_value;
68 private:
69 int m_value;
73 template< typename T >
74 typename enumrange<T>::Iterator begin( enumrange<T> )
76 return typename enumrange<T>::Iterator( (int)0 );
79 template< typename T >
80 typename enumrange<T>::Iterator end( enumrange<T> )
82 return typename enumrange<T>::Iterator( (static_cast<int>(T::LAST)) + 1 );
85 }; // namespace o3tl
87 #endif /* INCLUDED_O3TL_ENUMRANGE_HXX */
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */