⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 configuration.cpp

📁 开源的电子海图程序
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/* GHelm - Nautical Navigation Software * Copyright (C) 2004 Jon Michaelchuck * * This application is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * This software 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 software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA. */#include <iostream>#include <fstream>#include "configuration.h"#include "util.h"/** * Constructor */Configuration::Configuration(){    SetupObjectNameNumMap();}/** * Destructor */Configuration::~Configuration(){    // FIXME delete cvgs..     }/** * Load configuration from a directory * @param d path of directory * @return 0 on success, -1 on failure */int Configuration::LoadConfiguration(boost::filesystem::path &d){    dir = d;    if (LoadObjectNameFile() < 0) {        std::cerr << "Configuration::LoadConfiguration():"                  << " Error loading object name file from config dir "                  << dir.string() << std::endl;        return -1;    }    if (LoadPointCVGFile() < 0) {        std::cerr << "Configuration::LoadConfiguration():"                  << " Error loading point cvg file from config dir "                  << dir.string() << std::endl;        return -1;    }    if (LoadLineDrawPropFile() < 0) {        std::cerr << "Configuration::LoadConfiguration():"                  << " Error loading line draw prop file from config dir "                  << dir.string() << std::endl;        return -1;    }    if (LoadAreaDrawPropFile() < 0) {        std::cerr << "Configuration::LoadConfiguration():"                  << " Error loading area draw prop file from config dir "                  << dir.string() << std::endl;        return -1;    }    if (LoadCatalogFile() < 0) {        std::cerr << "Configuration::LoadConfiguration():"                  << " Error loading catalog file from config dir "                  << dir.string() << std::endl;        return -1;    }    return 0;}/** * Load the object name file from the current config dir * @return -1 on failure, 0 on success */int Configuration::LoadObjectNameFile(){    boost::filesystem::ifstream file;    file.open(dir / "objectnames");    if (!file) {        std::cerr << "Configuration::LoadObjectNameFile(): Couldn't open file "                  << (dir / "objectnames").string() << std::endl;        return -1;    }    std::string field;    while(!file.eof()) {        std::string int_name;        std::string string_name;        std::getline(file, int_name, ' ');        std::getline(file, string_name);        int_name = remove_whitespace(int_name);        string_name = remove_whitespace(string_name);        if (int_name != "" && string_name != "") {            if (object_name_num_map[int_name])                object_num_fullname_map[object_name_num_map[int_name]] =                                                                string_name;        }    }    file.close();    return 0;}/** * Load the point:cvg file from the current config dir * @return -1 on failure, 0 on success */int Configuration::LoadPointCVGFile(){    boost::filesystem::ifstream file;    file.open(dir / "pointcvg");    if (!file) {        std::cerr << "Configuration::LoadPointCVGFile():"                  << "Couldn't open file " << (dir / "pointcvg").string()                  << std::endl;        return -1;    }    std::string field;    while(!file.eof()) {        std::string int_name;        std::string cvg_name;        std::string drawn;        std::getline(file, int_name, ' ');        std::getline(file, cvg_name, ' ');        std::getline(file, drawn);        int_name = remove_whitespace(int_name);        cvg_name = remove_whitespace(cvg_name);        drawn = remove_whitespace(drawn);        boost::filesystem::path cvg_path = dir / "data" / cvg_name;        cvg_name = cvg_path.string();        if (int_name != "" && cvg_name != "") {            // avoid loading multiple copies of an cvg            CVG *cvg = NULL;            bool loaded = false;            std::map<int, CVG *>::const_iterator it;            std::map<int, CVG *>::const_iterator end(point_cvgs.end());            for (it = point_cvgs.begin(); it != end; ++it) {                if (it->second->filename == cvg_name) {                    loaded = true;                    cvg = it->second;                    break;                }            }            if (!loaded) {                cvg = new CVG;                 if (cvg->Load(cvg_path.string().c_str()) < 0) {                    std::cerr << "Configuration::LoadPointCVGFile():"                              << " Error loading cvg file " << cvg_name                              << std::endl;                    delete cvg;                    return -1;                }            }            point_cvgs[object_name_num_map[int_name]] = cvg;            if (drawn == "true")                points_drawn[object_name_num_map[int_name]] = true;            else                points_drawn[object_name_num_map[int_name]] = false;        }    }     file.close();    return 0;}/** * Load the area drawing property file from the current config dir * @return -1 on failure, 0 on success */int Configuration::LoadAreaDrawPropFile(){    boost::filesystem::ifstream file;    file.open(dir / "areadrawprop");    if (!file) {        std::cerr << "Configuration::LoadAreaDrawPropFile():"                  << "Couldn't open file " << (dir / "areadrawprop").string()                  << std::endl;        return -1;    }    std::string field;    while(!file.eof()) {        std::string int_name;        std::string r, g, b;        std::string drawn;        std::getline(file, int_name, ' ');        std::getline(file, r, ' ');        std::getline(file, g, ' ');        std::getline(file, b, ' ');        std::getline(file, drawn);        drawn = remove_whitespace(drawn);        area_drawprop_t adp;        adp.rgb[0] = atof(r.c_str());         adp.rgb[1] = atof(g.c_str());         adp.rgb[2] = atof(b.c_str());         if (drawn == "true")            areas_drawn[object_name_num_map[int_name]] = true;        else            areas_drawn[object_name_num_map[int_name]] = false;        area_drawprops[object_name_num_map[int_name]] = adp;    }     file.close();    return 0;}/** * Load the line drawing property file from the current config dir * @return -1 on failure, 0 on success */int Configuration::LoadLineDrawPropFile(){    boost::filesystem::ifstream file;    file.open(dir / "linedrawprop");    if (!file) {        std::cerr << "Configuration::LoadLineDrawPropFile():"                  << "Couldn't open file " << (dir / "linedrawprop").string()                  << std::endl;        return -1;    }    std::string field;    while(!file.eof()) {        std::string int_name;        std::string r, g, b;        std::string size;        std::string drawn;        std::getline(file, int_name, ' ');        std::getline(file, r, ' ');        std::getline(file, g, ' ');        std::getline(file, b, ' ');        std::getline(file, size, ' ');        std::getline(file, drawn);

⌨️ 快捷键说明

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