Optika GUI Toolik  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Optika_ArrayHelperFunctions.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Optika: A Tool For Developing Parameter Obtaining GUIs
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, with Sandia Corporation, the
8 // U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com)
38 //
39 // ***********************************************************************
40 // @HEADER
42 
43 namespace Optika{
44 
45 QString determineArrayType(RCP<const ParameterEntry> parameter, bool twoD){
46  any anyArray = parameter->getAny();
47  if(anyArray.type() == (twoD ? typeid(TwoDArray<int>) : typeid(Array<int>))){
48  return intId;
49  }
50  else if(anyArray.type() == (twoD ? typeid(TwoDArray<short>) : typeid(Array<short>))){
51  return shortId;
52  }
53  else if(anyArray.type() == (twoD ? typeid(TwoDArray<double>) : typeid(Array<double>))){
54  return doubleId;
55  }
56  else if(anyArray.type() == (twoD ? typeid(TwoDArray<float>) : typeid(Array<float>))){
57  return floatId;
58  }
59  else if(anyArray.type() == (twoD ? typeid(TwoDArray<std::string>) : typeid(Array<std::string>))){
60  return stringId;
61  }
62  else{
63  return unrecognizedId;
64  }
65 }
66 
68  any anyArray = parameter->getAny();
69  if(anyArray.type() == typeid(Array<int>)){
70  return intId;
71  }
72  else if(anyArray.type() == typeid(Array<short>)){
73  return shortId;
74  }
75  else if(anyArray.type() == typeid(Array<double>)){
76  return doubleId;
77  }
78  else if(anyArray.type() == typeid(Array<float>)){
79  return floatId;
80  }
81  else if(anyArray.type() == typeid(Array<std::string>)){
82  return stringId;
83  }
84  else{
85  return unrecognizedId;
86  }
87 }
88 
90  RCP<const ParameterEntry> arrayEntry, QString type, bool twoD){
91  if(type == intId){
92  return (twoD ?
93  QVariant::fromValue<TwoDArray<int> >(
94  getValue<TwoDArray<int> >(*arrayEntry))
95  :
96  QVariant::fromValue<Array<int> >(
97  getValue<Array<int> >(*arrayEntry)));
98  }
99  else if(type == shortId){
100  return (twoD ?
101  QVariant::fromValue<TwoDArray<short> >(
102  getValue<TwoDArray<short> >(*arrayEntry))
103  :
104  QVariant::fromValue<Array<short> >(
105  getValue<Array<short> >(*arrayEntry)));
106  }
107  else if(type == doubleId){
108  return (twoD ?
109  QVariant::fromValue<TwoDArray<double> >(
110  getValue<TwoDArray<double> >(*arrayEntry))
111  :
112  QVariant::fromValue<Array<double> >(
113  getValue<Array<double> >(*arrayEntry)));
114  }
115  else if(type == floatId){
116  return (twoD ?
117  QVariant::fromValue<TwoDArray<float> >(
118  getValue<TwoDArray<float> >(*arrayEntry))
119  :
120  QVariant::fromValue<Array<float> >(
121  getValue<Array<float> >(*arrayEntry)));
122  }
123  else if(type == stringId){
124  return (twoD ?
125  QVariant::fromValue<TwoDArray<std::string> >(
126  getValue<TwoDArray<std::string> >(*arrayEntry))
127  :
128  QVariant::fromValue<Array<std::string> >(
129  getValue<Array<std::string> >(*arrayEntry)));
130  }
131  return QVariant();
132 }
133 
134 QString getArrayType(QString itemType){
135  return itemType.section(" ",-1);
136 }
137 
138 bool isArrayEmpty(RCP<const ParameterEntry> arrayEntry, QString type){
139  if(type == intId){
140  return getValue<Array<int> >(*arrayEntry).size() == 0;
141  }
142  else if(type == shortId){
143  return getValue<Array<short> >(*arrayEntry).size() == 0;
144  }
145  else if(type == doubleId){
146  return getValue<Array<double> >(*arrayEntry).size() == 0;
147  }
148  else if(type == floatId){
149  return getValue<Array<float> >(*arrayEntry).size() == 0;
150  }
151  else if(type == stringId){
152  return getValue<Array<std::string> >(*arrayEntry).size() == 0;
153  }
154  return true;
155 }
156 
157 
158 }
QString shortId
QString intId
QString unrecognizedId
QString determineArrayType(RCP< const ParameterEntry > parameter, bool twoD)
Determines the type of array stored in a parameter.
QVariant arrayEntryToVariant(RCP< const ParameterEntry > arrayEntry, QString type, bool twoD)
Creates a QVariant containing the array that is in arrayEntry.
QString floatId
any & getAny(bool activeQry=true)
QString doubleId
QString stringId
bool isArrayEmpty(RCP< const ParameterEntry > arrayEntry, QString type)
Determines wether or no the array inside a ParameterEntry is empty.
const std::type_info & type() const
QString getArrayType(QString itemType)
Given a type string, determines the template type of the Array.