From 37f5d755f11501ce8e92d1c1c2d922121b49dfca Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sun, 8 Dec 2013 19:11:22 +0100 Subject: [PATCH] break out header file in compile unit --- Util/IniFile.cpp | 100 +++++++++++++++++++++++++++++++++++++++++++++++ Util/IniFile.h | 67 ++++--------------------------- 2 files changed, 108 insertions(+), 59 deletions(-) create mode 100644 Util/IniFile.cpp diff --git a/Util/IniFile.cpp b/Util/IniFile.cpp new file mode 100644 index 000000000..8d0dc5845 --- /dev/null +++ b/Util/IniFile.cpp @@ -0,0 +1,100 @@ +/* + +Copyright (c) 2013, Project OSRM, Dennis Luxen, others +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list +of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#include "IniFile.h" + +#include "OSRMException.h" +#include "../DataStructures/HashTable.h" + +#include +#include +#include + +#include + +IniFile::IniFile(const char * config_filename) { + boost::filesystem::path config_file(config_filename); + if ( !boost::filesystem::exists( config_file ) ) { + std::string error = std::string(config_filename) + " not found"; + throw OSRMException(error); + } + if ( 0 == boost::filesystem::file_size( config_file ) ) { + std::string error = std::string(config_filename) + " is empty"; + throw OSRMException(error); + } + + boost::filesystem::ifstream config( config_file ); + std::string line; + if (config.is_open()) { + while ( config.good() ) { + getline (config,line); + std::vector tokens; + Tokenize(line, tokens); + if(2 == tokens.size() ) { + parameters.insert(std::make_pair(tokens[0], tokens[1])); + } + } + config.close(); + } +} + +std::string IniFile::GetParameter(const std::string & key){ + return parameters.Find(key); +} + +std::string IniFile::GetParameter(const std::string & key) const { + return parameters.Find(key); +} + +bool IniFile::Holds(const std::string & key) const { + return parameters.Holds(key); +} + +void IniFile::SetParameter(const char* key, const char* value) { + SetParameter(std::string(key), std::string(value)); +} + +void IniFile::SetParameter(const std::string & key, const std::string & value) { + parameters.insert(std::make_pair(key, value)); +} + +void IniFile::Tokenize( + const std::string& str, + std::vector& tokens, + const std::string& delimiters +) { + std::string::size_type lastPos = str.find_first_not_of(delimiters, 0); + std::string::size_type pos = str.find_first_of(delimiters, lastPos); + + while (std::string::npos != pos || std::string::npos != lastPos) { + std::string temp = str.substr(lastPos, pos - lastPos); + boost::trim(temp); + tokens.push_back( temp ); + lastPos = str.find_first_not_of(delimiters, pos); + pos = str.find_first_of(delimiters, lastPos); + } +} diff --git a/Util/IniFile.h b/Util/IniFile.h index 80f33f728..0a9c26216 100644 --- a/Util/IniFile.h +++ b/Util/IniFile.h @@ -28,82 +28,31 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef INI_FILE_H_ #define INI_FILE_H_ -#include "OSRMException.h" #include "../DataStructures/HashTable.h" -#include -#include -#include - -#include -#include #include +#include class IniFile { public: - IniFile(const char * config_filename) { - boost::filesystem::path config_file(config_filename); - if ( !boost::filesystem::exists( config_file ) ) { - std::string error = std::string(config_filename) + " not found"; - throw OSRMException(error); - } - if ( 0 == boost::filesystem::file_size( config_file ) ) { - std::string error = std::string(config_filename) + " is empty"; - throw OSRMException(error); - } + IniFile(const char * config_filename); - boost::filesystem::ifstream config( config_file ); - std::string line; - if (config.is_open()) { - while ( config.good() ) { - getline (config,line); - std::vector tokens; - Tokenize(line, tokens); - if(2 == tokens.size() ) { - parameters.insert(std::make_pair(tokens[0], tokens[1])); - } - } - config.close(); - } - } + std::string GetParameter(const std::string & key); - std::string GetParameter(const std::string & key){ - return parameters.Find(key); - } + std::string GetParameter(const std::string & key) const; - std::string GetParameter(const std::string & key) const { - return parameters.Find(key); - } + bool Holds(const std::string & key) const; - bool Holds(const std::string & key) const { - return parameters.Holds(key); - } + void SetParameter(const char* key, const char* value); - void SetParameter(const char* key, const char* value) { - SetParameter(std::string(key), std::string(value)); - } - - void SetParameter(const std::string & key, const std::string & value) { - parameters.insert(std::make_pair(key, value)); - } + void SetParameter(const std::string & key, const std::string & value); private: void Tokenize( const std::string& str, std::vector& tokens, const std::string& delimiters = "=" - ) { - std::string::size_type lastPos = str.find_first_not_of(delimiters, 0); - std::string::size_type pos = str.find_first_of(delimiters, lastPos); - - while (std::string::npos != pos || std::string::npos != lastPos) { - std::string temp = str.substr(lastPos, pos - lastPos); - boost::trim(temp); - tokens.push_back( temp ); - lastPos = str.find_first_not_of(delimiters, pos); - pos = str.find_first_of(delimiters, lastPos); - } - } + ); HashTable parameters; };