File: constants.h

package info (click to toggle)
polymake 4.14-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,888 kB
  • sloc: cpp: 168,933; perl: 43,407; javascript: 31,575; ansic: 3,007; java: 2,654; python: 632; sh: 268; xml: 117; makefile: 61
file content (132 lines) | stat: -rw-r--r-- 3,240 bytes parent folder | download | duplicates (2)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* Copyright (c) 1997-2024
   Ewgenij Gawrilow, Michael Joswig, and the polymake team
   Technische Universität Berlin, Germany
   https://polymake.org

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version: http://www.gnu.org/licenses/gpl.txt.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
--------------------------------------------------------------------------------
*/

#pragma once

#include "polymake/AnyString.h"

namespace pm { namespace perl {

enum class ValueFlags {
   is_mutable = 0, read_only = 1, alloc_magic = 2, expect_lval = 4,
   allow_undef = 8, allow_non_persistent = 0x10, ignore_magic = 0x20,
   is_trusted = 0, not_trusted = 0x40, allow_conversion = 0x80,
   allow_store_ref = 0x100, allow_store_temp_ref = 0x200,
   allow_store_any_ref = allow_store_ref | allow_store_temp_ref
};

enum class ClassFlags {
   none = 0,
   is_scalar = 0, is_container, is_composite, is_opaque, kind_mask=0xf,
   is_assoc_container = 0x100, is_sparse_container = 0x200, is_set = 0x400,
   is_serializable = 0x800, is_sparse_serialized = 0x1000, is_declared = 0x2000,
   is_ordered = 0x4000
};

enum class Returns {
   normal,
   lvalue,
   list,
   empty  // should be void but it's a reserved keyword
};

// function argument reference classification
enum {
   arg_is_const_ref,
   arg_is_lval_ref,
   arg_is_univ_ref,
   arg_is_const_or_rval_ref
};

constexpr ValueFlags operator| (ValueFlags a, ValueFlags b)
{
   return static_cast<ValueFlags>(int(a) | int(b));
}

constexpr ValueFlags operator& (ValueFlags a, ValueFlags b)
{
   return static_cast<ValueFlags>(int(a) & int(b));
}

constexpr bool operator* (ValueFlags a, ValueFlags b)
{
   return (int(a) & int(b)) != 0;
}

constexpr ClassFlags operator| (ClassFlags a, ClassFlags b)
{
   return static_cast<ClassFlags>(int(a) | int(b));
}

constexpr ClassFlags operator& (ClassFlags a, ClassFlags b)
{
   return static_cast<ClassFlags>(int(a) & int(b));
}

constexpr bool operator* (ClassFlags a, ClassFlags b)
{
   return (int(a) & int(b)) != 0;
}

inline
ValueFlags& operator|= (ValueFlags& a, ValueFlags b)
{
   a = a | b;
   return a;
}

inline
ClassFlags& operator|= (ClassFlags& a, ClassFlags b)
{
   a = a | b;
   return a;
}

template <typename L>
void set_bit_flags(L& l, unsigned int r)
{
   l = static_cast<L>(static_cast<unsigned int>(l) | r);
}

template <typename L, typename R>
std::enable_if_t<std::is_enum<R>::value>
set_bit_flags(L& l, R r)
{
   set_bit_flags(l, static_cast<unsigned int>(r));
}

template <typename L>
void clear_bit_flags(L& l, unsigned int r)
{
   l = static_cast<L>(static_cast<unsigned int>(l) & ~r);
}

template <typename L, typename R>
std::enable_if_t<std::is_enum<R>::value>
clear_bit_flags(L& l, R r)
{
   clear_bit_flags(l, static_cast<unsigned int>(r));
}

} }


// Local Variables:
// mode:C++
// c-basic-offset:3
// indent-tabs-mode:nil
// End: