Skip to content

Commit

Permalink
use boost::describe for reflection as well
Browse files Browse the repository at this point in the history
  • Loading branch information
antonvw committed Nov 25, 2024
1 parent ea7e6c0 commit 1f266fc
Show file tree
Hide file tree
Showing 18 changed files with 111 additions and 62 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

### Added

- added boost::describe for reflection as well
- added showing git diff as indicators in stc component
- added robotidy beautifier, and added config page
- added LISTBOX item that uses a wxListBox
Expand Down
1 change: 1 addition & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ It benefits from the following boost libraries:
lib | info
-----|------
boost::algorithm | uses find_tail, icontains, iequals, replace_all, to_upper, trim
boost::describe | to add reflection
boost::json | to implement wex::config
boost::log | to implement wex::log
boost::process | to implement wex::process
Expand Down
5 changes: 4 additions & 1 deletion include/wex/core/file-status.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Name: file-status.h
// Purpose: Declaration of wex::file_status class
// Author: Anton van Wezenbeek
// Copyright: (c) 2010-2022 Anton van Wezenbeek
// Copyright: (c) 2010-2024 Anton van Wezenbeek
////////////////////////////////////////////////////////////////////////////////

#pragma once
Expand All @@ -23,6 +23,9 @@ class file_status
/// Default constructor. Calls sync.
explicit file_status(const std::string& path = std::string()) { sync(path); }

/// << Operator.
friend std::ostream& operator<<(std::ostream& os, const file_status& rhs);

/// Returns access time.
time_t get_access_time() const;

Expand Down
8 changes: 6 additions & 2 deletions include/wex/core/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

#pragma once

#include <wex/core/file-status.h>

#include <bitset>
#include <filesystem>
#include <ostream>
#include <sstream>
#include <string>
#include <vector>

#include <wex/core/file-status.h>

namespace wex
{
class file;
Expand Down Expand Up @@ -79,6 +80,9 @@ class path
/// == Operator.
bool operator==(const path& r) const { return data() == r.data(); }

/// << Operator.
friend std::ostream& operator<<(std::ostream& os, const path& rhs);

/// Appends path.
path& append(const path& path);

Expand Down
17 changes: 8 additions & 9 deletions include/wex/core/reflection.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Name: reflection.h
// Purpose: Declaration of wex::reflection class
// Author: Anton van Wezenbeek
// Copyright: (c) 2023 Anton van Wezenbeek
// Copyright: (c) 2023-2024 Anton van Wezenbeek
////////////////////////////////////////////////////////////////////////////////

#pragma once
Expand All @@ -12,15 +12,14 @@
#include <sstream>
#include <vector>

/// YOu can use this macro to add reflection to your class members,
/// You can use this macro to add reflection to your class members,
/// or functions.
#define REFLECT_ADD(NAME, ITEM) \
{ \
NAME, [&]() \
{ \
return ITEM; \
} \
}
#define REFLECT_ADD(NAME, ITEM) \
{NAME, \
[&]() \
{ \
return ITEM; \
}}

namespace wex
{
Expand Down
14 changes: 9 additions & 5 deletions include/wex/ctags/ctags-entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@

#pragma once

#include <string>

#include <boost/describe.hpp>
#include <readtags.h>
#include <wex/core/reflection.h>
#include <string>

class wxStyledTextCtrl;

Expand Down Expand Up @@ -132,7 +131,7 @@ class ctags_entry
ctags_entry& kind(const std::string& v);

/// Logs info about this entry.
const std::stringstream log() const { return m_reflect.log(); }
const std::stringstream log() const;

/// Returns signature member.
const auto& signature() const { return m_signature; }
Expand All @@ -149,6 +148,11 @@ class ctags_entry

std::string m_access, m_class, m_kind, m_signature;

reflection m_reflect;
BOOST_DESCRIBE_CLASS(
ctags_entry,
(),
(),
(),
(m_access, m_class, m_kind, m_signature))
};
}; // namespace wex
8 changes: 8 additions & 0 deletions include/wex/data/substitute.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#pragma once

#include <boost/describe.hpp>
#include <string>

namespace wex::data
Expand Down Expand Up @@ -60,5 +61,12 @@ class substitute
std::string m_commands, m_options, m_pattern, m_replacement;

bool m_clear{false}, m_global_command{false}, m_inverse{false};

BOOST_DESCRIBE_CLASS(
substitute,
(),
(),
(),
(m_commands, m_options, m_pattern, m_replacement))
};
} // namespace wex::data
8 changes: 1 addition & 7 deletions include/wex/syntax/lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
// Name: lexer.h
// Purpose: Declaration of wex::lexer class
// Author: Anton van Wezenbeek
// Copyright: (c) 2008-2023 Anton van Wezenbeek
// Copyright: (c) 2008-2024 Anton van Wezenbeek
////////////////////////////////////////////////////////////////////////////////

#pragma once

#include <wex/core/reflection.h>
#include <wex/syntax/property.h>
#include <wex/syntax/style.h>

Expand Down Expand Up @@ -133,9 +132,6 @@ class lexer
/// Returns the line size.
size_t line_size() const;

/// Logs info about this class.
std::stringstream log() const { return m_reflect.log(); }

/// Returns a lexer comment string with text formatted.
const std::string make_comment(
const std::string& text,
Expand Down Expand Up @@ -216,7 +212,5 @@ class lexer
bool m_is_ok{false}, m_previewable{false};

syntax::stc* m_stc{nullptr};

reflection m_reflect;
};
}; // namespace wex
14 changes: 10 additions & 4 deletions include/wex/ui/listitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// Name: listitem.h
// Purpose: Declaration of class wex::listitem
// Author: Anton van Wezenbeek
// Copyright: (c) 2009-2023 Anton van Wezenbeek
// Copyright: (c) 2009-2024 Anton van Wezenbeek
////////////////////////////////////////////////////////////////////////////////

#pragma once

#include <boost/describe.hpp>

#include <wex/core/path.h>
#include <wex/core/reflection.h>
#include <wex/ui/listview.h>

namespace wex
Expand Down Expand Up @@ -43,7 +44,7 @@ class listitem : public wxListItem
bool is_readonly() const { return m_is_readonly; }

/// Logs info about this item.
std::stringstream log() const { return m_reflect.log(); }
std::stringstream log() const;

/// Returns the path.
const auto& path() const { return m_path; }
Expand All @@ -66,6 +67,11 @@ class listitem : public wxListItem
const std::string m_file_spec;
bool m_is_readonly{false};

reflection m_reflect;
BOOST_DESCRIBE_CLASS(
listitem,
(),
(),
(),
(m_path, m_file_spec, m_is_readonly))
};
}; // namespace wex
7 changes: 7 additions & 0 deletions src/core/file-status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
#include <unistd.h>
#endif

std::ostream& wex::operator<<(std::ostream& os, const wex::file_status& rhs)
{
os << rhs.m_fullpath;

return os;
}

const std::string
wex::file_status::get_creation_time_str(const std::string& format) const
{
Expand Down
6 changes: 6 additions & 0 deletions src/core/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ wex::path::path(const std::vector<std::string>& v, log_t t)
}
}

std::ostream& wex::operator<<(std::ostream& os, const wex::path& p)
{
os << p.m_path;
return os;
}

wex::path::~path()
{
if (!m_path_original.empty() && m_path_original != current().data())
Expand Down
12 changes: 4 additions & 8 deletions src/ex/ex-stream-line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ wex::ex_stream_line::ex_stream_line(
, m_end(
type != ACTION_JOIN ? range.end().get_line() - 1 :
range.end().get_line() - 2)
, m_reflect(
{REFLECT_ADD("actions", m_actions),
REFLECT_ADD("from", m_begin),
REFLECT_ADD("to", m_end),
REFLECT_ADD("pattern", m_data.pattern()),
REFLECT_ADD("replacement", m_data.replacement())},
reflection::log_t::SKIP_EMPTY)
{
}

Expand Down Expand Up @@ -107,7 +100,10 @@ wex::ex_stream_line::ex_stream_line(

wex::ex_stream_line::~ex_stream_line()
{
log::trace("ex stream " + m_action_names.at(m_action)) << m_reflect.log();
std::stringstream ss;
using boost::describe::operators::operator<<;
ss << *this << m_data;
log::trace("ex stream " + m_action_names.at(m_action)) << ss;
}

wex::ex_stream_line::handle_t
Expand Down
12 changes: 8 additions & 4 deletions src/ex/ex-stream-line.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
// Name: ex-stream-line.h
// Purpose: Declaration of class wex::ex_stream_line
// Author: Anton van Wezenbeek
// Copyright: (c) 2020-2023 Anton van Wezenbeek
// Copyright: (c) 2020-2024 Anton van Wezenbeek
////////////////////////////////////////////////////////////////////////////////

#pragma once

#include <unordered_map>
#include <wex/core/file.h>
#include <wex/core/reflection.h>
#include <wex/data/substitute.h>
#include <wex/ex/addressrange.h>

Expand Down Expand Up @@ -109,8 +108,13 @@ class ex_stream_line

std::string m_copy;

reflection m_reflect;

static const std::unordered_map<action_t, std::string> m_action_names;

BOOST_DESCRIBE_CLASS(
ex_stream_line,
(),
(),
(),
(m_action, m_text, m_register, m_begin, m_end, m_dest))
};
}; // namespace wex
5 changes: 0 additions & 5 deletions src/syntax/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ wex::lexer::lexer(const pugi::xml_node* node)
wex::lexer::lexer(const pugi::xml_node* node, syntax::stc* s)
: m_scintilla_lexer(node != nullptr ? node->attribute("name").value() : "")
, m_stc(s)
, m_reflect(
{REFLECT_ADD("display", m_display_lexer),
REFLECT_ADD("extensions", m_extensions),
REFLECT_ADD("language", m_language),
REFLECT_ADD("lexer", m_scintilla_lexer)})
{
}

Expand Down
18 changes: 9 additions & 9 deletions src/ui/ctags/ctags-entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,7 @@ enum class image_access_t
};
}

wex::ctags_entry::ctags_entry()
: m_reflect(
{REFLECT_ADD("access", m_access),
REFLECT_ADD("class", m_class),
REFLECT_ADD("kind", m_kind),
REFLECT_ADD("signature", m_signature)},
reflection::log_t::SKIP_EMPTY)
{
}
wex::ctags_entry::ctags_entry() {}

wex::ctags_entry& wex::ctags_entry::access(const std::string& v)
{
Expand Down Expand Up @@ -187,6 +179,14 @@ wex::ctags_entry& wex::ctags_entry::kind(const std::string& v)
return *this;
}

const std::stringstream wex::ctags_entry::log() const
{
std::stringstream ss;
using boost::describe::operators::operator<<;
ss << *this;
return ss;
}

void wex::ctags_entry::register_image(wxStyledTextCtrl* stc)
{
stc->RegisterImage(
Expand Down
10 changes: 8 additions & 2 deletions src/ui/listitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ wex::listitem::listitem(
: m_listview(listview)
, m_path(filename)
, m_file_spec(filespec)
, m_reflect(
{REFLECT_ADD("path", m_path.string()), REFLECT_ADD("id", GetId())})
{
SetId(-1);
}
Expand Down Expand Up @@ -83,6 +81,14 @@ void wex::listitem::insert(long index)
}
}

std::stringstream wex::listitem::log() const
{
std::stringstream ss;
using boost::describe::operators::operator<<;
ss << "listitem: " << *this << GetId();
return ss;
}

bool wex::listitem::set_item(
const std::string& col_name,
const std::string& text)
Expand Down
Loading

0 comments on commit 1f266fc

Please sign in to comment.