- #include <cerrno>
- #include <cstring>
- #include <j/lang/errno.hpp>
- #include <j/lang/throwable.hpp>
- namespace j
- {
- namespace lang
- {
- /**
- * Throwable を構築します。
- */
- Throwable::Throwable() noexcept : message(Errno::message(Errno::get()))
- {
- // NOP
- }
- /**
- * Throwable を構築します。
- *
- * @param msg メッセージ
- */
- Throwable::Throwable(const String &msg) noexcept : message(msg)
- {
- // NOP
- }
- /**
- * Throwable のコピーコンストラクタ。
- *
- * @param t コピー元 Throwable
- */
- Throwable::Throwable(const Throwable &t) noexcept : Object(t), message(t.message)
- {
- // NOP
- }
- /**
- * Throwable のムーブコンストラクタ。
- *
- * @param str ムーブ元 String
- */
- Throwable::Throwable(Throwable &&t) noexcept : Object(std::move(t)), message(std::move(t.message))
- {
- t.message = nullptr;
- }
- /**
- * デストラクタ。
- */
- Throwable::~Throwable() noexcept
- {
- // NOP
- }
- /**
- * コピー代入演算子。
- * コピーして代入します。
- *
- * @param str コピー元 String
- * @return 本オブジェクトへの参照
- */
- Throwable &Throwable::operator=(const Throwable &t) noexcept
- {
- if (this != &t)
- {
- Object::operator=(t);
- message = t.message;
- }
- return *this;
- }
- /**
- * ムーブ代入演算子。
- *
- * @param obj ムーブ元オブジェクト
- * @return 本オブジェクトへの参照
- */
- Throwable &Throwable::operator=(Throwable &&t) noexcept
- {
- if (this != &t)
- {
- Object::operator=(std::move(t));
- message = std::move(t.message);
- t.message = nullptr;
- }
- return *this;
- }
- /**
- * エラーメッセージを取得します。
- *
- * @return エラーメッセージ
- */
- String Throwable::getMessage() const noexcept
- {
- return message;
- }
- /**
- * 本オブジェクトの文字列表現を返します。
- *
- * @return 本オブジェクトの文字列表現
- */
- String Throwable::toString() const noexcept
- {
- return getMessage();
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // protected
- //
- /**
- * 本オブジェクトの複製を取得します。
- *
- * [備考]
- * 派生クラスが、ポリモーフィズムをサポートするために、
- * unique_ptr<Object> を返すようにしています。
- *
- * @return 本オブジェクトの複製
- */
- std::unique_ptr<Object> Throwable::clone() const noexcept
- {
- return std::make_unique<Throwable>(*this);
- }
- } // namespace lang
- } // namespace j