File indexing completed on 2024-04-21 05:41:37
0001 /* 0002 This file is part of KCachegrind. 0003 0004 SPDX-FileCopyrightText: 2002-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de> 0005 0006 SPDX-License-Identifier: GPL-2.0-only 0007 */ 0008 0009 /* 0010 * Base class for loaders of profiling data. 0011 */ 0012 0013 #include "loader.h" 0014 0015 #include "logger.h" 0016 0017 /// Loader 0018 0019 QList<Loader*> Loader::_loaderList; 0020 0021 Loader::Loader(const QString& name, const QString& desc) 0022 { 0023 _name = name; 0024 _description = desc; 0025 0026 _logger = nullptr; 0027 } 0028 0029 Loader::~Loader() 0030 {} 0031 0032 bool Loader::canLoad(QIODevice*) 0033 { 0034 return false; 0035 } 0036 0037 int Loader::load(TraceData*, QIODevice*, const QString&) 0038 { 0039 return 0; 0040 } 0041 0042 Loader* Loader::matchingLoader(QIODevice* file) 0043 { 0044 foreach (Loader* l, _loaderList) 0045 if (l->canLoad(file)) 0046 return l; 0047 0048 return nullptr; 0049 } 0050 0051 Loader* Loader::loader(const QString& name) 0052 { 0053 foreach (Loader* l, _loaderList) 0054 if (l->name() == name) 0055 return l; 0056 0057 return nullptr; 0058 } 0059 0060 // factories of available loaders 0061 Loader* createCachegrindLoader(); 0062 0063 void Loader::initLoaders() 0064 { 0065 _loaderList.append(createCachegrindLoader()); 0066 //_loaderList.append(GProfLoader::createLoader()); 0067 } 0068 0069 void Loader::deleteLoaders() 0070 { 0071 while (!_loaderList.isEmpty()) 0072 delete _loaderList.takeFirst(); 0073 } 0074 0075 // notifications 0076 0077 void Loader::setLogger(Logger* l) 0078 { 0079 _logger = l; 0080 } 0081 0082 void Loader::loadStart(const QString& filename) 0083 { 0084 if (_logger) 0085 _logger->loadStart(filename); 0086 } 0087 0088 void Loader::loadProgress(int progress) 0089 { 0090 if (_logger) 0091 _logger->loadProgress(progress); 0092 } 0093 0094 void Loader::loadError(int line, const QString& msg) 0095 { 0096 if (_logger) 0097 _logger->loadError(line, msg); 0098 } 0099 0100 void Loader::loadWarning(int line, const QString& msg) 0101 { 0102 if (_logger) 0103 _logger->loadWarning(line, msg); 0104 } 0105 0106 void Loader::loadFinished(const QString& msg) 0107 { 0108 if (_logger) 0109 _logger->loadFinished(msg); 0110 } 0111