Debian Codegraph @

src/App/License.h

raw
1 /***************************************************************************
2 * Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23 #ifndef APP_LICENSE_H
24 #define APP_LICENSE_H
25
26 #include <array>
27 #include <cstring>
28 #include <string>
29 #include <Base/Tools.h>
30
31 namespace App
32 {
33
34 /**
35 * Licenses data [identifier, fullName, url]
36 * See also https://spdx.org/licenses/
37 */
38 constexpr int colsInArray = 3;
39 using TLicenseArr = std::array<const char*, colsInArray>;
40 constexpr int posnOfIdentifier = 0;
41 constexpr int posnOfFullName = 1;
42 constexpr int posnOfUrl = 2;
43 constexpr int countOfLicenses {19};
44 // clang-format off
45 constexpr std::array<TLicenseArr, countOfLicenses> licenseItems {{
46 { "AllRightsReserved", "All rights reserved", "https://en.wikipedia.org/wiki/All_rights_reserved" },
47 { "CC_BY_40", "Creative Commons Attribution 4.0", "https://creativecommons.org/licenses/by/4.0/" },
48 { "CC_BY_SA_40", "Creative Commons Attribution-ShareAlike 4.0", "https://creativecommons.org/licenses/by-sa/4.0/" },
49 { "CC_BY_ND_40", "Creative Commons Attribution-NoDerivatives 4.0", "https://creativecommons.org/licenses/by-nd/4.0/" },
50 { "CC_BY_NC_40", "Creative Commons Attribution-NonCommercial 4.0", "https://creativecommons.org/licenses/by-nc/4.0/" },
51 { "CC_BY_NC_SA_40", "Creative Commons Attribution-NonCommercial-ShareAlike 4.0", "https://creativecommons.org/licenses/by-nc-sa/4.0/" },
52 { "CC_BY_NC_ND_40", "Creative Commons Attribution-NonCommercial-NoDerivatives 4.0", "https://creativecommons.org/licenses/by-nc-nd/4.0/" },
53 { "CC_BY_30", "Creative Commons Attribution 3.0", "https://creativecommons.org/licenses/by/3.0/" },
54 { "CC_BY_SA_30", "Creative Commons Attribution-ShareAlike 3.0", "https://creativecommons.org/licenses/by-sa/3.0/" },
55 { "CC_BY_ND_30", "Creative Commons Attribution-NoDerivatives 3.0", "https://creativecommons.org/licenses/by-nd/3.0/" },
56 { "CC_BY_NC_30", "Creative Commons Attribution-NonCommercial 3.0", "https://creativecommons.org/licenses/by-nc/3.0/" },
57 { "CC_BY_NC_SA_30", "Creative Commons Attribution-NonCommercial-ShareAlike 3.0", "https://creativecommons.org/licenses/by-nc-sa/3.0/" },
58 { "CC_BY_NC_ND_30", "Creative Commons Attribution-NonCommercial-NoDerivatives 3.0", "https://creativecommons.org/licenses/by-nc-nd/3.0/" },
59 { "PublicDomain", "Public Domain", "https://en.wikipedia.org/wiki/Public_domain" },
60 { "FreeArt", "FreeArt", "https://artlibre.org/licence/lal" },
61 { "CERN_OHS_S", "CERN Open Hardware Licence strongly-reciprocal", "https://cern-ohl.web.cern.ch/" },
62 { "CERN_OHS_W", "CERN Open Hardware Licence weakly-reciprocal", "https://cern-ohl.web.cern.ch/" },
63 { "CERN_OHS_P", "CERN Open Hardware Licence permissive", "https://cern-ohl.web.cern.ch/" },
64 { "GPL-3.0-or-later", "GNU General Public License 3.0 or later", "https://www.gnu.org/licenses/gpl-3.0.html" },
65 }};
66 // clang-format on
67
68 int constexpr findLicense(const char* identifier)
69 {
70 if (Base::Tools::isNullOrEmpty(identifier)) {
71 return -1;
72 }
73 for (int i = 0; i < countOfLicenses; i++) {
74 if (strcmp(licenseItems.at(i).at(posnOfIdentifier), identifier) == 0) {
75 return i;
76 }
77 }
78 return -1;
79 }
80 } // namespace App
81
82 #endif // APP_LICENSE_H