Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ctapmex committed Jan 1, 2025
1 parent 05efa4f commit 2f2a048
Show file tree
Hide file tree
Showing 23 changed files with 72 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/colorer/Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Exception : public std::exception
[[nodiscard]]
const char* what() const noexcept override;

protected:
private:
std::string what_str;
};

Expand Down
19 changes: 10 additions & 9 deletions src/colorer/editor/BaseEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ FileType* BaseEditor::chooseFileTypeCh(const UnicodeString* fileName, int choose
UnicodeString textStart;
int totalLength = 0;
for (int i = 0; i < chooseStr; i++) {
UnicodeString* iLine = lineSource->getLine(i);
const UnicodeString* iLine = lineSource->getLine(i);
if (iLine == nullptr) {
break;
}
Expand Down Expand Up @@ -164,10 +164,11 @@ FileType* BaseEditor::chooseFileType(const UnicodeString* fileName)
currentFileType = parserFactory->getHrcLibrary().chooseFileType(fileName, nullptr);
}
else {
int chooseStr = CHOOSE_STR, chooseLen = CHOOSE_LEN;
int chooseStr = CHOOSE_STR;
int chooseLen = CHOOSE_LEN;

UnicodeString ds_def = UnicodeString("default");
FileType* def = parserFactory->getHrcLibrary().getFileType(&ds_def);
const FileType* def = parserFactory->getHrcLibrary().getFileType(&ds_def);
if (def) {
chooseStr = def->getParamValueInt("firstlines", chooseStr);
chooseLen = def->getParamValueInt("firstlinebytes", chooseLen);
Expand Down Expand Up @@ -360,7 +361,7 @@ void BaseEditor::lineCountEvent(int newLineCount)
lineCount = newLineCount;
}

inline int BaseEditor::getLastVisibleLine()
inline int BaseEditor::getLastVisibleLine() const
{
int r1 = (wStart + wSize);
int r2 = lineCount;
Expand All @@ -369,7 +370,8 @@ inline int BaseEditor::getLastVisibleLine()

void BaseEditor::validate(int lno, bool rebuildRegions)
{
int parseFrom, parseTo;
int parseFrom;
int parseTo;
bool layoutChanged = false;
TextParser::TextParseMode tpmode = TextParser::TextParseMode::TPM_CACHE_READ;

Expand Down Expand Up @@ -420,8 +422,7 @@ void BaseEditor::validate(int lno, bool rebuildRegions)
}
firstLine = newFirstLine;
layoutChanged = true;
COLORER_LOG_DEBUG("[BaseEditor] newFirstLine=%, parseFrom=%, parseTo=%", firstLine, parseFrom,
parseTo);
COLORER_LOG_DEBUG("[BaseEditor] newFirstLine=%, parseFrom=%, parseTo=%", firstLine, parseFrom, parseTo);
}

if (!layoutChanged) {
Expand All @@ -445,7 +446,7 @@ void BaseEditor::validate(int lno, bool rebuildRegions)
/* Runs parser */
if (parseTo - parseFrom > 0) {
COLORER_LOG_DEBUG("[BaseEditor] validate:parse:%-%, %", parseFrom, parseTo,
tpmode == TextParser::TextParseMode::TPM_CACHE_READ ? "READ" : "UPDATE");
tpmode == TextParser::TextParseMode::TPM_CACHE_READ ? "READ" : "UPDATE");
int stopLine = textParser->parse(parseFrom, parseTo - parseFrom, tpmode);

if (tpmode == TextParser::TextParseMode::TPM_CACHE_UPDATE) {
Expand Down Expand Up @@ -518,7 +519,7 @@ void BaseEditor::leaveScheme(size_t lno, UnicodeString* line, int sx, int ex, co
}
}

bool BaseEditor::haveInvalidLine()
bool BaseEditor::haveInvalidLine() const
{
return invalidLine < lineCount;
}
Expand Down
4 changes: 2 additions & 2 deletions src/colorer/editor/BaseEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class BaseEditor : public RegionHandler
void leaveScheme(size_t lno, UnicodeString* line, int sx, int ex, const Region* region,
const Scheme* scheme) override;

bool haveInvalidLine();
bool haveInvalidLine() const;
void setMaxBlockSize(int max_block_size);

private:
Expand Down Expand Up @@ -276,7 +276,7 @@ class BaseEditor : public RegionHandler
bool internalRM;
bool regionCompact;

inline int getLastVisibleLine();
inline int getLastVisibleLine() const;
void remapLRS(bool recreate);
/**
* Searches for the paired token and creates PairMatch
Expand Down
17 changes: 10 additions & 7 deletions src/colorer/editor/Outliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ OutlineItem* Outliner::getItem(size_t idx)
return outline.at(idx);
}

size_t Outliner::itemCount()
size_t Outliner::itemCount() const
{
return outline.size();
}

size_t Outliner::manageTree(std::vector<int>& treeStack, int newLevel)
{
while (treeStack.size() > 0 && newLevel < treeStack.back()) {
while (!treeStack.empty() && newLevel < treeStack.back()) {
treeStack.pop_back();
}
if (treeStack.size() == 0 || newLevel > treeStack.back()) {
if (treeStack.empty() || newLevel > treeStack.back()) {
treeStack.push_back(newLevel);
return treeStack.size() - 1;
}
Expand All @@ -44,7 +44,7 @@ size_t Outliner::manageTree(std::vector<int>& treeStack, int newLevel)
return 0;
}

bool Outliner::isOutlined(const Region* region)
bool Outliner::isOutlined(const Region* region) const
{
return region->hasParent(searchRegion);
}
Expand Down Expand Up @@ -92,7 +92,8 @@ void Outliner::addRegion(size_t lno, UnicodeString* line, int sx, int ex, const

if (lineIsEmpty) {
outline.push_back(new OutlineItem(lno, sx, curLevel, &itemLabel, region));
} else {
}
else {
OutlineItem* thisItem = outline.back();
if (thisItem->token != nullptr && thisItem->lno == lno) {
thisItem->token->append(itemLabel);
Expand All @@ -101,12 +102,14 @@ void Outliner::addRegion(size_t lno, UnicodeString* line, int sx, int ex, const
lineIsEmpty = false;
}

void Outliner::enterScheme(size_t /*lno*/, UnicodeString* /*line*/, int /*sx*/, int /*ex*/, const Region* /*region*/, const Scheme* /*scheme*/)
void Outliner::enterScheme(size_t /*lno*/, UnicodeString* /*line*/, int /*sx*/, int /*ex*/, const Region* /*region*/,
const Scheme* /*scheme*/)
{
curLevel++;
}

void Outliner::leaveScheme(size_t /*lno*/, UnicodeString* /*line*/, int /*sx*/, int /*ex*/, const Region* /*region*/, const Scheme* /*scheme*/)
void Outliner::leaveScheme(size_t /*lno*/, UnicodeString* /*line*/, int /*sx*/, int /*ex*/, const Region* /*region*/,
const Scheme* /*scheme*/)
{
curLevel--;
}
4 changes: 2 additions & 2 deletions src/colorer/editor/Outliner.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Outliner : public RegionHandler, public EditorListener
/**
* Total number of currently available outline items
*/
size_t itemCount();
size_t itemCount() const;

void startParsing(size_t lno) override;
void endParsing(size_t lno) override;
Expand All @@ -64,7 +64,7 @@ class Outliner : public RegionHandler, public EditorListener
void modifyEvent(size_t topLine) override;

protected:
bool isOutlined(const Region* region);
bool isOutlined(const Region* region) const;

BaseEditor* baseEditor;
const Region* searchRegion;
Expand Down
4 changes: 2 additions & 2 deletions src/colorer/handlers/LineRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ LineRegion::LineRegion()
special = false;
}

const StyledRegion* LineRegion::styled()
const StyledRegion* LineRegion::styled() const
{
return StyledRegion::cast(rdef);
}

const TextRegion* LineRegion::texted()
const TextRegion* LineRegion::texted() const
{
return TextRegion::cast(rdef);
}
4 changes: 2 additions & 2 deletions src/colorer/handlers/LineRegion.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ class LineRegion
/** Transforms this region's reference into styled region define
and returns new pointer.
*/
const StyledRegion* styled();
const StyledRegion* styled() const;

/** Transforms this region's reference into text region define
and returns new pointer.
*/
const TextRegion* texted();
const TextRegion* texted() const;

/** Copy operator */
LineRegion& operator=(const LineRegion& lr);
Expand Down
4 changes: 2 additions & 2 deletions src/colorer/handlers/LineRegionsSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void LineRegionsSupport::resize(size_t lineCount_)
this->lineCount = lineCount_;
}

size_t LineRegionsSupport::size()
size_t LineRegionsSupport::size() const
{
return lineCount;
}
Expand Down Expand Up @@ -60,7 +60,7 @@ void LineRegionsSupport::setFirstLine(size_t first)
firstLineNo = first;
}

size_t LineRegionsSupport::getFirstLine()
size_t LineRegionsSupport::getFirstLine() const
{
return firstLineNo;
}
Expand Down
4 changes: 2 additions & 2 deletions src/colorer/handlers/LineRegionsSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class LineRegionsSupport : public RegionHandler
/**
* Return current size of this line regions structure
*/
size_t size();
size_t size() const;

/**
* Drops all internal structures
Expand All @@ -41,7 +41,7 @@ class LineRegionsSupport : public RegionHandler
/**
* Returns first line position, installed in this line structures.
*/
size_t getFirstLine();
size_t getFirstLine() const;

/**
* Background region define, which is used to
Expand Down
4 changes: 2 additions & 2 deletions src/colorer/handlers/RegionMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
std::vector<const RegionDefine*> RegionMapper::enumerateRegionDefines() const
{
std::vector<const RegionDefine*> result(regionDefines.size());
for (const auto& regionDefine : regionDefines) {
result.push_back(regionDefine.second.get());
for (const auto& [key, value] : regionDefines) {
result.push_back(value.get());
}
return result;
}
Expand Down
6 changes: 3 additions & 3 deletions src/colorer/handlers/StyledHRDMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ void StyledHRDMapper::saveRegionMappings(Writer* writer) const
{
writer->write(u"<?xml version=\"1.0\"?>\n");

for (const auto& regionDefine : regionDefines) {
const StyledRegion* rdef = StyledRegion::cast(regionDefine.second.get());
for (const auto& [key, value] : regionDefines) {
const StyledRegion* rdef = StyledRegion::cast(value.get());
constexpr auto size_temporary = 256;
char temporary[size_temporary];
writer->write(u"\t<define name='" + regionDefine.first + u"'");
writer->write(u"\t<define name='" + key + u"'");
if (rdef->isForeSet) {
snprintf(temporary, size_temporary, " fore=\"#%06x\"", rdef->fore);
writer->write(temporary);
Expand Down
6 changes: 3 additions & 3 deletions src/colorer/handlers/TextHRDMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ void TextHRDMapper::saveRegionMappings(Writer* writer) const
{
writer->write(u"<?xml version=\"1.0\"?>\n");

for (const auto& regionDefine : regionDefines) {
const TextRegion* rdef = TextRegion::cast(regionDefine.second.get());
writer->write(u"\t<define name='" + regionDefine.first + u"'");
for (const auto& [key, value] : regionDefines) {
const TextRegion* rdef = TextRegion::cast(value.get());
writer->write(u"\t<define name='" + key + u"'");
if (rdef->start_text != nullptr) {
writer->write(u" start_text='" + *rdef->start_text + u"'");
}
Expand Down
1 change: 0 additions & 1 deletion src/colorer/io/FileWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class FileWriter : public StreamWriter{
*/
FileWriter(const UnicodeString* fileName, bool useBOM);
~FileWriter() override;
protected:
};

#endif
Expand Down
8 changes: 4 additions & 4 deletions src/colorer/parsers/FileTypeImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ std::vector<UnicodeString> FileType::Impl::enumParams() const
{
std::vector<UnicodeString> r;
r.reserve(paramsHash.size());
for (const auto& p : paramsHash) {
r.push_back(p.first);
for (const auto& [key, value] : paramsHash) {
r.push_back(key);
}
return r;
}
Expand Down Expand Up @@ -113,8 +113,8 @@ const UnicodeString* FileType::Impl::getParamUserValue(const UnicodeString& para

TypeParameter& FileType::Impl::addParam(const UnicodeString& param_name, const UnicodeString& value)
{
auto it = paramsHash.try_emplace(param_name, TypeParameter(param_name, value));
return it.first->second;
auto [fst, snd] = paramsHash.try_emplace(param_name, param_name, value);
return fst->second;
}

void FileType::Impl::setParamValue(const UnicodeString& param_name, const UnicodeString* value)
Expand Down
5 changes: 2 additions & 3 deletions src/colorer/parsers/HrcLibraryImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,7 @@ void HrcLibrary::Impl::updateLinks()
{
while (structureChanged) {
structureChanged = false;
for (auto& scheme_it : schemeHash) {
const SchemeImpl* scheme = scheme_it.second;
for (auto const& [key, scheme] : schemeHash) {
if (!scheme->fileType->pimpl->loadDone) {
continue;
}
Expand Down Expand Up @@ -1061,7 +1060,7 @@ const Region* HrcLibrary::Impl::getNCRegion(const UnicodeString* name, const boo
Regions with this name are always transparent
*/
if (reg != nullptr) {
const auto s_name = reg->getName();
const auto& s_name = reg->getName();
const auto idx = s_name.indexOf(":default");
if (idx != -1 && idx + 8 == s_name.length()) {
return nullptr;
Expand Down
8 changes: 4 additions & 4 deletions src/colorer/parsers/ParserFactoryImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void ParserFactory::Impl::loadHrcPath(const UnicodeString& location)
COLORER_LOG_DEBUG("try load '%'", location);
if (XmlInputSource::isFsURI(*base_catalog_path, &location)) {
auto files = colorer::Environment::getFilesFromPath(base_catalog_path.get(), &location, ".hrc");
for (auto& file : files) {
for (const auto& file : files) {
loadHrc(file, nullptr);
}
}
Expand Down Expand Up @@ -89,7 +89,7 @@ std::vector<UnicodeString> ParserFactory::Impl::enumHrdClasses()
{
std::vector<UnicodeString> result;
result.reserve(hrd_nodes.size());
for (auto& hrd_node : hrd_nodes) {
for (const auto& hrd_node : hrd_nodes) {
result.push_back(hrd_node.first);
}
return result;
Expand All @@ -100,7 +100,7 @@ std::vector<const HrdNode*> ParserFactory::Impl::enumHrdInstances(const UnicodeS
auto hash = hrd_nodes.find(classID);
std::vector<const HrdNode*> result;
result.reserve(hash->second->size());
for (auto& p : *hash->second) {
for (const auto& p : *hash->second) {
result.push_back(p.get());
}
return result;
Expand All @@ -112,7 +112,7 @@ const HrdNode& ParserFactory::Impl::getHrdNode(const UnicodeString& classID, con
if (hash == hrd_nodes.end()) {
throw ParserFactoryException("can't find HRDClass '" + classID + "'");
}
for (auto& p : *hash->second) {
for (const auto& p : *hash->second) {
if (nameID.compare(p->hrd_name) == 0) {
return *p;
}
Expand Down
6 changes: 4 additions & 2 deletions src/colorer/parsers/TextParserHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

ParseCache::~ParseCache()
{
//COLORER_LOG_DEEPTRACE("[TPCache] ~ParseCache():%,%-%", *scheme->getName(), sline, eline);
// COLORER_LOG_DEEPTRACE("[TPCache] ~ParseCache():%,%-%", *scheme->getName(), sline, eline);
delete backLine;
delete children;
prev = nullptr;
Expand All @@ -29,7 +29,9 @@ ParseCache::~ParseCache()

ParseCache* ParseCache::searchLine(int ln, ParseCache** cache)
{
ParseCache *r1 = nullptr, *r2 = nullptr, *tmp = this;
ParseCache* r1 = nullptr;
ParseCache* r2 = nullptr;
ParseCache* tmp = this;
*cache = nullptr;
while (tmp) {
COLORER_LOG_DEEPTRACE("[TPCache] searchLine() tmp:%,%-%", *tmp->scheme->getName(), tmp->sline, tmp->eline);
Expand Down
Loading

0 comments on commit 2f2a048

Please sign in to comment.