Mercurial > hg > easaier-soundaccess
comparison base/UnitDatabase.cpp @ 0:fc9323a41f5a
start base : Sonic Visualiser sv1-1.0rc1
author | lbajardsilogic |
---|---|
date | Fri, 11 May 2007 09:08:14 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:fc9323a41f5a |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2006 Chris Cannam. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #include "UnitDatabase.h" | |
17 | |
18 UnitDatabase | |
19 UnitDatabase::m_instance; | |
20 | |
21 UnitDatabase * | |
22 UnitDatabase::getInstance() | |
23 { | |
24 return &m_instance; | |
25 } | |
26 | |
27 UnitDatabase::UnitDatabase() : | |
28 m_nextId(0) | |
29 { | |
30 } | |
31 | |
32 QStringList | |
33 UnitDatabase::getKnownUnits() const | |
34 { | |
35 QStringList list; | |
36 for (UnitMap::const_iterator i = m_units.begin(); i != m_units.end(); ++i) { | |
37 list.push_back(i->first); | |
38 } | |
39 return list; | |
40 } | |
41 | |
42 void | |
43 UnitDatabase::registerUnit(QString unit) | |
44 { | |
45 if (m_units.find(unit) == m_units.end()) { | |
46 m_units[unit] = m_nextId++; | |
47 } | |
48 emit unitDatabaseChanged(); | |
49 } | |
50 | |
51 int | |
52 UnitDatabase::getUnitId(QString unit, bool registerNew) | |
53 { | |
54 if (m_units.find(unit) == m_units.end()) { | |
55 if (registerNew) registerUnit(unit); | |
56 else return -1; | |
57 } | |
58 return m_units[unit]; | |
59 } | |
60 | |
61 QString | |
62 UnitDatabase::getUnitById(int id) | |
63 { | |
64 for (UnitMap::const_iterator i = m_units.begin(); i != m_units.end(); ++i) { | |
65 if (i->second == id) return i->first; | |
66 } | |
67 return ""; | |
68 } | |
69 |