Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port the project to C++11 - Part 2 #72

Merged
merged 12 commits into from
Sep 26, 2022
14 changes: 0 additions & 14 deletions src/abstract-parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,3 @@ AbstractParserPtr createParser(InStream &input)
// GCC
return make_unique<GccParser>(input);
}

EFileFormat Parser::inputFormat() const
{
if (dynamic_cast<JsonParser *>(parser_.get()))
return FF_JSON;

if (dynamic_cast<CovParser *>(parser_.get()))
return FF_COVERITY;

if (dynamic_cast<GccParser *>(parser_.get()))
return FF_GCC;

return FF_INVALID;
}
8 changes: 7 additions & 1 deletion src/abstract-parser.hh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class AbstractParser {
return emptyProps_;
}

virtual EFileFormat inputFormat() const {
return FF_INVALID;
}

protected:
AbstractParser() = default;

Expand Down Expand Up @@ -91,7 +95,9 @@ class Parser {
return parser_->getScanProps();
}

EFileFormat inputFormat() const;
EFileFormat inputFormat() const {
return parser_->inputFormat();
};

private:
InStream &input_;
Expand Down
6 changes: 3 additions & 3 deletions src/color.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 Red Hat, Inc.
* Copyright (C) 2014-2022 Red Hat, Inc.
*
* This file is part of csdiff.
*
Expand Down Expand Up @@ -39,7 +39,7 @@ ColorWriter::ColorWriter(const std::ostream &str, const EColorMode cm)
}
}

const char* ColorWriter::setColor(const EColor color)
const char* ColorWriter::setColor(const EColor color) const
{
if (!enabled_)
return "";
Expand All @@ -55,7 +55,7 @@ const char* ColorWriter::setColor(const EColor color)
return "";
}

const char* ColorWriter::setColorIf(bool cond, const EColor color)
const char* ColorWriter::setColorIf(bool cond, const EColor color) const
{
return (cond) ? this->setColor(color) : "";
}
6 changes: 3 additions & 3 deletions src/color.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 Red Hat, Inc.
* Copyright (C) 2014-2022 Red Hat, Inc.
*
* This file is part of csdiff.
*
Expand Down Expand Up @@ -39,8 +39,8 @@ enum EColor {
class ColorWriter {
public:
ColorWriter(const std::ostream &str, EColorMode);
const char* setColor(EColor);
const char* setColorIf(bool, EColor);
const char* setColor(EColor) const;
const char* setColorIf(bool, EColor) const;

private:
bool enabled_;
Expand Down
6 changes: 3 additions & 3 deletions src/csdiff.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2011 Red Hat, Inc.
* Copyright (C) 2011-2022 Red Hat, Inc.
*
* This file is part of csdiff.
*
Expand Down Expand Up @@ -37,7 +37,7 @@ int main(int argc, char *argv[])
po::options_description desc(string("Usage: ") + name
+ " [options] old.err new.err, where options are");

typedef std::vector<string> TStringList;
using TStringList = std::vector<string>;
string mode;

try {
Expand Down Expand Up @@ -124,7 +124,7 @@ int main(int argc, char *argv[])
const RE reSubst("([^,]+),(.*)");
for (const string &subst : substList) {
if (!boost::regex_match(subst, sm, reSubst)) {
std::cerr << "bad substutution format: " << subst
std::cerr << "bad substitution format: " << subst
<< std::endl << "use: -s OLD,NEW" << std::endl;
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/csfilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct MsgReplace {
}
};

typedef std::vector<MsgReplace> TMsgReplaceList;
using TMsgReplaceList = std::vector<MsgReplace>;

struct MsgFilter::Private {
bool ignorePath = false;
Expand Down
6 changes: 3 additions & 3 deletions src/csfilter.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2011 Red Hat, Inc.
* Copyright (C) 2011-2022 Red Hat, Inc.
*
* This file is part of csdiff.
*
Expand All @@ -26,8 +26,8 @@
#include <string>
#include <vector>

typedef std::vector<std::string> TStringList;
typedef std::map<std::string, std::string> TSubstMap;
using TStringList = std::vector<std::string>;
using TSubstMap = std::map<std::string, std::string>;

class MsgFilter {
public:
Expand Down
6 changes: 5 additions & 1 deletion src/csparser.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2011-2012 Red Hat, Inc.
* Copyright (C) 2011-2022 Red Hat, Inc.
*
* This file is part of csdiff.
*
Expand Down Expand Up @@ -30,6 +30,10 @@ class CovParser: public AbstractParser {
bool getNext(Defect *) override;
bool hasError() const override;

EFileFormat inputFormat() const override {
return FF_COVERITY;
}

private:
CovParser(const Parser &);
CovParser& operator=(const Parser &);
Expand Down
6 changes: 5 additions & 1 deletion src/gcc-parser.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013 Red Hat, Inc.
* Copyright (C) 2013-2022 Red Hat, Inc.
*
* This file is part of csdiff.
*
Expand Down Expand Up @@ -30,6 +30,10 @@ class GccParser: public AbstractParser {
bool getNext(Defect *) override;
bool hasError() const override;

EFileFormat inputFormat() const override {
return FF_GCC;
}

private:
GccParser(const Parser &);
GccParser& operator=(const Parser &);
Expand Down
20 changes: 6 additions & 14 deletions src/instream.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2011 - 2021 Red Hat, Inc.
* Copyright (C) 2011 - 2022 Red Hat, Inc.
*
* This file is part of csdiff.
*
Expand All @@ -19,35 +19,27 @@

#include "instream.hh"

InStream::InStream(const std::string &fileName, const bool silent):
fileName_(fileName),
InStream::InStream(std::string fileName, const bool silent):
fileName_(std::move(fileName)),
silent_(silent),
anyError_(false),
str_((!fileName_.compare("-"))
str_((fileName_ == "-")
? std::cin
: fileStr_)
{
if (&str_ == &fileStr_)
fileStr_.open(fileName_, std::ios::in);
fileStr_.open(fileName_);

if (!fileStr_)
throw InFileException(fileName_);
}

InStream::InStream(std::istringstream &str, const bool silent):
silent_(silent),
anyError_(false),
str_(str)
{
}

InStream::~InStream()
{
if (&str_ == &fileStr_)
fileStr_.close();
}

void InStream::handleError(const std::string msg, const long line)
void InStream::handleError(const std::string &msg, const unsigned long line)
{
anyError_ = true;
if (silent_ || msg.empty())
Expand Down
14 changes: 7 additions & 7 deletions src/instream.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2011 - 2021 Red Hat, Inc.
* Copyright (C) 2011 - 2022 Red Hat, Inc.
*
* This file is part of csdiff.
*
Expand Down Expand Up @@ -38,29 +38,29 @@ struct InFileException {

class InStream {
public:
InStream(const std::string &fileName, bool silent = false);
InStream(std::string fileName, bool silent = false);
InStream(std::istringstream &str, bool silent = false);
~InStream();
~InStream() = default;

const std::string& fileName() const { return fileName_; }
std::istream& str() const { return str_; }
bool silent() const { return silent_; }
bool anyError() const { return anyError_; }

void handleError(std::string msg = std::string(), long line = 0L);
void handleError(const std::string &msg = "", unsigned long line = 0UL);

private:
const std::string fileName_;
const bool silent_;
bool anyError_;
std::fstream fileStr_;
bool anyError_ = false;
std::ifstream fileStr_;
std::istream &str_;
};

class InStreamLookAhead {
public:
InStreamLookAhead(
InStream &inStr,
InStream &input,
unsigned size,
bool skipWhiteSpaces = false);

Expand Down
6 changes: 5 additions & 1 deletion src/json-parser.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2012 Red Hat, Inc.
* Copyright (C) 2012-2022 Red Hat, Inc.
*
* This file is part of csdiff.
*
Expand Down Expand Up @@ -31,6 +31,10 @@ class JsonParser: public AbstractParser {
bool hasError() const override;
const TScanProps& getScanProps() const override;

EFileFormat inputFormat() const override {
return FF_JSON;
}

private:
JsonParser(const Parser &);
JsonParser& operator=(const Parser &);
Expand Down