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

Line Exec Source
1
/*********************                                                        */
2
/*! \file cdmaybe.h
3
 ** \verbatim
4
 ** Top contributors (to current version):
5
 **   Tim King
6
 ** This file is part of the CVC4 project.
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.\endverbatim
11
 **
12
 ** \brief 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 "cvc4_private.h"
21
22
#pragma once
23
24
#include "context/cdo.h"
25
#include "context/context.h"
26
27
namespace CVC4 {
28
namespace context {
29
30
8994
class CDRaised {
31
private:
32
  context::CDO<bool> d_flag;
33
34
public:
35
8997
 CDRaised(context::Context* c)
36
8997
 : d_flag(c, false)
37
8997
 {}
38
39
40
850313
  bool isRaised() const {
41
850313
    return d_flag.get();
42
  }
43
44
2388
  void raise(){
45
2388
    Assert(!isRaised());
46
2388
    d_flag.set(true);
47
2388
  }
48
49
};/* class CDRaised */
50
51
template <class T>
52
10820
class CDMaybe {
53
private:
54
  typedef std::pair<bool, T> BoolTPair;
55
  context::CDO<BoolTPair> d_data;
56
57
public:
58
21646
  CDMaybe(context::Context* c) : d_data(c, std::make_pair(false, T()))
59
10823
  {}
60
61
883598
  bool isSet() const {
62
883598
    return d_data.get().first;
63
  }
64
65
1724
  void set(const T& d){
66
1724
    Assert(!isSet());
67
3448
    d_data.set(std::make_pair(true, d));
68
1724
  }
69
70
2506
  const T& get() const{
71
2506
    Assert(isSet());
72
2506
    return d_data.get().second;
73
  }
74
};/* class CDMaybe<T> */
75
76
}/* CVC4::context namespace */
77
}/* CVC4 namespace */
78