Debian Codegraph @

src/Base/UnitsSchemas.h

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2
3 /************************************************************************
4 * *
5 * This file is part of the FreeCAD CAx development system. *
6 * *
7 * This library is free software; you can redistribute it and/or *
8 * modify it under the terms of the GNU Library General Public *
9 * License as published by the Free Software Foundation; either *
10 * version 2 of the License, or (at your option) any later version. *
11 * *
12 * This library is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU Library General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Library General Public *
18 * License along with this library; see the file COPYING.LIB. If not, *
19 * write to the Free Software Foundation, Inc., 59 Temple Place, *
20 * Suite 330, Boston, MA 02111-1307, USA *
21 * *
22 ************************************************************************/
23
24 #ifndef SRC_BASE_UNITSSCHEMAS_H
25 #define SRC_BASE_UNITSSCHEMAS_H
26
27 #include <functional>
28 #include <string>
29 #include <vector>
30
31 #include "UnitsSchema.h"
32 #include "UnitsSchemasSpecs.h"
33
34 namespace Base
35 {
36
37 /**
38 * The interface to schema specifications
39 * Has pointer to current schema
40 */
41 class UnitsSchemas
42 {
43 public:
44 explicit UnitsSchemas(const UnitsSchemasDataPack& pack);
45
46 /** Make a schema and set as current*/
47 void select(); // default
48 void select(const std::string_view& name);
49 void select(std::size_t num);
50
51 /** Get a schema specification*/
52 UnitsSchemaSpec spec(); // default, or the first spec
53 UnitsSchemaSpec spec(const std::string_view& name);
54 UnitsSchemaSpec spec(std::size_t num);
55
56 size_t count() const;
57 std::vector<std::string> names();
58 std::vector<std::string> descriptions();
59 std::size_t getDecimals() const;
60 std::size_t defFractDenominator() const;
61 void setdefFractDenominator(std::size_t size);
62
63 UnitsSchema* currentSchema() const;
64
65 private:
66 /** DRY utils */
67 std::vector<std::string> getVec(const std::function<std::string(UnitsSchemaSpec)>& fn);
68 UnitsSchemaSpec findSpec(const std::function<bool(UnitsSchemaSpec)>& fn);
69 void makeCurr(const UnitsSchemaSpec& spec);
70
71 UnitsSchemasDataPack pack;
72 std::unique_ptr<UnitsSchema> current {std::make_unique<UnitsSchema>(spec())};
73 std::size_t denominator;
74 std::size_t decimals;
75 };
76
77
78 } // namespace Base
79 #endif // SRC_BASE_UNITSSCHEMAS_H