00001 #pragma ident "$Id: TimeTag.cpp 360 2007-01-12 02:40:07Z ocibu $"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "TimeTag.hpp"
00028 #include "StringUtils.hpp"
00029
00030 namespace gpstk
00031 {
00032 void TimeTag::scanf( const std::string& str,
00033 const std::string& fmt )
00034 throw( gpstk::InvalidRequest,
00035 gpstk::StringUtils::StringException )
00036 {
00037 try
00038 {
00039
00040 IdToValue info;
00041 getInfo( str, fmt, info );
00042
00043
00044 if( !setFromInfo( info ) )
00045 {
00046 gpstk::InvalidRequest ir( "Incomplete time specification." );
00047 GPSTK_THROW( ir );
00048 }
00049 }
00050 catch( gpstk::StringUtils::StringException& se )
00051 {
00052 GPSTK_RETHROW( se );
00053 }
00054 }
00055
00056 void TimeTag::getInfo( const std::string& str,
00057 const std::string& fmt,
00058 IdToValue& info )
00059 throw( gpstk::StringUtils::StringException )
00060 {
00061 try
00062 {
00063 using namespace gpstk::StringUtils;
00064
00065
00066 std::string f = fmt;
00067 std::string s = str;
00068
00069
00070
00071 while( !s.empty() && !f.empty() )
00072 {
00073
00074
00075
00076 while ( !s.empty() &&
00077 !f.empty() &&
00078 ( f[0] != '%' ) )
00079 {
00080
00081 s.erase(0,1);
00082 f.erase(0,1);
00083 }
00084
00085
00086 if ( s.empty() || f.empty() )
00087 break;
00088
00089
00090 f.erase( 0, 1 );
00091
00092 std::string::size_type fieldLength = std::string::npos;
00093 char delimiter = 0;
00094
00095 if (false)
00096 std::cout << "--------------" << std::endl
00097 << "f:\"" << f << "\"" << std::endl
00098 << "s:\"" << s << "\"" << std::endl;
00099
00100 if( !isalpha( f[0] ) )
00101 {
00102
00103
00104
00105 fieldLength = asInt( f );
00106
00107
00108
00109 while ( !f.empty() && !isalpha( f[0] ) )
00110 f.erase( 0, 1 );
00111
00112 if ( f.empty() )
00113 break;
00114 }
00115 else
00116 {
00117
00118
00119 if ( f.size() > 1 )
00120 {
00121 if ( f[1] != '%' )
00122 {
00123 delimiter = f[1];
00124
00125 stripLeading(s);
00126 fieldLength = s.find( delimiter, 0 );
00127 }
00128 else
00129 {
00130
00131
00132
00133 fieldLength = 1;
00134 }
00135 }
00136 }
00137
00138
00139 std::string value( s.substr( 0, fieldLength ) );
00140
00141
00142 info[ f[0] ] = value;
00143
00144
00145 stripLeading( s, value, 1 );
00146
00147
00148 f.erase( 0, 1 );
00149
00150
00151 if (delimiter != 0)
00152 {
00153 f.erase(0,1);
00154 s.erase(0,1);
00155 }
00156 }
00157 }
00158 catch( gpstk::StringUtils::StringException& se )
00159 {
00160 GPSTK_RETHROW( se );
00161 }
00162 }
00163
00164 }
00165
00166 std::ostream& operator<<( std::ostream& s,
00167 const gpstk::TimeTag& t )
00168 {
00169 s << t.printf( t.getDefaultFormat() );
00170 return s;
00171 }