]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/var_manager.cpp
91f65fef838df636287dac75f2d1fa57ac186301
[vlc] / modules / gui / skins2 / src / var_manager.cpp
1 /*****************************************************************************
2  * var_manager.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 the VideoLAN team
5  * $Id$
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #include "var_manager.hpp"
26
27
28 VarManager::VarManager( intf_thread_t *pIntf ): SkinObject( pIntf ),
29     m_pTooltipText( NULL ), m_pHelpText( NULL )
30 {
31     m_pTooltipText = new VarText( pIntf );
32     m_pHelpText = new VarText( pIntf, false );
33 }
34
35
36 VarManager::~VarManager()
37 {
38     // Delete the variables in the reverse order they were added
39     list<string>::const_iterator it1;
40     for( it1 = m_varList.begin(); it1 != m_varList.end(); it1++ )
41     {
42         m_varMap.erase(*it1);
43     }
44
45     // Delete the anonymous variables
46     while( !m_anonVarList.empty() )
47     {
48         m_anonVarList.pop_back();
49     }
50
51
52     delete m_pTooltipText;
53
54     // Warning! the help text must be the last variable to be deleted,
55     // because VarText destructor references it (FIXME: find a cleaner way?)
56     delete m_pHelpText;
57 }
58
59
60 VarManager *VarManager::instance( intf_thread_t *pIntf )
61 {
62     if( ! pIntf->p_sys->p_varManager )
63     {
64         VarManager *pVarManager;
65         pVarManager = new VarManager( pIntf );
66         if( pVarManager )
67         {
68             pIntf->p_sys->p_varManager = pVarManager;
69         }
70     }
71     return pIntf->p_sys->p_varManager;
72 }
73
74
75 void VarManager::destroy( intf_thread_t *pIntf )
76 {
77     if( pIntf->p_sys->p_varManager )
78     {
79         delete pIntf->p_sys->p_varManager;
80         pIntf->p_sys->p_varManager = NULL;
81     }
82 }
83
84
85 void VarManager::registerVar( const VariablePtr &rcVar, const string &rName )
86 {
87     m_varMap[rName] = rcVar;
88     m_varList.push_front( rName );
89
90     m_anonVarList.push_back( rcVar );
91 }
92
93
94 void VarManager::registerVar( const VariablePtr &rcVar )
95 {
96     m_anonVarList.push_back( rcVar );
97 }
98
99
100 Variable *VarManager::getVar( const string &rName )
101 {
102     if( m_varMap.find( rName ) != m_varMap.end() )
103     {
104         return m_varMap[rName].get();
105     }
106     else
107     {
108         return NULL;
109     }
110 }
111
112
113 Variable *VarManager::getVar( const string &rName, const string &rType )
114 {
115     if( m_varMap.find( rName ) != m_varMap.end() )
116     {
117         Variable *pVar = m_varMap[rName].get();
118         // Check the variable type
119         if( pVar->getType() != rType )
120         {
121             msg_Warn( getIntf(), "variable %s has incorrect type (%s instead"
122                       " of (%s)", rName.c_str(), pVar->getType().c_str(),
123                       rType.c_str() );
124             return NULL;
125         }
126         else
127         {
128             return pVar;
129         }
130     }
131     else
132     {
133         return NULL;
134     }
135 }
136
137
138 void VarManager::registerConst( const string &rName, const string &rValue)
139 {
140     m_constMap[rName] = rValue;
141 }
142
143
144 string VarManager::getConst( const string &rName )
145 {
146     return m_constMap[rName];
147 }
148