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