GiNaCRA
0.6.4
|
00001 /* 00002 * GiNaCRA - GiNaC Real Algebra package 00003 * Copyright (C) 2010-2012 Ulrich Loup, Joachim Redies, Sebastian Junges 00004 * 00005 * This file is part of GiNaCRA. 00006 * 00007 * GiNaCRA 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 * GiNaCRA 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 GiNaCRA. If not, see <http://www.gnu.org/licenses/>. 00019 * 00020 */ 00021 00022 00023 #include "SymbolDB.h" 00024 #include "constants.h" 00025 #include "SymbolDB.h" 00026 00027 using GiNaC::symbol; 00028 00039 namespace GiNaCRA 00040 { 00042 // Con- and destructors // 00044 00045 SymbolDB::SymbolDB( std::string stdname ): 00046 mStdName( stdname ) 00047 {} 00048 00050 // Operators // 00052 00053 const symbol SymbolDB::operator []( unsigned i ) const 00054 { 00055 return mVariables[i]; 00056 } 00057 00058 unsigned SymbolDB::operator []( const symbol& v ) const 00059 { 00060 return mSymbollist.at( v ); 00061 00062 } 00063 00064 unsigned SymbolDB::addSymbol() 00065 { 00066 unsigned size = mVariables.size(); 00067 std::stringstream str; 00068 str << size; 00069 std::string name = mStdName + "_" + str.str(); 00070 symbol s = symbol( name ); 00071 mVariables.push_back( s ); 00072 mSymbollist.insert( std::pair<symbol, unsigned>( s, size )); 00073 return size; 00074 } 00075 00076 unsigned SymbolDB::addSymbol( std::string name ) 00077 { 00078 symbol s = symbol( name ); 00079 map<symbol, unsigned>::const_iterator pos = mSymbollist.find( s ); 00080 if( pos != mSymbollist.end() ) 00081 return pos->second; 00082 unsigned size = mVariables.size(); 00083 mSymbollist.insert( std::pair<symbol, unsigned>( s, size )); 00084 mVariables.push_back( s ); 00085 return size; 00086 } 00087 00088 unsigned SymbolDB::addSymbol( symbol s ) 00089 { 00090 map<symbol, unsigned>::const_iterator pos = mSymbollist.find( s ); 00091 if( pos != mSymbollist.end() ) 00092 return pos->second; 00093 unsigned size = mVariables.size(); 00094 mSymbollist.insert( std::pair<symbol, unsigned>( s, size )); 00095 mVariables.push_back( s ); 00096 return size; 00097 } 00098 00099 } // namespace GiNaCRA 00100