Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+217
@@ -0,0 +1,217 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "symbol_table.h"
|
||||
#include "symbol_reader.h"
|
||||
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QDirIterator>
|
||||
#include <QtCore/QFile>
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
namespace SymbologyXML
|
||||
{
|
||||
|
||||
|
||||
SymbolTable::SymbolTable(const char *loggerName)
|
||||
: logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger(loggerName))
|
||||
{
|
||||
DEBUG_LOG(logger) << LOGFUNCTION ;
|
||||
DEBUG_LOG(logger) << "END " << LOGFUNCTION ;
|
||||
} // SymbolTable::SymbolTable()
|
||||
|
||||
|
||||
SymbolTable::~SymbolTable()
|
||||
{
|
||||
DEBUG_LOG(logger) << LOGFUNCTION ;
|
||||
clear();
|
||||
DEBUG_LOG(logger) << "END " << LOGFUNCTION ;
|
||||
} // SymbolTable::SymbolTable()
|
||||
|
||||
bool SymbolTable::loadSymbolFromFile(const QString &filename, bool replace)
|
||||
{
|
||||
QFile file(filename);
|
||||
|
||||
SymbolReader sr;
|
||||
Symbol* s = new Symbol();
|
||||
if ( !sr.read(&file, *s) ) {
|
||||
ERROR_LOG(logger) << LOGFUNCTION << ": Failed to read xml-symbol '"
|
||||
<< filename << "'" ;
|
||||
return false;
|
||||
}
|
||||
DEBUG_LOG(logger) << LOGFUNCTION
|
||||
<< ": id '" << s->id() << "'"
|
||||
<< " '0x" << std::hex << s->id() << "'"
|
||||
<< " cP="<< s->getPrimitives().count()
|
||||
<< " file '" << filename << "'";
|
||||
if (replace)
|
||||
m_map.insert(s->id(), s);
|
||||
else
|
||||
m_map.insertMulti(s->id(), s);
|
||||
|
||||
return true;
|
||||
} // bool SymbolTable::loadSymbolFromFile(const QString &filename, bool replace)
|
||||
|
||||
|
||||
bool SymbolTable::setDirectory(const QString &directory, const QStringList &nameFilters) {
|
||||
DEBUG_LOG(logger) << LOGFUNCTION
|
||||
<< " dir='" << directory << "'";
|
||||
|
||||
if (directory.isEmpty())
|
||||
return true;
|
||||
|
||||
QDir dir(directory);
|
||||
bool result = dir.exists();
|
||||
if ( !result ) {
|
||||
ERROR_LOG(logger) << LOGFUNCTION << ": Failed to read dir '"
|
||||
<< dir.absolutePath().toLatin1().data() << "'"
|
||||
;
|
||||
} else {
|
||||
clear(); // alte Caches aufräumen
|
||||
m_directory = directory + QLatin1Char('/');
|
||||
if ( nameFilters.isEmpty() ) {
|
||||
// No filters, assume that all files should be read
|
||||
QDirIterator dirIt(directory, QDir::Files|QDir::Readable|QDir::NoDotAndDotDot);
|
||||
while(dirIt.hasNext()) {
|
||||
bool bRet = loadSymbolFromFile(dirIt.next());
|
||||
if( !bRet ) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
QDirIterator dirIt(directory, nameFilters, QDir::Files|QDir::Readable|QDir::NoDotAndDotDot);
|
||||
while(dirIt.hasNext()) {
|
||||
bool bRet = loadSymbolFromFile(dirIt.next());
|
||||
if( !bRet ) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DEBUG_LOG(logger) << "END " << LOGFUNCTION
|
||||
<< " dir='" << directory << "'"
|
||||
<< " count=" << this->size();
|
||||
return result;
|
||||
} // bool SymbolTable::setDirectory(const QString &directory, const QStringList & nameFilters = QStringList())
|
||||
|
||||
bool SymbolTable::updateSymbol(int id, bool replace) {
|
||||
DEBUG_LOG(logger) << LOGFUNCTION ;
|
||||
|
||||
bool bRet = false;
|
||||
// Der Dateiname muss "symbol_%04d.xml" sein!
|
||||
QString filename(QString::asprintf("symbol_%04d.xml", id));
|
||||
bRet = loadSymbolFromFile( m_directory + filename, replace);
|
||||
|
||||
DEBUG_LOG(logger) << "END " << LOGFUNCTION ;
|
||||
return bRet;
|
||||
} // bool SymbolTable::updateSymbol(int id, bool replace)
|
||||
|
||||
|
||||
Symbol* SymbolTable::value(const int key, Symbol *defaultValue) const
|
||||
{
|
||||
DEBUG_LOG(logger) << LOGFUNCTION ;
|
||||
|
||||
const QList<Symbol*> &allValues = m_map.values(key);
|
||||
for (Symbol *symbol : allValues)
|
||||
{
|
||||
if (!symbol)
|
||||
continue;
|
||||
bool match = symbol->getAffil() == SymbolTypes::AFFIL_UNDEFINED;
|
||||
match &= symbol->getDimen() == SymbolTypes::DIMEN_UNDEFINED;
|
||||
match &= symbol->transformed() == false;
|
||||
if (match)
|
||||
{
|
||||
DEBUG_LOG(logger) << "END " << LOGFUNCTION ;
|
||||
return symbol;
|
||||
}
|
||||
}
|
||||
DEBUG_LOG(logger) << "END " << LOGFUNCTION ;
|
||||
return m_map.value(key, defaultValue);
|
||||
} // Symbol SymbolTable::value(const int &key, const Symbol *defaultValue) const
|
||||
|
||||
|
||||
QList<Symbol*> SymbolTable::values(int key) const
|
||||
{
|
||||
return m_map.values(key);
|
||||
} // QList<Symbol*> values(int key) const
|
||||
|
||||
|
||||
|
||||
Symbol* SymbolTable::operator[](const int &key)
|
||||
{
|
||||
DEBUG_LOG(logger) << LOGFUNCTION ;
|
||||
|
||||
const QList<Symbol*> &allValues = m_map.values(key);
|
||||
for (Symbol *symbol : allValues)
|
||||
{
|
||||
if (!symbol)
|
||||
continue;
|
||||
bool match = symbol->getAffil() == SymbolTypes::AFFIL_UNDEFINED;
|
||||
match &= symbol->getDimen() == SymbolTypes::DIMEN_UNDEFINED;
|
||||
match &= symbol->transformed() == false;
|
||||
if (match)
|
||||
{
|
||||
DEBUG_LOG(logger) << "END " << LOGFUNCTION ;
|
||||
return symbol;
|
||||
}
|
||||
}
|
||||
DEBUG_LOG(logger) << "END " << LOGFUNCTION ;
|
||||
return m_map[key];
|
||||
} // Symbol* SymbolTable::operator[](const int &key)
|
||||
|
||||
|
||||
const Symbol* SymbolTable::operator[](const int &key) const
|
||||
{
|
||||
DEBUG_LOG(logger) << LOGFUNCTION ;
|
||||
|
||||
const QList<Symbol*> &allValues = m_map.values(key);
|
||||
for (const Symbol *symbol : allValues)
|
||||
{
|
||||
if (!symbol)
|
||||
continue;
|
||||
bool match = symbol->getAffil() == SymbolTypes::AFFIL_UNDEFINED;
|
||||
match &= symbol->getDimen() == SymbolTypes::DIMEN_UNDEFINED;
|
||||
match &= symbol->transformed() == false;
|
||||
if (match)
|
||||
{
|
||||
DEBUG_LOG(logger) << "END " << LOGFUNCTION ;
|
||||
return symbol;
|
||||
}
|
||||
}
|
||||
DEBUG_LOG(logger) << "END " << LOGFUNCTION ;
|
||||
return m_map[key];
|
||||
} // const Symbol* SymbolTable::operator[](const int &key) const
|
||||
|
||||
|
||||
void SymbolTable::rotateAllSymbolPrimitives()
|
||||
{
|
||||
DEBUG_LOG(logger) << LOGFUNCTION
|
||||
<< " m_map.count = " <<m_map.count();
|
||||
|
||||
for (Symbol *s : qAsConst(m_map))
|
||||
s->rotatePrimitives();
|
||||
DEBUG_LOG(logger) << "END " << LOGFUNCTION ;
|
||||
} // void SymbolTable::rotateAllSymbolPrimitives()
|
||||
|
||||
|
||||
bool SymbolTable::contains(int key) const
|
||||
{
|
||||
return m_map.contains(key);
|
||||
} // void SymbolTable::contains(int key)
|
||||
|
||||
int SymbolTable::size() const
|
||||
{
|
||||
return m_map.size();
|
||||
} // void SymbolTable::size()
|
||||
|
||||
void SymbolTable::clear()
|
||||
{
|
||||
qDeleteAll(m_map);
|
||||
m_map.clear();
|
||||
} // void SymbolTable::clear()
|
||||
|
||||
} // namespace SymbologyXML
|
||||
Reference in new issue
Block a user