Program Listing for File named_object.hpp

Return to documentation for file (include/email/named_object.hpp)

// Copyright 2021 Christophe Bedard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef EMAIL__NAMED_OBJECT_HPP_
#define EMAIL__NAMED_OBJECT_HPP_

#include <regex>
#include <stdexcept>
#include <string>

#include "email/macros.hpp"

namespace email
{

class ObjectNameInvalidError : public std::runtime_error
{
protected:
  explicit ObjectNameInvalidError(
    const std::string & object_type_name,
    const std::string & object_name,
    const std::string & reason)
  : std::runtime_error(object_type_name + " name invalid (" + reason + "): '" + object_name + "'")
  {}
};


class NamedObject
{
protected:

  const std::string &
  get_object_name() const;


  explicit NamedObject(const std::string & name);

  virtual ~NamedObject();

  virtual
  void
  validate_name() const = 0;

  bool
  has_newline() const;

private:
  EMAIL_DISABLE_COPY(NamedObject)


  static const std::regex REGEX_NEWLINE;

  const std::string object_name_;
};

}  // namespace email

#endif  // EMAIL__NAMED_OBJECT_HPP_