]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/var_manager.cpp
e4c11bae4141554590dd38555e1d13d2769e5483
[vlc] / modules / gui / skins2 / src / var_manager.cpp
1 /*****************************************************************************
2  * var_manager.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: var_manager.cpp,v 1.2 2004/01/11 17:12:17 asmax Exp $
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@via.ecp.fr>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #include "var_manager.hpp"
26
27
28 VarManager::VarManager( intf_thread_t *pIntf ): SkinObject( pIntf ),
29     m_tooltipText( pIntf ), m_helpText( pIntf )
30 {
31 }
32
33
34 VarManager *VarManager::instance( intf_thread_t *pIntf )
35 {
36     if( ! pIntf->p_sys->p_varManager )
37     {
38         VarManager *pVarManager;
39         pVarManager = new VarManager( pIntf );
40         if( pVarManager )
41         {
42             pIntf->p_sys->p_varManager = pVarManager;
43         }
44     }
45     return pIntf->p_sys->p_varManager;
46 }
47
48
49 void VarManager::destroy( intf_thread_t *pIntf )
50 {
51     if( pIntf->p_sys->p_varManager )
52     {
53         delete pIntf->p_sys->p_varManager;
54         pIntf->p_sys->p_varManager = NULL;
55     }
56 }
57
58
59 void VarManager::registerVar( const VariablePtr &rcVar, const string &rName )
60 {
61     m_varMap[rName] = rcVar;
62 }
63
64
65 Variable *VarManager::getVar( const string &rName )
66 {
67     if( m_varMap.find( rName ) != m_varMap.end() )
68     {
69         return m_varMap[rName].get();
70     }
71     else
72     {
73         return NULL;
74     }
75 }
76
77
78 Variable *VarManager::getVar( const string &rName, const string &rType )
79 {
80     if( m_varMap.find( rName ) != m_varMap.end() )
81     {
82         Variable *pVar = m_varMap[rName].get();
83         // Check the variable type
84         if( pVar->getType() != rType )
85         {
86             msg_Warn( getIntf(), "Variable %s has incorrect type (%s instead"
87                       " of (%s)", rName.c_str(), pVar->getType().c_str(),
88                       rType.c_str() );
89             return NULL;
90         }
91         else
92         {
93             return pVar;
94         }
95     }
96     else
97     {
98         return NULL;
99     }
100 }
101