]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/var_manager.cpp
Uniformize source files encoding
[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     delete m_pTooltipText;
52
53     // Warning! the help text must be the last variable to be deleted,
54     // because VarText destructor references it (FIXME: find a cleaner way?)
55     delete m_pHelpText;
56 }
57
58
59 VarManager *VarManager::instance( intf_thread_t *pIntf )
60 {
61     if( ! pIntf->p_sys->p_varManager )
62     {
63         VarManager *pVarManager;
64         pVarManager = new VarManager( pIntf );
65         if( pVarManager )
66         {
67             pIntf->p_sys->p_varManager = pVarManager;
68         }
69     }
70     return pIntf->p_sys->p_varManager;
71 }
72
73
74 void VarManager::destroy( intf_thread_t *pIntf )
75 {
76     if( pIntf->p_sys->p_varManager )
77     {
78         delete pIntf->p_sys->p_varManager;
79         pIntf->p_sys->p_varManager = NULL;
80     }
81 }
82
83
84 void VarManager::registerVar( const VariablePtr &rcVar, const string &rName )
85 {
86     m_varMap[rName] = rcVar;
87     m_varList.push_front( rName );
88 }
89
90
91 void VarManager::registerVar( const VariablePtr &rcVar )
92 {
93     m_anonVarList.push_back( rcVar );
94 }
95
96
97 Variable *VarManager::getVar( const string &rName )
98 {
99     if( m_varMap.find( rName ) != m_varMap.end() )
100     {
101         return m_varMap[rName].get();
102     }
103     else
104     {
105         return NULL;
106     }
107 }
108
109
110 Variable *VarManager::getVar( const string &rName, const string &rType )
111 {
112     if( m_varMap.find( rName ) != m_varMap.end() )
113     {
114         Variable *pVar = m_varMap[rName].get();
115         // Check the variable type
116         if( pVar->getType() != rType )
117         {
118             msg_Warn( getIntf(), "Variable %s has incorrect type (%s instead"
119                       " of (%s)", rName.c_str(), pVar->getType().c_str(),
120                       rType.c_str() );
121             return NULL;
122         }
123         else
124         {
125             return pVar;
126         }
127     }
128     else
129     {
130         return NULL;
131     }
132 }
133