/* =========================================================================== maya2q3 - export .md3 files from maya Copyright (C) 2005 HermitWorks Entertainment Corporation Portions of this file Copyright (C) Id Software, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. =========================================================================== */ #include "common.h" namespace q3 { const std::string& Entity::AsString( const std::string &key ) const { EntMap::const_iterator iter = pairs.find( key ); if( iter == pairs.end() ) throw KeyNotFound(); return iter->second; } const std::string& Entity::AsString( const std::string &key, const std::string &def ) const { try { return AsString( key ); } catch( KeyNotFound& ) { return def; } } bool Entity::AsBool( const std::string &key ) const { return atoi( AsString( key ).c_str() ) != 0; } bool Entity::AsBool( const std::string &key, bool def ) const { try { return AsBool( key ); } catch( KeyNotFound& ) { return def; } } float Entity::AsFloat( const std::string &key ) const { return (float)atof( AsString( key ).c_str() ); } float Entity::AsFloat( const std::string &key, float def ) const { try { return AsFloat( key ); } catch( KeyNotFound& ) { return def; } } vec3 Entity::AsVec3( const std::string &key ) const { vec3 ret; const char *str = AsString( key ).c_str(); ParseVector( ret, 3, str, false ); return ret; } vec3 Entity::AsVec3( const std::string &key, const vec3 &def ) const { try { return AsVec3( key ); } catch( KeyNotFound& ) { return def; } } /* static */ std::vector< Entity > Entity::ParseEntities( const char *entStr ) { std::vector< Entity > ret; parse_token tok, val; for( ; ; ) { ParseExt( entStr, true, tok ); if( tok == "" ) break; demand( tok == "{", "Missing { at start of entity block." ); Entity ent; for( ; ; ) { ParseExt( entStr, true, tok ); demand( tok != "", "Missing } in entity block." ); if( tok == "}" ) break; ParseExt( entStr, true, val ); demand( val != "", "Missing value part in entity." ); strlwr( tok ); ent.pairs.insert( EntMap::value_type( std::string( tok ), std::string( val ) ) ); } ret.push_back( ent ); } return ret; } };