Optika GUI Toolik Version of the Day
Optika_ArrayHelperFunctions.cpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //         Optika: A Tool For Developing Parameter Obtaining GUIs
00005 //                Copyright (2009) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, with Sandia Corporation, the 
00008 // U.S. Government retains certain rights in this software.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 #include "Optika_ArrayHelperFunctions.hpp"
00029 
00030 namespace Optika{
00031 
00032 QString determineArrayType(RCP<const ParameterEntry> parameter, bool twoD){
00033   any anyArray = parameter->getAny();
00034   if(anyArray.type() == (twoD ? typeid(TwoDArray<int>) : typeid(Array<int>))){
00035     return intId;
00036   }
00037   else if(anyArray.type() == (twoD ? typeid(TwoDArray<short>) : typeid(Array<short>))){
00038     return shortId;
00039   }
00040   else if(anyArray.type() == (twoD ? typeid(TwoDArray<double>) : typeid(Array<double>))){
00041     return doubleId;
00042   }
00043   else if(anyArray.type() == (twoD ? typeid(TwoDArray<float>) : typeid(Array<float>))){
00044     return floatId;
00045   }
00046   else if(anyArray.type() == (twoD ? typeid(TwoDArray<std::string>) : typeid(Array<std::string>))){
00047     return stringId;
00048   }
00049   else{
00050     return unrecognizedId;    
00051   }
00052 }
00053 
00054 QString determineArrayType(RCP<const ParameterEntry> parameter){
00055   any anyArray = parameter->getAny();
00056   if(anyArray.type() == typeid(Array<int>)){
00057     return intId;
00058   }
00059   else if(anyArray.type() == typeid(Array<short>)){
00060     return shortId;
00061   }
00062   else if(anyArray.type() == typeid(Array<double>)){
00063     return doubleId;
00064   }
00065   else if(anyArray.type() == typeid(Array<float>)){
00066     return floatId;
00067   }
00068   else if(anyArray.type() == typeid(Array<std::string>)){
00069     return stringId;
00070   }
00071   else{
00072     return unrecognizedId;    
00073   }
00074 }
00075 
00076 QVariant arrayEntryToVariant(
00077   RCP<const ParameterEntry> arrayEntry, QString type, bool twoD){
00078   if(type == intId){
00079     return (twoD ? 
00080       QVariant::fromValue<TwoDArray<int> >(
00081       getValue<TwoDArray<int> >(*arrayEntry))
00082       :
00083       QVariant::fromValue<Array<int> >(
00084       getValue<Array<int> >(*arrayEntry)));
00085   }
00086   else if(type == shortId){
00087     return (twoD ? 
00088       QVariant::fromValue<TwoDArray<short> >(
00089       getValue<TwoDArray<short> >(*arrayEntry))
00090       :
00091       QVariant::fromValue<Array<short> >(
00092       getValue<Array<short> >(*arrayEntry)));
00093   }
00094   else if(type == doubleId){
00095     return (twoD ? 
00096       QVariant::fromValue<TwoDArray<double> >(
00097       getValue<TwoDArray<double> >(*arrayEntry))
00098       :
00099       QVariant::fromValue<Array<double> >(
00100       getValue<Array<double> >(*arrayEntry)));
00101   }
00102   else if(type == floatId){
00103     return (twoD ? 
00104       QVariant::fromValue<TwoDArray<float> >(
00105       getValue<TwoDArray<float> >(*arrayEntry))
00106       :
00107       QVariant::fromValue<Array<float> >(
00108       getValue<Array<float> >(*arrayEntry)));
00109   }
00110   else if(type == stringId){
00111     return (twoD ? 
00112       QVariant::fromValue<TwoDArray<std::string> >(
00113       getValue<TwoDArray<std::string> >(*arrayEntry))
00114       :
00115       QVariant::fromValue<Array<std::string> >(
00116       getValue<Array<std::string> >(*arrayEntry)));
00117   }
00118   return QVariant();
00119 }
00120 
00121 QString getArrayType(QString itemType){
00122   return itemType.section(" ",-1);  
00123 }
00124 
00125 bool isArrayEmpty(RCP<const ParameterEntry> arrayEntry, QString type){
00126   if(type == intId){
00127     return getValue<Array<int> >(*arrayEntry).size() == 0;
00128   }
00129   else if(type == shortId){
00130     return getValue<Array<short> >(*arrayEntry).size() == 0;
00131   }
00132   else if(type == doubleId){
00133     return getValue<Array<double> >(*arrayEntry).size() == 0;
00134   }
00135   else if(type == floatId){
00136     return getValue<Array<float> >(*arrayEntry).size() == 0;
00137   }
00138   else if(type == stringId){
00139     return getValue<Array<std::string> >(*arrayEntry).size() == 0;
00140   }
00141   return true;
00142 }
00143 
00144 
00145 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines