svcore
1.9
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2006 Chris Cannam. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #include "UnitDatabase.h" 00017 00018 UnitDatabase 00019 UnitDatabase::m_instance; 00020 00021 UnitDatabase * 00022 UnitDatabase::getInstance() 00023 { 00024 return &m_instance; 00025 } 00026 00027 UnitDatabase::UnitDatabase() : 00028 m_nextId(0) 00029 { 00030 } 00031 00032 QStringList 00033 UnitDatabase::getKnownUnits() const 00034 { 00035 QStringList list; 00036 for (UnitMap::const_iterator i = m_units.begin(); i != m_units.end(); ++i) { 00037 list.push_back(i->first); 00038 } 00039 return list; 00040 } 00041 00042 void 00043 UnitDatabase::registerUnit(QString unit) 00044 { 00045 if (m_units.find(unit) == m_units.end()) { 00046 m_units[unit] = m_nextId++; 00047 emit unitDatabaseChanged(); 00048 } 00049 } 00050 00051 int 00052 UnitDatabase::getUnitId(QString unit, bool registerNew) 00053 { 00054 if (m_units.find(unit) == m_units.end()) { 00055 if (registerNew) registerUnit(unit); 00056 else return -1; 00057 } 00058 return m_units[unit]; 00059 } 00060 00061 QString 00062 UnitDatabase::getUnitById(int id) 00063 { 00064 for (UnitMap::const_iterator i = m_units.begin(); i != m_units.end(); ++i) { 00065 if (i->second == id) return i->first; 00066 } 00067 return ""; 00068 } 00069