GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/context/cdmaybe.h Lines: 22 22 100.0 %
Date: 2021-05-22 Branches: 12 60 20.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Tim King
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8
 * in the top-level source directory and their institutional affiliations.
9
 * All rights reserved.  See the file COPYING in the top-level source
10
 * directory for licensing information.
11
 * ****************************************************************************
12
 * A context-dependent "maybe" template type
13
 *
14
 * This implements a CDMaybe.
15
 * This has either been set in the context or it has not.
16
 * Template parameter T must have a default constructor and support
17
 * assignment.
18
 */
19
20
#include "cvc5_private.h"
21
22
#pragma once
23
24
#include "context/cdo.h"
25
#include "context/context.h"
26
27
namespace cvc5 {
28
namespace context {
29
30
9459
class CDRaised {
31
private:
32
  context::CDO<bool> d_flag;
33
34
public:
35
9459
 CDRaised(context::Context* c)
36
9459
 : d_flag(c, false)
37
9459
 {}
38
39
40
598113
  bool isRaised() const {
41
598113
    return d_flag.get();
42
  }
43
44
1943
  void raise(){
45
1943
    Assert(!isRaised());
46
1943
    d_flag.set(true);
47
1943
  }
48
49
};/* class CDRaised */
50
51
template <class T>
52
9459
class CDMaybe {
53
private:
54
  typedef std::pair<bool, T> BoolTPair;
55
  context::CDO<BoolTPair> d_data;
56
57
public:
58
18918
  CDMaybe(context::Context* c) : d_data(c, std::make_pair(false, T()))
59
9459
  {}
60
61
1023744
  bool isSet() const {
62
1023744
    return d_data.get().first;
63
  }
64
65
1517
  void set(const T& d){
66
1517
    Assert(!isSet());
67
3034
    d_data.set(std::make_pair(true, d));
68
1517
  }
69
70
1517
  const T& get() const{
71
1517
    Assert(isSet());
72
1517
    return d_data.get().second;
73
  }
74
};/* class CDMaybe<T> */
75
76
}  // namespace context
77
}  // namespace cvc5