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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 #include "Optika_ArrayHelperFunctions.hpp"
00042 
00043 namespace Optika{
00044 
00045 QString determineArrayType(RCP<const ParameterEntry> parameter, bool twoD){
00046   any anyArray = parameter->getAny();
00047   if(anyArray.type() == (twoD ? typeid(TwoDArray<int>) : typeid(Array<int>))){
00048     return intId;
00049   }
00050   else if(anyArray.type() == (twoD ? typeid(TwoDArray<short>) : typeid(Array<short>))){
00051     return shortId;
00052   }
00053   else if(anyArray.type() == (twoD ? typeid(TwoDArray<double>) : typeid(Array<double>))){
00054     return doubleId;
00055   }
00056   else if(anyArray.type() == (twoD ? typeid(TwoDArray<float>) : typeid(Array<float>))){
00057     return floatId;
00058   }
00059   else if(anyArray.type() == (twoD ? typeid(TwoDArray<std::string>) : typeid(Array<std::string>))){
00060     return stringId;
00061   }
00062   else{
00063     return unrecognizedId;    
00064   }
00065 }
00066 
00067 QString determineArrayType(RCP<const ParameterEntry> parameter){
00068   any anyArray = parameter->getAny();
00069   if(anyArray.type() == typeid(Array<int>)){
00070     return intId;
00071   }
00072   else if(anyArray.type() == typeid(Array<short>)){
00073     return shortId;
00074   }
00075   else if(anyArray.type() == typeid(Array<double>)){
00076     return doubleId;
00077   }
00078   else if(anyArray.type() == typeid(Array<float>)){
00079     return floatId;
00080   }
00081   else if(anyArray.type() == typeid(Array<std::string>)){
00082     return stringId;
00083   }
00084   else{
00085     return unrecognizedId;    
00086   }
00087 }
00088 
00089 QVariant arrayEntryToVariant(
00090   RCP<const ParameterEntry> arrayEntry, QString type, bool twoD){
00091   if(type == intId){
00092     return (twoD ? 
00093       QVariant::fromValue<TwoDArray<int> >(
00094       getValue<TwoDArray<int> >(*arrayEntry))
00095       :
00096       QVariant::fromValue<Array<int> >(
00097       getValue<Array<int> >(*arrayEntry)));
00098   }
00099   else if(type == shortId){
00100     return (twoD ? 
00101       QVariant::fromValue<TwoDArray<short> >(
00102       getValue<TwoDArray<short> >(*arrayEntry))
00103       :
00104       QVariant::fromValue<Array<short> >(
00105       getValue<Array<short> >(*arrayEntry)));
00106   }
00107   else if(type == doubleId){
00108     return (twoD ? 
00109       QVariant::fromValue<TwoDArray<double> >(
00110       getValue<TwoDArray<double> >(*arrayEntry))
00111       :
00112       QVariant::fromValue<Array<double> >(
00113       getValue<Array<double> >(*arrayEntry)));
00114   }
00115   else if(type == floatId){
00116     return (twoD ? 
00117       QVariant::fromValue<TwoDArray<float> >(
00118       getValue<TwoDArray<float> >(*arrayEntry))
00119       :
00120       QVariant::fromValue<Array<float> >(
00121       getValue<Array<float> >(*arrayEntry)));
00122   }
00123   else if(type == stringId){
00124     return (twoD ? 
00125       QVariant::fromValue<TwoDArray<std::string> >(
00126       getValue<TwoDArray<std::string> >(*arrayEntry))
00127       :
00128       QVariant::fromValue<Array<std::string> >(
00129       getValue<Array<std::string> >(*arrayEntry)));
00130   }
00131   return QVariant();
00132 }
00133 
00134 QString getArrayType(QString itemType){
00135   return itemType.section(" ",-1);  
00136 }
00137 
00138 bool isArrayEmpty(RCP<const ParameterEntry> arrayEntry, QString type){
00139   if(type == intId){
00140     return getValue<Array<int> >(*arrayEntry).size() == 0;
00141   }
00142   else if(type == shortId){
00143     return getValue<Array<short> >(*arrayEntry).size() == 0;
00144   }
00145   else if(type == doubleId){
00146     return getValue<Array<double> >(*arrayEntry).size() == 0;
00147   }
00148   else if(type == floatId){
00149     return getValue<Array<float> >(*arrayEntry).size() == 0;
00150   }
00151   else if(type == stringId){
00152     return getValue<Array<std::string> >(*arrayEntry).size() == 0;
00153   }
00154   return true;
00155 }
00156 
00157 
00158 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines