处理不同的输入文件类型

时间:2016-09-14 17:22:25

标签: c++ gps

我正在创建一个程序来读取RINEX文件(本质上是GPS文本文件)并将观察结果传递给一个单独的类来处理它们。有几个RINEX版本,现在有7种常用格式(v2,v2.10,v2.11,v3.0,v3.01,v3.01,v3.02,v3.03),每个都有一个数据如何在文件中呈现的变化,因此需要不同的方式来读取文件。什么是最合适的处理方式,所以如果新版本出来,它很容易处理。另外,如何在运行时处理输入,一个用户

现在我正在考虑使用基类RinexObs并为每个版本创建一个超类。有更优雅的方式来处理这个问题吗?

我缩短了下面的代码,但显示了我的目标。我知道这是一种效率低下的方式,只是无法绕过其他方式来做这件事。

class RinexObs {
    // All possible rinex versions
    enum class Versions {
       v2_0,
       v2_10,
       v2_11,
       // and others
     }
    // Override this method with every superclass 
    virtual double GetData() = 0;
    // Method to determine the Rinex version. I cant tell
    // the rinex version until after opening the file and reading the first
    // the first line, hence why this method is in the base class.
    Versions GetRinexVersion () { };
}; // end of class RinexObs

class RinexV2 : public RinexObs {
    // Override base class
     double GetData() {
     // Implement code how to read V2 files
  }
}; // end of class RinexV2

class RinexV210 : public RinexObs {
    // Override base class
    double GetData() {
        // Implement code how to read V2.10 files
   }
}; // end of class RinexV210

int main() {
    RinexObs input_file;
    // ... code to open file properly
    // Get the rinex version
    RinexObs::Versions rinex_version = input_file.GetRinexVersion();
    // Something to hold the data from the rinex file
    double data = 0;
    // Based off the rinex_version read the data
    switch(rinex_version) {
    case RinexObs::Versions::v2_0:
        input_file = new RinexV2();
        data = input_file.GetData();
        break;
    // all other cases
   } // end of switch
} // end of main

0 个答案:

没有答案