GPSTK日志五 TimeTag

来源:互联网 发布:山东省卫生网络直报 编辑:程序博客网 时间:2024/06/06 01:50

         看完 commontime 的定义又回过头来看了下 TimeTag 这个类,这是一个具体时间系统的基类,所以楼主觉得有必要仔细的介绍下里面的方法。注意 commontime 并不是 TimeTag 的子类,之所以要先介绍它,应为它是所有时间系统转转的一个中间过程。转换的实现由 TimeTag 的虚函数定义的以下两个方法完成:  

      virtual CommonTime convertToCommonTime() const       
         throw( gpstk::InvalidRequest ) = 0;    
           //对应时间系统转换为CommonTime 
      
      virtual void convertFromCommonTime( const CommonTime& ct )
         throw( gpstk::InvalidRequest ) = 0;
     // CommonTime  转换为对应时间系统

        这里顺道对上面函数的几个基本语法注明下吧, 函数后面的 const 意味着函数返回值是不可修改的,throw 表示该函数跑出的异常,

      func() throw(type) ,会抛出某种异常

      func() throw(),不会抛出

      func() throw(...),可能是任何类型的异常

      函数后面 = 0;表示这是一个纯虚函数,没有具体的函数体,只有一个函数声名,函数体留给它的派生类来实现,而且,这个类的派生类必须重载全部纯虚函数(重载的时候不能指定为纯虚)。 可以理解为表示将这个函数指针设置为0。

       两个纯虚打印函数,  

      virtual std::string printf( const std::string& fmt ) const throw( gpstk::StringUtils::StringException ) = 0;
      virtual std::string printError( const std::string& fmt ) const throw( gpstk::StringUtils::StringException ) = 0;

       virtual void scanf( const std::string& str,  const std::string& fmt )
 throw( gpstk::InvalidRequest,  gpstk::StringUtils::StringException );
   // This function sets this object to the time stored in the given 这个具体的结合实例来说

     typedef std::map< char, std::string> IdToValue;  // 定义map容器

     static void getInfo( const std::string& str, const std::string& fmt,IdToValue& info )
 throw( gpstk::StringUtils::StringException );
 //这个是 scanf 成员函数实现的具体方法,在sacnf中需要调用它

      virtual bool setFromInfo( const IdToValue& info )   throw() = 0;   // 将对象按 IdToValue 格式进行设置
      virtual std::string getPrintChars() const throw() = 0;     // 这个留在下一篇讲吧
      virtual std::string getDefaultFormat() const throw() = 0;   // 返回一个打印格式的字符串的 

      virtual bool isValid() const throw() = 0;   // 检查对象的成员是否有效

      virtual void reset() throw() = 0;   // 将对象设置为默认值

        virtual std::string asString() const throw( gpstk::StringUtils::StringException )    // 这个函数前面已经说过
                  { return printf( getDefaultFormat() ); }


         /// Hey, it's an implicit casting operator!  Basically just a lazy
         /// way to get at convertToCommonTime().
       virtual operator CommonTime() const throw(InvalidRequest)  { return convertToCommonTime(); }   //看下原文注释这个没什么好说的
 

         /// This returns the regular expression prefix that is used when 
         /// searching for integer specifiers.
      static inline std::string getFormatPrefixInt()
      { return "%[ 0-]?[[:digit:]]*"; }
      
         /// This returns the regular expression prefix that is used when
         /// searching for float specifiers.
      static inline std::string getFormatPrefixFloat()     
      { return getFormatPrefixInt() + "(\\.[[:digit:]]+)?"; }     // 以上两个均与正则表达式有关

      static inline std::string getError()    //返回一个默认错误信息
      { return "ErrorBadTime"; }