Skip to content

Commit babcfb9

Browse files
committed
Add back missing parameter helper functions
1 parent cf25ece commit babcfb9

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

Source/Processors/Parameter/Parameter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
#include "Parameter.h"
25-
#include "../../../PluginGenerator/Source/Utility/openEphys_pluginHelpers.h"
25+
#include "ParameterHelpers.h"
2626

2727

2828
Parameter::Parameter (const String& name, bool defaultValue, int ID, bool deactivateDuringAcquisition)
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
------------------------------------------------------------------
3+
4+
This file is part of the Open Ephys GUI
5+
Copyright (C) 2020 Open Ephys
6+
7+
------------------------------------------------------------------
8+
9+
This program is free software: you can redistribute it and/or modify
10+
it under the terms of the GNU General Public License as published by
11+
the Free Software Foundation, either version 3 of the License, or
12+
(at your option) any later version.
13+
14+
This program is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
GNU General Public License for more details.
18+
19+
You should have received a copy of the GNU General Public License
20+
along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
23+
#ifndef __PARAMETER_HELPERS__
24+
#define __PARAMETER_HELPERS__
25+
26+
#include <JuceHeader.h>
27+
28+
/** Returns the string reporesentation of an array. */
29+
template<typename ValueType>
30+
static String convertArrayToString (const Array<ValueType>& sourceArray)
31+
{
32+
// Allow to convert only the arrays which store arithmetic types
33+
//if (! std::is_arithmetic<ValueType>::value)
34+
//{
35+
// DBG ("Not Arithmetic");
36+
// return String::empty;
37+
//}
38+
39+
String stringRepr;
40+
for (auto value: sourceArray)
41+
stringRepr += value.toString() + ",";
42+
43+
// Some hardcode - remove last coma at the end of the string
44+
stringRepr = stringRepr.dropLastCharacters (1);
45+
46+
return stringRepr;
47+
}
48+
49+
50+
/** Creates and returns the array created from given string. Could be dangerous. */
51+
template <typename ValueType>
52+
static Array<var> createArrayFromString (const String& arrayString, const String& breakCharacters, const String& quoteCharacters = String::empty)
53+
{
54+
// Allow to convert only the arrays which store arithmetic types
55+
if (! std::is_arithmetic<ValueType>::value)
56+
return Array<var> {};
57+
58+
StringArray valuesStr;
59+
valuesStr.addTokens (arrayString, breakCharacters, quoteCharacters);
60+
61+
const bool isBool = std::is_same<ValueType, bool>::value;
62+
const bool isInt = std::is_same<ValueType, int>::value;
63+
const bool isLong = std::is_same<ValueType, long>::value;
64+
const bool isFloat = std::is_same<ValueType, float>::value;
65+
const bool isDouble = std::is_same<ValueType, double>::value;
66+
67+
Array<var> resultArray;
68+
for (const auto& line: valuesStr)
69+
{
70+
if (isBool)
71+
resultArray.add (line.getFloatValue());
72+
else if (isInt)
73+
resultArray.add (line.getIntValue());
74+
else if (isLong)
75+
resultArray.add (line.getLargeIntValue());
76+
else if (isFloat)
77+
resultArray.add (line.getFloatValue());
78+
else if (isDouble)
79+
resultArray.add (line.getDoubleValue());
80+
// If any another type - try to convert to int
81+
else
82+
resultArray.add (line.getIntValue());
83+
}
84+
85+
return resultArray;
86+
}
87+
88+
#endif // __PARAMETER_HELPERS__

0 commit comments

Comments
 (0)