1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #include "var_manager.hpp"
28 VarManager::VarManager( intf_thread_t *pIntf ): SkinObject( pIntf ),
29 m_pTooltipText( NULL ), m_pHelpText( NULL )
31 m_pTooltipText = new VarText( pIntf );
32 m_pHelpText = new VarText( pIntf, false );
36 VarManager::~VarManager()
38 // Delete the anonymous variables
39 while( !m_anonVarList.empty() )
41 m_anonVarList.pop_back();
44 // Delete the variables in the reverse order they were added
45 list<string>::const_iterator it1;
46 for( it1 = m_varList.begin(); it1 != m_varList.end(); it1++ )
51 delete m_pTooltipText;
53 // Warning! the help text must be the last variable to be deleted,
54 // because VarText destructor references it (FIXME: find a cleaner way?)
59 VarManager *VarManager::instance( intf_thread_t *pIntf )
61 if( ! pIntf->p_sys->p_varManager )
63 VarManager *pVarManager;
64 pVarManager = new VarManager( pIntf );
67 pIntf->p_sys->p_varManager = pVarManager;
70 return pIntf->p_sys->p_varManager;
74 void VarManager::destroy( intf_thread_t *pIntf )
76 if( pIntf->p_sys->p_varManager )
78 delete pIntf->p_sys->p_varManager;
79 pIntf->p_sys->p_varManager = NULL;
84 void VarManager::registerVar( const VariablePtr &rcVar, const string &rName )
86 m_varMap[rName] = rcVar;
87 m_varList.push_front( rName );
91 void VarManager::registerVar( const VariablePtr &rcVar )
93 m_anonVarList.push_back( rcVar );
97 Variable *VarManager::getVar( const string &rName )
99 if( m_varMap.find( rName ) != m_varMap.end() )
101 return m_varMap[rName].get();
110 Variable *VarManager::getVar( const string &rName, const string &rType )
112 if( m_varMap.find( rName ) != m_varMap.end() )
114 Variable *pVar = m_varMap[rName].get();
115 // Check the variable type
116 if( pVar->getType() != rType )
118 msg_Warn( getIntf(), "variable %s has incorrect type (%s instead"
119 " of (%s)", rName.c_str(), pVar->getType().c_str(),
135 void VarManager::registerConst( const string &rName, const string &rValue)
137 m_constMap[rName] = rValue;
141 string VarManager::getConst( const string &rName )
143 return m_constMap[rName];