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

ROW: clean up in preparation to hide CharRow & AttrRow #8446

Merged
17 commits merged into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/buffer/out/AttrRow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class ATTR_ROW final

ATTR_ROW(const UINT cchRowWidth, const TextAttribute attr);

void Reset(const TextAttribute attr);

TextAttribute GetAttrByColumn(const size_t column) const;
TextAttribute GetAttrByColumn(const size_t column,
size_t* const pApplies) const;
Expand Down Expand Up @@ -63,8 +61,11 @@ class ATTR_ROW final

friend bool operator==(const ATTR_ROW& a, const ATTR_ROW& b) noexcept;
friend class AttrRowIterator;
friend class ROW;

private:
void Reset(const TextAttribute attr);

std::vector<TextAttributeRun> _list;
size_t _cchRowWidth;

Expand Down
58 changes: 0 additions & 58 deletions src/buffer/out/CharRow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,11 @@
// - instantiated object
// Note: will through if unable to allocate char/attribute buffers
CharRow::CharRow(size_t rowWidth, ROW* const pParent) :
_wrapForced{ false },
_doubleBytePadded{ false },
_data(rowWidth, value_type()),
_pParent{ FAIL_FAST_IF_NULL(pParent) }
{
}

// Routine Description:
// - Sets the wrap status for the current row
// Arguments:
// - wrapForced - True if the row ran out of space and we forced to wrap to the next row. False otherwise.
// Return Value:
// - <none>
void CharRow::SetWrapForced(const bool wrapForced) noexcept
{
_wrapForced = wrapForced;
}

// Routine Description:
// - Gets the wrap status for the current row
// Arguments:
// - <none>
// Return Value:
// - True if the row ran out of space and we were forced to wrap to the next row. False otherwise.
bool CharRow::WasWrapForced() const noexcept
{
return _wrapForced;
}

// Routine Description:
// - Sets the double byte padding for the current row
// Arguments:
// - fWrapWasForced - True if the row ran out of space for a double byte character and we padded out the row. False otherwise.
// Return Value:
// - <none>
void CharRow::SetDoubleBytePadded(const bool doubleBytePadded) noexcept
{
_doubleBytePadded = doubleBytePadded;
}

// Routine Description:
// - Gets the double byte padding status for the current row.
// Arguments:
// - <none>
// Return Value:
// - True if the row didn't have space for a double byte character and we were padded out the row. False otherwise.
bool CharRow::WasDoubleBytePadded() const noexcept
{
return _doubleBytePadded;
}

// Routine Description:
// - gets the size of the row, in glyph cells
// Arguments:
Expand All @@ -90,9 +44,6 @@ void CharRow::Reset() noexcept
{
cell.Reset();
}

_wrapForced = false;
_doubleBytePadded = false;
}

// Routine Description:
Expand Down Expand Up @@ -316,12 +267,3 @@ COORD CharRow::GetStorageKey(const size_t column) const noexcept
{
return { gsl::narrow<SHORT>(column), _pParent->GetId() };
}

// Routine Description:
// - Updates the pointer to the parent row (which might change if we shuffle the rows around)
// Arguments:
// - pParent - Pointer to the parent row
void CharRow::UpdateParent(ROW* const pParent)
{
_pParent = FAIL_FAST_IF_NULL(pParent);
}
29 changes: 9 additions & 20 deletions src/buffer/out/CharRow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,14 @@ class CharRow final

CharRow(size_t rowWidth, ROW* const pParent);

void SetWrapForced(const bool wrap) noexcept;
bool WasWrapForced() const noexcept;
void SetDoubleBytePadded(const bool doubleBytePadded) noexcept;
bool WasDoubleBytePadded() const noexcept;
size_t size() const noexcept;
void Reset() noexcept;
[[nodiscard]] HRESULT Resize(const size_t newSize) noexcept;
size_t MeasureLeft() const;
size_t MeasureRight() const noexcept;
void ClearCell(const size_t column);
bool ContainsText() const noexcept;
const DbcsAttribute& DbcsAttrAt(const size_t column) const;
DbcsAttribute& DbcsAttrAt(const size_t column);
void ClearGlyph(const size_t column);
std::wstring GetText() const;

const DelimiterClass DelimiterClassAt(const size_t column, const std::wstring_view wordDelimiters) const;

Expand All @@ -88,30 +81,26 @@ class CharRow final
const UnicodeStorage& GetUnicodeStorage() const noexcept;
COORD GetStorageKey(const size_t column) const noexcept;

void UpdateParent(ROW* const pParent);

friend CharRowCellReference;
friend constexpr bool operator==(const CharRow& a, const CharRow& b) noexcept;

protected:
// Occurs when the user runs out of text in a given row and we're forced to wrap the cursor to the next line
bool _wrapForced;
friend bool operator==(const CharRow& a, const CharRow& b) noexcept;
friend class ROW;

// Occurs when the user runs out of text to support a double byte character and we're forced to the next line
bool _doubleBytePadded;
private:
void Reset() noexcept;
void ClearCell(const size_t column);
std::wstring GetText() const;

protected:
// storage for glyph data and dbcs attributes
std::vector<value_type> _data;

// ROW that this CharRow belongs to
ROW* _pParent;
};

constexpr bool operator==(const CharRow& a, const CharRow& b) noexcept
inline bool operator==(const CharRow& a, const CharRow& b) noexcept
{
return (a._wrapForced == b._wrapForced &&
a._doubleBytePadded == b._doubleBytePadded &&
a._data == b._data);
return (a._data == b._data);
}

template<typename InputIt1, typename InputIt2>
Expand Down
52 changes: 50 additions & 2 deletions src/buffer/out/Row.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ ROW::ROW(const SHORT rowId, const short rowWidth, const TextAttribute fillAttrib
_rowWidth{ gsl::narrow<size_t>(rowWidth) },
_charRow{ gsl::narrow<size_t>(rowWidth), this },
_attrRow{ gsl::narrow<UINT>(rowWidth), fillAttribute },
_wrapForced{ false },
_doubleBytePadded{ false },
_pParent{ pParent }
{
}
Expand Down Expand Up @@ -68,6 +70,8 @@ void ROW::SetId(const SHORT id) noexcept
// - <none>
bool ROW::Reset(const TextAttribute Attr)
{
_wrapForced = false;
_doubleBytePadded = false;
_charRow.Reset();
try
{
Expand Down Expand Up @@ -213,7 +217,7 @@ OutputCellIterator ROW::WriteCells(OutputCellIterator it, const size_t index, co
else if (fillingLastColumn && it->DbcsAttr().IsLeading())
{
_charRow.ClearCell(currentIndex);
_charRow.SetDoubleBytePadded(true);
SetDoubleBytePadded(true);
}
// Otherwise, copy the data given and increment the iterator.
else
Expand All @@ -231,7 +235,7 @@ OutputCellIterator ROW::WriteCells(OutputCellIterator it, const size_t index, co
if (wrap.has_value() && fillingLastColumn)
{
// set wrap status on the row to parameter's value.
_charRow.SetWrapForced(wrap.value());
SetWrapForced(*wrap);
}
}
else
Expand All @@ -256,3 +260,47 @@ OutputCellIterator ROW::WriteCells(OutputCellIterator it, const size_t index, co

return it;
}

// Routine Description:
// - Sets the wrap status for the current row
// Arguments:
// - wrapForced - True if the row ran out of space and we forced to wrap to the next row. False otherwise.
// Return Value:
// - <none>
void ROW::SetWrapForced(const bool wrapForced) noexcept
{
_wrapForced = wrapForced;
}

// Routine Description:
// - Gets the wrap status for the current row
// Arguments:
// - <none>
// Return Value:
// - True if the row ran out of space and we were forced to wrap to the next row. False otherwise.
bool ROW::WasWrapForced() const noexcept
{
return _wrapForced;
}

// Routine Description:
// - Sets the double byte padding for the current row
// Arguments:
// - fWrapWasForced - True if the row ran out of space for a double byte character and we padded out the row. False otherwise.
// Return Value:
// - <none>
void ROW::SetDoubleBytePadded(const bool doubleBytePadded) noexcept
{
_doubleBytePadded = doubleBytePadded;
}

// Routine Description:
// - Gets the double byte padding status for the current row.
// Arguments:
// - <none>
// Return Value:
// - True if the row didn't have space for a double byte character and we were padded out the row. False otherwise.
bool ROW::WasDoubleBytePadded() const noexcept
{
return _doubleBytePadded;
}
12 changes: 12 additions & 0 deletions src/buffer/out/Row.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class ROW final

size_t size() const noexcept;

void SetWrapForced(const bool wrap) noexcept;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could just move the getters/setters up here per the other PR and chat recently about inline potential.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no reason not to

bool WasWrapForced() const noexcept;

void SetDoubleBytePadded(const bool doubleBytePadded) noexcept;
bool WasDoubleBytePadded() const noexcept;

const CharRow& GetCharRow() const noexcept;
CharRow& GetCharRow() noexcept;

Expand Down Expand Up @@ -70,6 +76,10 @@ class ROW final
ATTR_ROW _attrRow;
SHORT _id;
size_t _rowWidth;
// Occurs when the user runs out of text in a given row and we're forced to wrap the cursor to the next line
bool _wrapForced;
// Occurs when the user runs out of text to support a double byte character and we're forced to the next line
bool _doubleBytePadded;
TextBuffer* _pParent; // non ownership pointer
};

Expand All @@ -79,5 +89,7 @@ inline bool operator==(const ROW& a, const ROW& b) noexcept
a._attrRow == b._attrRow &&
a._rowWidth == b._rowWidth &&
a._pParent == b._pParent &&
a._wrapForced == b._wrapForced &&
a._doubleBytePadded == b._doubleBytePadded &&
a._id == b._id);
}
Loading