Skip to content

Commit

Permalink
UP-23, UP-24 Added methods GetLastGlyph() and GetPreviousGlyph()
Browse files Browse the repository at this point in the history
  • Loading branch information
tatyanakrivonogova committed May 28, 2024
1 parent 71bd28e commit d79afa2
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 18 deletions.
2 changes: 2 additions & 0 deletions include/document/glyphs/button.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class Button : public Glyph {
void Add(GlyphPtr) override {}

GlyphPtr GetFirstGlyph() override;
GlyphPtr GetLastGlyph() override;
GlyphPtr GetNextGlyph(GlyphPtr& glyph) override;
GlyphPtr GetPreviousGlyph(GlyphPtr& glyph) override;

/**
* @brief Returns whether the button is pressed.
Expand Down
2 changes: 2 additions & 0 deletions include/document/glyphs/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class Character : public Glyph {
char GetChar() const;

GlyphPtr GetFirstGlyph() override;
GlyphPtr GetLastGlyph() override;
GlyphPtr GetNextGlyph(GlyphPtr& glyph) override;
GlyphPtr GetPreviousGlyph(GlyphPtr& glyph) override;

std::shared_ptr<Glyph> Clone() const override;

Expand Down
13 changes: 7 additions & 6 deletions include/document/glyphs/glyph.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifndef TEXT_EDITOR_GLYPH_H_
#define TEXT_EDITOR_GLYPH_H_

#include <iostream>
#include <boost/serialization/export.hpp>
#include <boost/serialization/assume_abstract.hpp>
#include <boost/serialization/export.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <iostream>

#include "utils/point.h"

Expand Down Expand Up @@ -89,7 +89,9 @@ class Glyph {
virtual void MoveGlyph(int x, int y);

virtual GlyphPtr GetFirstGlyph() = 0;
virtual Glyph::GlyphPtr GetLastGlyph() = 0;
virtual GlyphPtr GetNextGlyph(GlyphPtr& glyph) = 0;
virtual GlyphPtr GetPreviousGlyph(GlyphPtr& glyph) = 0;

/**
* @brief Creates a copy of the glyph and wraps it in a smart
Expand Down Expand Up @@ -135,11 +137,10 @@ class Glyph {

explicit Glyph() {}

private:
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
std::cout << "0 Glyph\n";
ar & x & y & width & height;
std::cout << "1 Glyph\n";
Expand Down
17 changes: 9 additions & 8 deletions include/document/glyphs/glyph_container.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifndef TEXT_EDITOR_GLYPH_CONTAINER_H_
#define TEXT_EDITOR_GLYPH_CONTAINER_H_

#include <boost/serialization/list.hpp>
#include <boost/serialization/export.hpp>
#include <boost/serialization/assume_abstract.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/export.hpp>
#include <boost/serialization/list.hpp>

#include "glyph.h"

Expand All @@ -30,22 +30,23 @@ class GlyphContainer : public Glyph {
Glyph::GlyphPtr GetGlyphByIndex(int index);

GlyphPtr GetFirstGlyph() override;
Glyph::GlyphPtr GetLastGlyph() override;
GlyphPtr GetNextGlyph(GlyphPtr& glyph) override;
GlyphPtr GetPreviousGlyph(GlyphPtr& glyph) override;

protected:
Glyph::GlyphList components;
explicit GlyphContainer() {}
private:

private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
std::cout << "0 GlyphContainer\n";
ar & boost::serialization::base_object<Glyph>(*this);
ar& boost::serialization::base_object<Glyph>(*this);
ar & components;
std::cout << "1 GlyphContainer\n";
}

};

BOOST_SERIALIZATION_ASSUME_ABSTRACT(GlyphContainer)
Expand Down
2 changes: 2 additions & 0 deletions include/document/glyphs/monoglyph.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class MonoGlyph : public Glyph {
void Add(GlyphPtr glyph) override;

GlyphPtr GetFirstGlyph() override;
GlyphPtr GetLastGlyph() override;
GlyphPtr GetNextGlyph(GlyphPtr& glyph) override;
GlyphPtr GetPreviousGlyph(GlyphPtr& glyph) override;

std::shared_ptr<Glyph> Clone() const override;

Expand Down
4 changes: 1 addition & 3 deletions src/document/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ void Document::Remove(Glyph::GlyphPtr& glyph) {
compositor->Compose();
}

void Document::SetCurrentPage(Page::PagePtr page) {
currentPage = std::move(page);
}
void Document::SetCurrentPage(Page::PagePtr page) { currentPage = page; }

Page::PagePtr Document::GetCurrentPage() { return currentPage; }

Expand Down
2 changes: 2 additions & 0 deletions src/document/glyphs/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ void Button::Draw() {
}

Glyph::GlyphPtr Button::GetFirstGlyph() { return nullptr; }
Glyph::GlyphPtr Button::GetLastGlyph() { return nullptr; }

Glyph::GlyphPtr Button::GetNextGlyph(GlyphPtr& glyph) { return nullptr; }
Glyph::GlyphPtr Button::GetPreviousGlyph(GlyphPtr& glyph) { return nullptr; }

std::shared_ptr<Glyph> Button::Clone() const {
Button* copy =
Expand Down
5 changes: 4 additions & 1 deletion src/document/glyphs/character.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "document/glyphs/character.h"

#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include "document/glyphs/character.h"
BOOST_CLASS_EXPORT_IMPLEMENT(Character)

Character::Character(const int x, const int y, const int width,
Expand All @@ -16,8 +17,10 @@ void Character::SetChar(char c) { symbol = c; }
char Character::GetChar() const { return symbol; }

Glyph::GlyphPtr Character::GetFirstGlyph() { return nullptr; }
Glyph::GlyphPtr Character::GetLastGlyph() { return nullptr; }

Glyph::GlyphPtr Character::GetNextGlyph(GlyphPtr& glyph) { return nullptr; }
Glyph::GlyphPtr Character::GetPreviousGlyph(GlyphPtr& glyph) { return nullptr; }

std::shared_ptr<Glyph> Character::Clone() const {
Character* copy = new Character(this->x, this->y, this->width, this->height,
Expand Down
21 changes: 21 additions & 0 deletions src/document/glyphs/glyph_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ Glyph::GlyphPtr GlyphContainer::GetFirstGlyph() {
return *(components.begin());
}

Glyph::GlyphPtr GlyphContainer::GetLastGlyph() {
if (components.begin() == components.end()) {
return nullptr;
}
return *(components.end()--);
}

Glyph::GlyphPtr GlyphContainer::GetNextGlyph(GlyphPtr& glyph) {
auto currentGlyph =
std::find_if(components.begin(), components.end(),
Expand All @@ -65,4 +72,18 @@ Glyph::GlyphPtr GlyphContainer::GetNextGlyph(GlyphPtr& glyph) {
return nullptr;
}
return *nextGlyph;
}

Glyph::GlyphPtr GlyphContainer::GetPreviousGlyph(GlyphPtr& glyph) {
auto currentGlyph =
std::find_if(components.begin(), components.end(),
[&](const auto& elem) { return elem == glyph; });

assert(currentGlyph != components.end());

if (currentGlyph == components.begin()) {
return nullptr;
}
auto previousGlyph = std::prev(currentGlyph);
return *previousGlyph;
}
2 changes: 2 additions & 0 deletions src/document/glyphs/monoglyph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ void MonoGlyph::Remove(const GlyphPtr& glyph) {
}

Glyph::GlyphPtr MonoGlyph::GetFirstGlyph() { return component; }
Glyph::GlyphPtr MonoGlyph::GetLastGlyph() { return component; }

Glyph::GlyphPtr MonoGlyph::GetNextGlyph(GlyphPtr& glyph) { return nullptr; }
Glyph::GlyphPtr MonoGlyph::GetPreviousGlyph(GlyphPtr& glyph) { return nullptr; }

std::shared_ptr<Glyph> MonoGlyph::Clone() const {
// MonoGlyph* copy =
Expand Down

0 comments on commit d79afa2

Please sign in to comment.