ChaiScript / ChaiScript
1
// This file is distributed under the BSD License.
2
// See "license.txt" for details.
3
// Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com)
4
// Copyright 2009-2017, Jason Turner (jason@emptycrate.com)
5
// http://www.chaiscript.com
6

7
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
8
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
9

10

11
#ifndef CHAISCRIPT_FUNCTION_PARAMS_HPP
12
#define CHAISCRIPT_FUNCTION_PARAMS_HPP
13

14

15
#include "boxed_value.hpp"
16

17
namespace chaiscript {
18

19
  class Function_Params
20
  {
21
    public:
22 1
      constexpr Function_Params(const Boxed_Value * const t_begin, const Boxed_Value * const t_end)
23 1
        : m_begin(t_begin), m_end(t_end)
24
      {
25
      }
26

27 1
      explicit Function_Params(const Boxed_Value &bv)
28 1
        : m_begin(&bv), m_end(m_begin + 1)
29
      {
30
      }
31

32 1
      explicit Function_Params(const std::vector<Boxed_Value> &vec)
33 1
        : m_begin(vec.empty() ? nullptr : &vec.front()), m_end(vec.empty() ? nullptr : &vec.front() + vec.size())
34
      {
35
      }
36

37
      template<size_t Size>
38 1
      constexpr explicit Function_Params(const std::array<Boxed_Value, Size> &a)
39 1
        : m_begin(&a.front()), m_end(&a.front() + Size)
40
      {
41
      }
42

43 1
      [[nodiscard]] constexpr const Boxed_Value &operator[](const std::size_t t_i) const noexcept {
44 1
        return m_begin[t_i];
45
      }
46

47 1
      [[nodiscard]] constexpr const Boxed_Value *begin() const noexcept {
48 1
        return m_begin;
49
      }
50

51 1
      [[nodiscard]] constexpr const Boxed_Value &front() const noexcept {
52 1
        return *m_begin;
53
      }
54

55 1
      [[nodiscard]] constexpr const Boxed_Value *end() const noexcept {
56 1
        return m_end;
57
      }
58

59 1
      [[nodiscard]] constexpr std::size_t size() const noexcept {
60 1
        return m_end - m_begin;
61
      }
62

63 1
      std::vector<Boxed_Value> to_vector() const {
64 1
        return std::vector<Boxed_Value>{m_begin, m_end};
65
      }
66

67 1
      [[nodiscard]] constexpr bool empty() const noexcept {
68 1
        return m_begin == m_end;
69
      }
70

71
    private:
72
      const Boxed_Value *m_begin = nullptr;
73
      const Boxed_Value *m_end = nullptr;
74

75
  };
76

77
  // Constructor specialization for array of size 0
78
  template<>
79 1
  constexpr Function_Params::Function_Params(const std::array<Boxed_Value, size_t{0}> & /* a */)
80 1
    : m_begin(nullptr), m_end(nullptr)
81
  {
82
  }
83

84
}
85

86

87
#endif
88

Read our documentation on viewing source code .

Loading