ListPolicy.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2019-2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Namespace
27  Foam::Detail::ListPolicy
28 
29 Description
30  Additional compile-time controls of List behaviour
31 
32 \*---------------------------------------------------------------------------*/
33 
34 #ifndef Foam_ListPolicy_H
35 #define Foam_ListPolicy_H
36 
37 #include <type_traits>
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43 
44 // Forward Declarations
45 class keyType;
46 class word;
47 class wordRe;
48 
49 namespace Detail
50 {
51 namespace ListPolicy
52 {
53 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
56 //- Number of items before requiring line-breaks in the list output.
57 //
58 // Default definition: 10
59 template<class T>
60 struct short_length : std::integral_constant<int,10> {};
61 
62 // Can override on a per-type basis
63 // Eg,
64 // template<> struct short_length<label> : std::integral_constant<int,20> {};
65 
66 
67 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 
69 //- Can suppress additional line breaks separate ASCII data content
70 //- when the data elements are primitives, or contiguous
71 //
72 // Default definition: (integral | floating-point) are contiguous and thus
73 // never need any line breaks
74 template<class T>
75 struct no_linebreak : std::is_arithmetic<T> {};
76 
77 // Specialization for word-like classes
78 // These elements are normally fairly short, so ok to output a few (eg, 10)
79 // of them on a single line.
80 
81 //- Suppress line-breaks for keyType
82 template<> struct no_linebreak<keyType> : std::true_type {};
83 
84 //- Suppress line-breaks for word
85 template<> struct no_linebreak<word> : std::true_type {};
86 
87 //- Suppress line-breaks for wordRe
88 template<> struct no_linebreak<wordRe> : std::true_type {};
89 
90 
91 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
92 
93 //- Classification of list/container uniformity.
94 //- The values can be used with bit-wise \c or reduction
95 enum uniformity : unsigned char
96 {
97  EMPTY = 0,
98  UNIFORM = 0x1,
99  NONUNIFORM = 0x2,
100  MIXED = 0x3
101 };
102 
103 //- Algorithm to determine list/container uniformity
104 template<class InputIt>
105 enum uniformity check_uniformity(InputIt first, InputIt last)
106 {
107  if (first == last) return uniformity::EMPTY;
109  // Like std::all_of() with checking against element 0,
110  // but without using a lambda with auto type (pre C++14) etc.
111 
112  const auto& elem0 = *first;
113 
114  for ((void)++first; (first != last); (void)++first)
115  {
116  if (elem0 != *first)
117  {
118  return uniformity::NONUNIFORM;
119  }
120  }
121 
122  return uniformity::UNIFORM;
123 }
124 
125 
126 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
127 
128 } // End namespace ListPolicy
129 } // End namespace Detail
130 } // End namespace Foam
131 
132 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
133 
134 #endif
135 
136 // ************************************************************************* //
A class for handling keywords in dictionaries.
Definition: keyType.H:66
Mixed uniform/non-uniform (eg, after reduction)
Definition: ListPolicy.H:108
Number of items before requiring line-breaks in the list output.
Definition: ListPolicy.H:57
Container (non-empty) with different values.
Definition: ListPolicy.H:107
An empty container.
Definition: ListPolicy.H:105
uniformity
Classification of list/container uniformity. The values can be used with bit-wise or reduction...
Definition: ListPolicy.H:103
A class for handling words, derived from Foam::string.
Definition: word.H:63
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings...
Definition: wordRe.H:78
enum uniformity check_uniformity(InputIt first, InputIt last)
Algorithm to determine list/container uniformity.
Definition: ListPolicy.H:115
Can suppress additional line breaks separate ASCII data content when the data elements are primitives...
Definition: ListPolicy.H:75
Container (non-empty) with identical values.
Definition: ListPolicy.H:106
Namespace for OpenFOAM.