]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/var_manager.cpp
* bitmap_font.cpp: full support of text bitmap font
[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.3 2004/01/24 13:08:12 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()
35 {
36     // Delete the variables in the reverse order they were added
37     list<string>::const_iterator it;
38     for( it = m_varList.begin(); it != m_varList.end(); it++ )
39     {
40         m_varMap.erase(*it);
41     }
42 }
43
44
45 VarManager *VarManager::instance( intf_thread_t *pIntf )
46 {
47     if( ! pIntf->p_sys->p_varManager )
48     {
49         VarManager *pVarManager;
50         pVarManager = new VarManager( pIntf );
51         if( pVarManager )
52         {
53             pIntf->p_sys->p_varManager = pVarManager;
54         }
55     }
56     return pIntf->p_sys->p_varManager;
57 }
58
59
60 void VarManager::destroy( intf_thread_t *pIntf )
61 {
62     if( pIntf->p_sys->p_varManager )
63     {
64         delete pIntf->p_sys->p_varManager;
65         pIntf->p_sys->p_varManager = NULL;
66     }
67 }
68
69
70 void VarManager::registerVar( const VariablePtr &rcVar, const string &rName )
71 {
72     m_varMap[rName] = rcVar;
73     m_varList.push_front(rName);
74 }
75
76
77 Variable *VarManager::getVar( const string &rName )
78 {
79     if( m_varMap.find( rName ) != m_varMap.end() )
80     {
81         return m_varMap[rName].get();
82     }
83     else
84     {
85         return NULL;
86     }
87 }
88
89
90 Variable *VarManager::getVar( const string &rName, const string &rType )
91 {
92     if( m_varMap.find( rName ) != m_varMap.end() )
93     {
94         Variable *pVar = m_varMap[rName].get();
95         // Check the variable type
96         if( pVar->getType() != rType )
97         {
98             msg_Warn( getIntf(), "Variable %s has incorrect type (%s instead"
99                       " of (%s)", rName.c_str(), pVar->getType().c_str(),
100                       rType.c_str() );
101             return NULL;
102         }
103         else
104         {
105             return pVar;
106         }
107     }
108     else
109     {
110         return NULL;
111     }
112 }
113