diff options
author | Robert Jonsson <spamatica@gmail.com> | 2010-10-13 19:34:22 +0000 |
---|---|---|
committer | Robert Jonsson <spamatica@gmail.com> | 2010-10-13 19:34:22 +0000 |
commit | 8a2c2824a59d7644e13bc52c9a0ecbd641f21f95 (patch) | |
tree | 064ad3f2bf8daab0ad27b128abd86a9bbdb1e496 /muse2/muse/stringparam.cpp | |
parent | a27706d9629e8b592cca4659f865b70adef24e6d (diff) |
new branch muse2, first checkin
Diffstat (limited to 'muse2/muse/stringparam.cpp')
-rw-r--r-- | muse2/muse/stringparam.cpp | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/muse2/muse/stringparam.cpp b/muse2/muse/stringparam.cpp new file mode 100644 index 00000000..b3b5104e --- /dev/null +++ b/muse2/muse/stringparam.cpp @@ -0,0 +1,113 @@ +//============================================================================= +// MusE +// Linux Music Editor +// $Id: stringparam.cpp,v 1.0.0.0 2010/04/24 01:01:01 terminator356 Exp $ +// +// Copyright (C) 1999-2010 by Werner Schweer and others +// String parameter module added by Tim. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= + +#include <qstring.h> +#include "stringparam.h" +#include "xml.h" + +//--------------------------------------------------------- +// findKey +//--------------------------------------------------------- + +iStringParamMap StringParamMap::findKey(const char* key) +{ + iStringParamMap icm = find(std::string(key)); + return icm; +} + +//--------------------------------------------------------- +// set +//--------------------------------------------------------- + +void StringParamMap::set(const char* key, const char* value) +{ + iStringParamMap icm = find(std::string(key)); + if(icm == end()) + insert(std::pair<std::string, std::string>(key, value)); + else + icm->second = std::string(value); +} + +//--------------------------------------------------------- +// remove +//--------------------------------------------------------- + +void StringParamMap::remove(const char* key) +{ + erase(std::string(key)); +} + +//--------------------------------------------------------- +// read +//--------------------------------------------------------- + +void StringParamMap::read(Xml& xml, const QString& name) +{ + QString n; + QString value; + + for (;;) + { + Xml::Token token = xml.parse(); + const QString tag = xml.s1(); + switch (token) + { + case Xml::Error: + case Xml::End: + return; + case Xml::TagStart: + xml.unknown(name); + break; + case Xml::Attribut: + if(tag == "name") + n = xml.s2(); + else + if(tag == "val") + value = xml.s2(); + else + xml.unknown(name); + break; + case Xml::TagEnd: + if(tag == name) + { + // Add or modify the item. + set(n.latin1(), value.latin1()); + return; + } + default: + break; + } + } +} + +//--------------------------------------------------------- +// write +//--------------------------------------------------------- + +void StringParamMap::write(int level, Xml& xml, const char* name) const +{ + if(empty()) + return; + + for(ciStringParamMap r = begin(); r != end(); ++r) + xml.tag(level, "%s name=\"%s\" val=\"%s\"/", name, r->first.c_str(), r->second.c_str()); +} + |