example_getrecord.cc

00001 // --8<--8<--8<--8<--
00002 //
00003 // Copyright (C) 2006 Smithsonian Astrophysical Observatory
00004 //
00005 // This file is part of suplibxx
00006 //
00007 // suplibxx is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // suplibxx is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with this program; if not, write to the 
00019 //       Free Software Foundation, Inc. 
00020 //       51 Franklin Street, Fifth Floor
00021 //       Boston, MA  02110-1301, USA
00022 //
00023 // -->8-->8-->8-->8--
00024 
00025 #include <iostream>
00026 #include <string>
00027 #include <strstream>
00028 using namespace std;
00029 
00030 #include "io.h"
00031 
00032 int main( int argc, char** argv ) {
00033 
00034   string expected;
00035   string returned;
00036 
00037   {
00038     // Example 1
00039     strstream strstr; 
00040     strstr <<  "  now, is, the, time  ";
00041     expected = "  now, is, the, time  ";
00042     suplib::getrecord( strstr, returned, suplib::READ_PHYS );
00043     cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
00044   }
00045   
00046   {
00047     // Example 2
00048     strstream strstr;
00049     strstr <<  "  now, is, the, time  \n";
00050     expected = "  now, is, the, time";
00051     suplib::getrecord( strstr, returned, suplib::READ_PHYS | suplib::STRIP );
00052     cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
00053   }
00054     
00055   {
00056     // Example 3
00057     strstream strstr;
00058     strstr <<   "  now, is, the, time  \\  \n" 
00059            <<   "  now, is, the, time  \\  \n" 
00060            <<   "  now, is, the, time  ";
00061     expected  = "  now, is, the, time  ";
00062     expected += "  now, is, the, time  ";
00063     expected += "  now, is, the, time  ";
00064     suplib::getrecord( strstr, returned, suplib::READ_LOGICAL );
00065     cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
00066   }
00067   
00068   {
00069     // Example 4
00070     strstream strstr; 
00071     strstr   << "  now, is, the, time  \\  \n"
00072              << "  now, is, the, time  \\  \n"
00073              << "  now, is, the, time  ";
00074     expected  = "  now, is, the, time  \\\n";
00075     expected += "  now, is, the, time  \\\n";
00076     expected += "  now, is, the, time  ";
00077     suplib::getrecord( strstr, returned, suplib::READ_LOGICAL | suplib::CLEAN );
00078     cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
00079   }
00080 
00081   {
00082     // Example 5
00083     strstream strstr; 
00084     strstr  << "  now, is, the, time  \n";
00085     expected = "  now, is, the, time";
00086     suplib::getrecord( strstr, returned, suplib::READ_LOGICAL | suplib::STRIP );
00087     cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
00088   }
00089 
00090   {
00091     // Example 6
00092     strstream strstr;
00093     strstr <<   "  now, is, the, time  \\  \n"
00094            <<   "  now, is, the, time  \\  \n"
00095            <<   "  now, is, the, time  ";
00096     expected  = "  now, is, the, time  ";
00097     expected += "  now, is, the, time  ";
00098     expected += "  now, is, the, time";
00099     suplib::getrecord( strstr, returned, suplib::READ_LOGICAL | suplib::STRIP);
00100     cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
00101   }
00102 
00103   {
00104     // Example 7
00105     strstream strstr;
00106     strstr << "  now, is, the, time  \\  \n"
00107            << "  now, is, the, time  \\  \n"
00108            << "  now, is, the, time  ";
00109     expected  = "  now, is, the, time  \\\n";
00110     expected += "  now, is, the, time  \\\n";
00111     expected += "  now, is, the, time";
00112     suplib::getrecord( strstr, returned, suplib::READ_LOGICAL | suplib::STRIP | suplib::CLEAN );
00113     cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
00114   }
00115 
00116   {
00117     // Example 8
00118     strstream strstr;
00119     strstr   << "  now, is, the, time  -  \n"
00120              << "  now, is, the, time  -  \n"
00121              << "  now, is, the, time  ";
00122     expected  = "  now, is, the, time  ";
00123     expected += "  now, is, the, time  ";
00124     expected += "  now, is, the, time  ";
00125     suplib::getrecord( strstr, returned, suplib::READ_LOGICAL, '\n', '-' );
00126     cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
00127   }
00128 
00129   return 0;
00130 }

Generated on Thu Oct 2 20:49:06 2008 for suplibxx by  doxygen 1.5.6