Repository navigation
Expand file tree
/
Copy pathSettingsSerializer.cpp
More file actions
68 lines (50 loc) · 1.96 KB
/
Copy pathSettingsSerializer.cpp
File metadata and controls
68 lines (50 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*==============================================================================
Copyright 2018 by Tracktion Corporation.
For more information visit www.tracktion.com
You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
pluginval IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================*/
#include "SettingsSerializer.h"
#include <stdexcept>
namespace settings_serializer
{
nlohmann::json toJson (const PluginvalSettings& s)
{
return nlohmann::json (s);
}
PluginvalSettings fromJsonString (const std::string& jsonString)
{
return nlohmann::json::parse (jsonString).get<PluginvalSettings>();
}
PluginvalSettings fromJsonFile (const juce::File& file)
{
return fromJsonString (file.loadFileAsString().toStdString());
}
//==============================================================================
std::int64_t parseRandomSeed (const juce::String& raw)
{
if (! raw.containsOnly ("x-0123456789abcdef"))
throw std::invalid_argument ("Invalid random seed argument!");
if (raw.startsWith ("0x"))
return raw.getHexValue64();
return raw.getLargeIntValue();
}
std::vector<std::string> disabledTestsToList (const juce::String& raw)
{
std::vector<std::string> out;
if (juce::File::isAbsolutePath (raw))
{
juce::StringArray lines;
juce::File (raw).readLines (lines);
for (const auto& line : lines)
out.push_back (line.toStdString());
return out;
}
for (const auto& token : juce::StringArray::fromTokens (raw, ",", ""))
out.push_back (token.toStdString());
return out;
}
} // namespace settings_serializer