aboutsummaryrefslogtreecommitdiff
path: root/build2/test/script/builtin
blob: e3c16b336af4e02f75f6b0d22384955bc26178f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// file      : build2/test/script/builtin -*- C++ -*-
// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#ifndef BUILD2_TEST_SCRIPT_BUILTIN
#define BUILD2_TEST_SCRIPT_BUILTIN

#include <build2/types>
#include <build2/utility>

#include <map>

namespace build2
{
  namespace test
  {
    namespace script
    {
      class scope;

      // Note that unlike argc/argv, our args don't include the program name.
      //
      using builtin = int (*) (scope&,
                               const strings& args,
                               auto_fd in, auto_fd out, auto_fd err);

      class builtin_map: public std::map<string, builtin>
      {
      public:
        using base = std::map<string, builtin>;
        using base::base;

        // Return NULL if not a builtin.
        //
        builtin
        find (const string& n) const
        {
          auto i (base::find (n));
          return i != end () ? i->second : nullptr;
        }
      };

      extern const builtin_map builtins;
    }
  }
}

#endif // BUILD2_TEST_SCRIPT_BUILTIN