1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 #include "var_manager.hpp"
28 VarManager::VarManager( intf_thread_t *pIntf ): SkinObject( pIntf ),
29 m_tooltipText( pIntf ), m_helpText( pIntf )
34 VarManager::~VarManager()
36 // Delete the variables in the reverse order they were added
37 list<string>::const_iterator it1;
38 for( it1 = m_varList.begin(); it1 != m_varList.end(); it1++ )
43 // Delete the anonymous variables
44 while( !m_anonVarList.empty() )
46 m_anonVarList.pop_back();
51 VarManager *VarManager::instance( intf_thread_t *pIntf )
53 if( ! pIntf->p_sys->p_varManager )
55 VarManager *pVarManager;
56 pVarManager = new VarManager( pIntf );
59 pIntf->p_sys->p_varManager = pVarManager;
62 return pIntf->p_sys->p_varManager;
66 void VarManager::destroy( intf_thread_t *pIntf )
68 if( pIntf->p_sys->p_varManager )
70 delete pIntf->p_sys->p_varManager;
71 pIntf->p_sys->p_varManager = NULL;
76 void VarManager::registerVar( const VariablePtr &rcVar, const string &rName )
78 m_varMap[rName] = rcVar;
79 m_varList.push_front( rName );
83 void VarManager::registerVar( const VariablePtr &rcVar )
85 m_anonVarList.push_back( rcVar );
89 Variable *VarManager::getVar( const string &rName )
91 if( m_varMap.find( rName ) != m_varMap.end() )
93 return m_varMap[rName].get();
102 Variable *VarManager::getVar( const string &rName, const string &rType )
104 if( m_varMap.find( rName ) != m_varMap.end() )
106 Variable *pVar = m_varMap[rName].get();
107 // Check the variable type
108 if( pVar->getType() != rType )
110 msg_Warn( getIntf(), "Variable %s has incorrect type (%s instead"
111 " of (%s)", rName.c_str(), pVar->getType().c_str(),