blob: b985cbfd261cbb6560148acc03646f096a1ae37e [file] [log] [blame]
weijia yuan82cf9142018-10-21 12:25:02 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento11904062022-04-14 22:33:28 -04002/*
3 * Copyright (c) 2014-2022, Regents of the University of California.
weijia yuan82cf9142018-10-21 12:25:02 -07004 *
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 Pesavento11904062022-04-14 22:33:28 -040019
weijia yuan82cf9142018-10-21 12:25:02 -070020#ifndef REPO_REPO_COMMAND_HPP
21#define REPO_REPO_COMMAND_HPP
22
23#include "common.hpp"
24#include "repo-command-parameter.hpp"
25
weijia yuan82cf9142018-10-21 12:25:02 -070026namespace repo {
27
28class RepoCommand : boost::noncopyable
29{
30public:
Davide Pesavento11904062022-04-14 22:33:28 -040031 /**
32 * \brief Represents an error in RepoCommandParameters
weijia yuan82cf9142018-10-21 12:25:02 -070033 */
34 class ArgumentError : public std::invalid_argument
35 {
36 public:
Davide Pesavento11904062022-04-14 22:33:28 -040037 using std::invalid_argument::invalid_argument;
weijia yuan82cf9142018-10-21 12:25:02 -070038 };
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
81private:
82 virtual void
83 check(const RepoCommandParameter& parameters) const
84 {
85 }
86
87public:
88 FieldValidator m_requestValidator;
89};
90
91class InsertCommand : public RepoCommand
92{
93public:
94 InsertCommand();
weijia yuan82cf9142018-10-21 12:25:02 -070095};
96
97class InsertCheckCommand : public RepoCommand
98{
99public:
100 InsertCheckCommand();
101};
102
weijia yuan82cf9142018-10-21 12:25:02 -0700103class DeleteCommand : public RepoCommand
104{
105public:
106 DeleteCommand();
107
108private:
109 void
110 check(const RepoCommandParameter& parameters) const override;
111};
112
113} // namespace repo
114
Davide Pesavento11904062022-04-14 22:33:28 -0400115#endif // REPO_REPO_COMMAND_HPP