cartographer_common_configuration_file_resolver

class FileResolver read parameter file lua programming interface

Most cartographer interface function is defined as a pure virtual function, then achieved by another subclass.

As FileResolver categories:

class FileResolver {
 public:
  virtual ~FileResolver() {}
  virtual std::string GetFullPathOrDie(const std::string& basename) = 0;
  virtual std::string GetFileContentOrDie(const std::string& basename) = 0;
};

Method to realize:

// configuration_file_resolver.h
class ConfigurationFileResolver : public FileResolver {
public:
  explicit ConfigurationFileResolver(
      const std::vector<std::string>& configuration_files_directories);

  std::string GetFullPathOrDie(const std::string& basename) override;  //override 标记该函数为虚函数,必须定义,具体用法,参考小贴士。
  std::string GetFileContentOrDie(const std::string& basename) override;

 private:
  std::vector<std::string> configuration_files_directories_;
};
  • function:

    • GetFullPathOrDie(const std::string& basename) : basename 文件名

      By file name and path parameters, find the corresponding file and returns the result.

      The results are: filename contains full path information. If you can not find the file, terminate the program, print log: LOG (fatal)

    • GetFileContentOrDie(const std::string& basename) :

      Get the file contents by file name, type is stored as a string and returns a string. If you step to find the file, terminate the program.

  • parameter:

    • configuration_files_directories_ parameter path

carto code references Description:

ConfigurationFileResolver—> nodeOptions(carto节点参数配置)

[-] D:\cartographer\cartographer_ros-master\cartographer_ros-master\cartographer_ros\cartographer_ros\node_options.cc


Tips:

  1. override usage

    In the member function declaration or definition, override function is a virtual function to ensure that the override and from base class virtual function.
    Position: operator after the function call, the function or pure virtual function identifier "= 0" before.

    Do not use override:

    #include <iostream>
    using namespace std;
    
    class Base
    {
    public:
     virtual void foo() { cout << "Base::foo" << endl; }
     virtual void goo() { cout << "Base::goo" << endl; }
     // ...
    };
    
    class Derived : public Base
    {
    public:
     void foo() { cout << "Derived::foo" << endl; }
     void gao() { cout << "Derived::goo" << endl; } // 错误的将goo写成了gao,但编译器并不会给出提示
     // ...
    };
    
    int main(void)
    {
     Derived d;
     d.foo();                  // Derived::foo
     d.goo();                  // Base::goo 很明显,这不是我们想要的结果
    
     return 0;
    }

    Use override:

    #include <iostream>
    using namespace std;
    
    class Base
    {
    public:
        virtual void foo()
        {
            cout << "Base::foo()" << endl;
        }
    
        virtual void bar()
        {
            cout << "Base::bar()" << endl;
        }
    
        void goo()
        {
            cout << "Base::goo()" << endl;
        }
    };
    
    class Derived : public Base
    {
    public:
        void foo() override          // ok
        {
            cout << "Derived::foo()" << endl;
        }
    
        void foo() const override    // error: Derived::foo does not override. signature mismatch.
        {
            cout << "Derived::foo()" << endl;
        }
    
        void goo() override          // error: Base::goo is not virtual
        {
            cout << "Derived::goo()" << endl;
        }
    
        void bao() override          // error: 将bar误写成了bao,且基类中无名为bao的虚函数,
        {                            // 由于使用了override,编译器会检测出此错误
            cout << "Derived::bao()" << endl;
        }
    };

    When using the override member function of the derived class, the base class if no such function or not function in the base class virtual function, the compiler will give an error message related.

The main content from: https://blog.csdn.net/linuxwuj/article/details/83183381

Guess you like

Origin www.cnblogs.com/heimazaifei/p/12435845.html