blob: 28c299938dd765929a6014bbc3a9add1e8ad3fb2 [file] [log] [blame]
weijia yuan82cf9142018-10-21 12:25:02 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2018, Regents of the University of California.
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 */
19#ifndef REPO_REPO_COMMAND_HPP
20#define REPO_REPO_COMMAND_HPP
21
22#include "common.hpp"
23#include "repo-command-parameter.hpp"
24
25#include <stdexcept>
26
27namespace repo {
28
29class RepoCommand : boost::noncopyable
30{
31public:
32 /** \brief represents an error in RepoCommandParameters
33 */
34 class ArgumentError : public std::invalid_argument
35 {
36 public:
37 explicit
38 ArgumentError(const std::string& what)
39 : std::invalid_argument(what)
40 {
41 }
42 };
43
44 virtual
45 ~RepoCommand() = default;
46
47 class FieldValidator
48 {
49 public:
50 FieldValidator();
51
52 /** \brief declare a required field
53 */
54 FieldValidator&
55 required(RepoParameterField field)
56 {
57 m_required[field] = true;
58 return *this;
59 }
60
61 /** \brief declare an optional field
62 */
63 FieldValidator&
64 optional(RepoParameterField field)
65 {
66 m_optional[field] = true;
67 return *this;
68 }
69
70 /** \brief verify that all required fields are present,
71 * and all present fields are either required or optional
72 * \throw ArgumentError
73 */
74 void
75 validate(const RepoCommandParameter& parameters) const;
76
77 private:
78 std::vector<bool> m_required;
79 std::vector<bool> m_optional;
80 };
81
82 void
83 validateRequest(const RepoCommandParameter& parameters);
84
85private:
86 virtual void
87 check(const RepoCommandParameter& parameters) const
88 {
89 }
90
91public:
92 FieldValidator m_requestValidator;
93};
94
95class InsertCommand : public RepoCommand
96{
97public:
98 InsertCommand();
weijia yuan82cf9142018-10-21 12:25:02 -070099};
100
101class InsertCheckCommand : public RepoCommand
102{
103public:
104 InsertCheckCommand();
105};
106
weijia yuan82cf9142018-10-21 12:25:02 -0700107class DeleteCommand : public RepoCommand
108{
109public:
110 DeleteCommand();
111
112private:
113 void
114 check(const RepoCommandParameter& parameters) const override;
115};
116
117} // namespace repo
118
119#endif // REPO_REPO_COMMAND_HPP