test-ParamMap.C

Go to the documentation of this file.
00001 /*!@file TestSuite/test-ParamMap.C */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00005 // by the University of Southern California (USC) and the iLab at USC.  //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Rob Peters <rjpeters at usc dot edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/TestSuite/test-ParamMap.C $
00035 // $Id: test-ParamMap.C 8386 2007-05-13 22:01:11Z rjpeters $
00036 //
00037 
00038 #ifndef TESTSUITE_TEST_PARAMMAP_C_DEFINED
00039 #define TESTSUITE_TEST_PARAMMAP_C_DEFINED
00040 
00041 #include "Component/ParamMap.H"
00042 #include "Util/sformat.H"
00043 
00044 #include <iostream>
00045 #include <vector>
00046 
00047 int main()
00048 {
00049   {
00050     // generate a ParamMap
00051     std::cout << "\n\n\n==== generating A ParamMap...\n\n";
00052 
00053     rutz::shared_ptr<ParamMap> pmap1(new ParamMap);
00054 
00055     pmap1->putStringParam("stringparam", "string param value");
00056     pmap1->putIntParam("intparam", 42);
00057     pmap1->putDoubleParam("doubleparam", 5.56);
00058 
00059     rutz::shared_ptr<ParamMap> pmap2(new ParamMap);
00060 
00061     pmap2->putStringParam("submapstringparam", "submap string param value");
00062     pmap2->putIntParam("submapintparam", 93);
00063 
00064     std::vector<int> values;
00065     values.push_back(3);
00066     values.push_back(10);
00067     values.push_back(-9);
00068 
00069     pmap2->putIntParam("num_array", int(values.size()));
00070     for (size_t i = 0; i < values.size(); ++i)
00071       {
00072         pmap2->putIntParam(sformat("array%d", int(i)), values[i]);
00073       }
00074 
00075     pmap1->putSubpmap("submap", pmap2);
00076 
00077     std::cout << "\n\n\n==== printing the ParamMap to stdout...\n\n";
00078 
00079     pmap1->format(std::cout);
00080 
00081     // save it to disk
00082     std::cout << "\n\n\n==== saving the ParamMap to disk...\n\n";
00083     pmap1->format("parammap-test.pmap");
00084   }
00085 
00086   // load it back from disk
00087   std::cout << "\n\n\n==== loading the ParamMap back in from disk...\n\n";
00088   rutz::shared_ptr<ParamMap> pmap3 =
00089     ParamMap::loadPmapFile("parammap-test.pmap");
00090 
00091   std::cout << "\n\n\n==== unpacking the loaded ParamMap...\n\n";
00092 
00093   // now parse parameters back out
00094   std::string s1 = pmap3->getStringParam("stringparam");
00095   std::cout << "got stringparam = '" << s1 << "'\n";
00096 
00097   int i1 = pmap3->getIntParam("intparam");
00098   std::cout << "got intparam = '" << i1 << "'\n";
00099 
00100   double d1 = pmap3->getDoubleParam("doubleparam");
00101   std::cout << "got doubleparam = '" << d1 << "'\n";
00102 
00103   rutz::shared_ptr<ParamMap> pmap4 = pmap3->getSubpmap("submap");
00104 
00105   std::string s2 = pmap4->getStringParam("submapstringparam");
00106   std::cout << "got submap.submapstringparam = '" << s2 << "'\n";
00107 
00108   int i2 = pmap4->getIntParam("submapintparam");
00109   std::cout << "got submap.submapintparam = '" << i2 << "'\n";
00110 
00111   int sz = pmap4->getIntParam("num_array");
00112   std::cout << "got submap.num_array = '" << sz << "'\n";
00113   for (int i = 0; i < sz; ++i)
00114     {
00115       int v = pmap4->getIntParam(sformat("array%d", i));
00116       std::cout << "got submap.array" << i << " = '" << v << "'\n";
00117     }
00118 }
00119 
00120 // ######################################################################
00121 /* So things look consistent in everyone's emacs... */
00122 /* Local Variables: */
00123 /* mode: c++ */
00124 /* indent-tabs-mode: nil */
00125 /* End: */
00126 
00127 #endif // TESTSUITE_TEST_PARAMMAP_C_DEFINED
Generated on Sun May 8 08:42:22 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3