parse.h

来自「该文件是包含了机器人足球比赛中的整个系统的代码」· C头文件 代码 · 共 46 行

H
46
字号
#ifndef PARSE_H
#define PARSE_H

#include <vector>
#include <stdlib.h>
#include <stdio.h>

// these define the maximum number of characters in a key, and in a value
#define MAX_KEYLENGTH 64
#define MAX_VALLENGTH 64

using namespace std;

struct Pair {
  char* key; // note max lengths above
  char* val;
};

class Parse {
  public:
    Parse();
    void WriteFile(const char* filename, const char* buffer, int buffersize);
    void ParseFile(const char* filename);

    // probably should never call this externally, but there's no technical reason why you can't ...
    void RegisterPair(char* k, char* v);

    int GetAsInt(const char* k);
    bool GetAsBool(const char* k);
    char* GetAsString(const char* k);
    double GetAsDouble(const char* k);

  private:
    // don't mess with this.
    Pair* FindPair(const char* k);
    Pair* FindPairFailFast(const char* k);

    bool IsTerminator(const char c);
    bool IsLF(const char c);
    bool IsSpace(const char c);

    vector<Pair> keyValuePairs;
};

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?