|
MASA-Core
|
00001 /******************************************************************************* 00002 * 00003 * Copyright (c) 2010-2015 Edans Sandes 00004 * 00005 * This file is part of MASA-Core. 00006 * 00007 * MASA-Core is free software: you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation, either version 3 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * MASA-Core is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with MASA-Core. If not, see <http://www.gnu.org/licenses/>. 00019 * 00020 ******************************************************************************/ 00021 00022 #include <stdlib.h> 00023 00024 #include "Properties.hpp" 00025 #include <stdio.h> 00026 #include <string.h> 00027 #include <stdlib.h> 00028 00029 Properties::Properties() { 00030 00031 } 00032 00033 Properties::Properties(const Properties& orig) { 00034 } 00035 00036 Properties::~Properties() { 00037 } 00038 00039 int Properties::initialize(string filename) { 00040 FILE* f = fopen(filename.c_str(), "r"); 00041 if (f == NULL) { 00042 return 0; // TODO lancar excecao 00043 } 00044 char str[500]; 00045 while (fgets(str, sizeof(str), f) != NULL) { 00046 string line(str); 00047 line.resize(line.size()-1); // Remove white space 00048 int pos = line.find('='); 00049 if (pos > 0) { 00050 string key = line.substr(0, pos); 00051 string value = line.substr(pos+1, string::npos); 00052 printf("%s = %s\n", key.c_str(), value.c_str()); 00053 propertyMap[key] = value; 00054 } 00055 } 00056 fclose(f); 00057 return 1; 00058 } 00059 00060 string Properties::get_property(string key) { 00061 return propertyMap[key]; 00062 } 00063 00064 int Properties::get_property_int(string key) { 00065 return atoi(propertyMap[key].c_str()); 00066 }
1.7.6.1