LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/context - cdmaybe.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 15 15 100.0 %
Date: 2026-07-14 10:35:28 Functions: 7 7 100.0 %
Branches: 6 18 33.3 %

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

Generated by: LCOV version 1.14