/* * Copyright (C) 2021 ~ 2022 Deepin Technology Co., Ltd. * * Author: weizhixiang * * Maintainer: weizhixiang * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef KEYFILE_H #define KEYFILE_H #include #include #include typedef std::map KeyMap; typedef std::map MainKeyMap; // 解析ini、desktop文件类 class KeyFile { public: explicit KeyFile(char separtor = ';'); ~KeyFile(); bool getBool(const std::string §ion, const std::string &key, bool defaultValue = false); void setBool(const std::string §ion, const std::string &key, const std::string &defaultValue = "false"); std::vector getBoolList(const std::string §ion, const std::string &key, bool defaultValue = false); int getInt(const std::string §ion, const std::string &key, int defaultValue = 0); std::vector getIntList(const std::string §ion, const std::string &key, int defaultValue = 0); int64_t getInt64(const std::string §ion, const std::string &key, int64_t defaultValue = 0); uint64_t getUint64(const std::string §ion, const std::string &key, int64_t defaultValue = 0); float getFloat(const std::string §ion, const std::string &key, float defaultValue = 0); std::string getStr(const std::string §ion, const std::string &key, std::string defaultValue = ""); bool containKey(const std::string §ion, const std::string &key); std::string getLocaleStr(const std::string §ion, const std::string &key, std::string defaultLocale = ""); std::vector getStrList(const std::string §ion, const std::string &key); std::vector getLocaleStrList(const std::string §ion, const std::string &key, std::string defaultLocale = ""); void setKey(const std::string §ion, const std::string &key, const std::string &value); bool saveToFile(const std::string &filePath); bool loadFile(const std::string &filePath); std::vector getMainKeys(); std::string getFilePath() { return m_filePath; } // for test void print(); private: MainKeyMap m_mainKeyMap; // section -> key : value std::string m_filePath; FILE *m_fp; bool m_modified; char m_listSeparator; }; #endif // KEYFILE_H