weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 2 | /* |
| 3 | * Copyright (c) 2014-2022, Regents of the University of California. |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of NDN repo-ng (Next generation of NDN repository). |
| 6 | * See AUTHORS.md for complete list of repo-ng authors and contributors. |
| 7 | * |
| 8 | * repo-ng is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 19 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 20 | #ifndef REPO_REPO_COMMAND_HPP |
| 21 | #define REPO_REPO_COMMAND_HPP |
| 22 | |
| 23 | #include "common.hpp" |
| 24 | #include "repo-command-parameter.hpp" |
| 25 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 26 | namespace repo { |
| 27 | |
| 28 | class RepoCommand : boost::noncopyable |
| 29 | { |
| 30 | public: |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 31 | /** |
| 32 | * \brief Represents an error in RepoCommandParameters |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 33 | */ |
| 34 | class ArgumentError : public std::invalid_argument |
| 35 | { |
| 36 | public: |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 37 | using std::invalid_argument::invalid_argument; |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | virtual |
| 41 | ~RepoCommand() = default; |
| 42 | |
| 43 | class FieldValidator |
| 44 | { |
| 45 | public: |
| 46 | FieldValidator(); |
| 47 | |
| 48 | /** \brief declare a required field |
| 49 | */ |
| 50 | FieldValidator& |
| 51 | required(RepoParameterField field) |
| 52 | { |
| 53 | m_required[field] = true; |
| 54 | return *this; |
| 55 | } |
| 56 | |
| 57 | /** \brief declare an optional field |
| 58 | */ |
| 59 | FieldValidator& |
| 60 | optional(RepoParameterField field) |
| 61 | { |
| 62 | m_optional[field] = true; |
| 63 | return *this; |
| 64 | } |
| 65 | |
| 66 | /** \brief verify that all required fields are present, |
| 67 | * and all present fields are either required or optional |
| 68 | * \throw ArgumentError |
| 69 | */ |
| 70 | void |
| 71 | validate(const RepoCommandParameter& parameters) const; |
| 72 | |
| 73 | private: |
| 74 | std::vector<bool> m_required; |
| 75 | std::vector<bool> m_optional; |
| 76 | }; |
| 77 | |
| 78 | void |
| 79 | validateRequest(const RepoCommandParameter& parameters); |
| 80 | |
| 81 | private: |
| 82 | virtual void |
| 83 | check(const RepoCommandParameter& parameters) const |
| 84 | { |
| 85 | } |
| 86 | |
| 87 | public: |
| 88 | FieldValidator m_requestValidator; |
| 89 | }; |
| 90 | |
| 91 | class InsertCommand : public RepoCommand |
| 92 | { |
| 93 | public: |
| 94 | InsertCommand(); |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | class InsertCheckCommand : public RepoCommand |
| 98 | { |
| 99 | public: |
| 100 | InsertCheckCommand(); |
| 101 | }; |
| 102 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 103 | class DeleteCommand : public RepoCommand |
| 104 | { |
| 105 | public: |
| 106 | DeleteCommand(); |
| 107 | |
| 108 | private: |
| 109 | void |
| 110 | check(const RepoCommandParameter& parameters) const override; |
| 111 | }; |
| 112 | |
| 113 | } // namespace repo |
| 114 | |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame^] | 115 | #endif // REPO_REPO_COMMAND_HPP |