aboutsummaryrefslogtreecommitdiff
path: root/build/name
blob: fdfe0830b555a58b1e444f5e75ab1460cf6afe35 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// file      : build/name -*- C++ -*-
// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#ifndef BUILD_NAME
#define BUILD_NAME

#include <string>
#include <vector>
#include <iosfwd>
#include <utility> // move()

#include <butl/path>

// Note: include <build/types> instead of this file directly.
//
namespace build
{
  using butl::dir_path;

  // A name is what we operate on by default. Depending on the context,
  // it can be interpreted as a target or prerequisite name. A name
  // without a type and directory can be used to represent any text.
  // A name with directory and empty value represents a directory.
  //
  // If pair is not '\0', then this name and the next in the list
  // form a pair.
  //
  struct name
  {
    name () = default;

    explicit
    name (std::string v): value (std::move (v)) {}

    explicit
    name (dir_path d): dir (std::move (d)) {}

    name (std::string t, dir_path d, std::string v)
        : type (std::move (t)), dir (std::move (d)), value (std::move (v)) {}

    bool
    empty () const {return type.empty () && dir.empty () && value.empty ();}

    bool
    simple () const {return type.empty () && dir.empty ();}

    bool
    directory () const
    {return type.empty () && !dir.empty () && value.empty ();}

    std::string type;
    dir_path dir;
    std::string value;
    char pair = '\0'; // Pair symbol, if any.
  };

  inline bool
  operator== (const name& x, const name& y)
  {
    return x.type == y.type && x.dir == y.dir && x.value == y.value;
  }

  inline bool
  operator!= (const name& x, const name& y) {return !(x == y);}

  typedef std::vector<name> names;

  std::ostream&
  operator<< (std::ostream&, const name&);

  std::ostream&
  operator<< (std::ostream&, const names&);
}

#endif // BUILD_NAME