File indexing completed on 2024-05-12 04:38:43

0001 /*
0002     SPDX-FileCopyrightText: 2012 Olivier de Gaalon <olivier.jg@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-only
0005 */
0006 
0007 #include "delayedoutput.h"
0008 
0009 #include <QDebug>
0010 #include <QStack>
0011 
0012 namespace KDevelop {
0013 using DepthedOutput = QPair<QString, int>;
0014 
0015 class DelayedOutputPrivate
0016 {
0017 public:
0018     void flushOutput()
0019     {
0020         while (!output.isEmpty()) {
0021             DepthedOutput curOutput = output.pop();
0022             qDebug().nospace() <<
0023                 qPrintable(QString(curOutput.second - 1, QLatin1Char(' '))) << curOutput.first.toUtf8().data();
0024         }
0025     }
0026     QStack<DepthedOutput> output;
0027     int delayDepth;
0028 };
0029 DelayedOutput::Delay::Delay(DelayedOutput* output)
0030 {
0031     m_output = output;
0032     ++m_output->d_func()->delayDepth;
0033 }
0034 DelayedOutput::Delay::~Delay()
0035 {
0036     --m_output->d_func()->delayDepth;
0037     if (!m_output->d_func()->delayDepth)
0038         m_output->d_func()->flushOutput();
0039 }
0040 
0041 DelayedOutput::DelayedOutput()
0042     : d_ptr(new DelayedOutputPrivate())
0043 {
0044 }
0045 DelayedOutput::~DelayedOutput()
0046 {
0047 }
0048 DelayedOutput& DelayedOutput::self()
0049 {
0050     static DelayedOutput _inst;
0051     return _inst;
0052 }
0053 void DelayedOutput::push(const QString& output)
0054 {
0055     Q_D(DelayedOutput);
0056 
0057     d->output.push(DepthedOutput(output, d->delayDepth));
0058 }
0059 }