|
Blender
V2.59
|
00001 /* 00002 * $Id: ExtraTags.cpp 35897 2011-03-30 10:51:01Z jesterking $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * Contributor(s): Nathan Letwory. 00021 * 00022 * ***** END GPL LICENSE BLOCK ***** 00023 */ 00024 00029 #include <stddef.h> 00030 #include <stdlib.h> 00031 #include "BLI_string.h" 00032 00033 #include <iostream> 00034 00035 #include "ExtraTags.h" 00036 00037 ExtraTags::ExtraTags( std::string profile) 00038 { 00039 this->profile = profile; 00040 this->tags = std::map<std::string, std::string>(); 00041 } 00042 00043 ExtraTags::~ExtraTags() 00044 { 00045 } 00046 00047 bool ExtraTags::isProfile( std::string profile) 00048 { 00049 return this->profile == profile; 00050 } 00051 00052 bool ExtraTags::addTag( std::string tag, std::string data) 00053 { 00054 tags[tag] = data; 00055 00056 return true; 00057 } 00058 00059 int ExtraTags::asInt( std::string tag, bool *ok) 00060 { 00061 if(tags.find(tag) == tags.end()) { 00062 *ok = false; 00063 return -1; 00064 } 00065 *ok = true; 00066 return atoi(tags[tag].c_str()); 00067 } 00068 00069 float ExtraTags::asFloat( std::string tag, bool *ok) 00070 { 00071 if(tags.find(tag) == tags.end()) { 00072 *ok = false; 00073 return -1.0f; 00074 } 00075 *ok = true; 00076 return (float)atof(tags[tag].c_str()); 00077 } 00078 00079 std::string ExtraTags::asString( std::string tag, bool *ok) 00080 { 00081 if(tags.find(tag) == tags.end()) { 00082 *ok = false; 00083 return ""; 00084 } 00085 *ok = true; 00086 return tags[tag]; 00087 } 00088 00089 00090 void ExtraTags::setData(std::string tag, short *data) 00091 { 00092 bool ok = false; 00093 int tmp = 0; 00094 tmp = asInt(tag, &ok); 00095 if(ok) 00096 *data = (short)tmp; 00097 } 00098 void ExtraTags::setData(std::string tag, int *data) 00099 { 00100 bool ok = false; 00101 int tmp = 0; 00102 tmp = asInt(tag, &ok); 00103 if(ok) 00104 *data = tmp; 00105 } 00106 void ExtraTags::setData(std::string tag, float *data) 00107 { 00108 bool ok = false; 00109 float tmp = 0.0f; 00110 tmp = asFloat(tag, &ok); 00111 if(ok) 00112 *data = tmp; 00113 } 00114 void ExtraTags::setData(std::string tag, char *data) 00115 { 00116 bool ok = false; 00117 int tmp = 0; 00118 tmp = asInt(tag, &ok); 00119 if(ok) 00120 *data = (char)tmp; 00121 } 00122