1 | // |
---|

2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo |
---|

3 | // |
---|

4 | // The contents of this file are covered under the licence agreement in the |
---|

5 | // file "LICENCE" distributed with Cforall. |
---|

6 | // |
---|

7 | // result -- Contains the expected value or an error value. |
---|

8 | // |
---|

9 | // Author : Andrew Beach |
---|

10 | // Created On : Wed May 24 14:45:00 2017 |
---|

11 | // Last Modified By : Peter A. Buhr |
---|

12 | // Last Modified On : Sat Jul 22 10:00:44 2017 |
---|

13 | // Update Count : 3 |
---|

14 | // |
---|

15 | |
---|

16 | #pragma once |
---|

17 | |
---|

18 | #include <stdbool.h> |
---|

19 | |
---|

20 | // DO NOT USE DIRECTLY! |
---|

21 | forall(otype T, otype E) |
---|

22 | union inner_result{ |
---|

23 | T value; |
---|

24 | E error; |
---|

25 | }; |
---|

26 | |
---|

27 | forall(otype T, otype E) |
---|

28 | struct result { |
---|

29 | bool has_value; |
---|

30 | inline union inner_result(T, E); |
---|

31 | }; |
---|

32 | |
---|

33 | |
---|

34 | forall(otype T, otype E) |
---|

35 | void ?{}(result(T, E) & this); |
---|

36 | |
---|

37 | forall(otype T, otype E) |
---|

38 | void ?{}(result(T, E) & this, one_t, T value); |
---|

39 | |
---|

40 | forall(otype T, otype E) |
---|

41 | void ?{}(result(T, E) & this, zero_t, E error); |
---|

42 | |
---|

43 | forall(otype T, otype E) |
---|

44 | void ?{}(result(T, E) & this, result(T, E) other); |
---|

45 | |
---|

46 | forall(otype T, otype E) |
---|

47 | void ^?{}(result(T, E) & this); |
---|

48 | |
---|

49 | forall(otype T, otype E) |
---|

50 | result(T, E) ?=?(result(T, E) & this, result(T, E) other); |
---|

51 | |
---|

52 | forall(otype T, otype E) |
---|

53 | bool ?!=?(result(T, E) this, zero_t); |
---|

54 | |
---|

55 | /* Wating for bug#11 to be fixed. |
---|

56 | forall(otype T, otype E) |
---|

57 | result(T, E) result_value(T value); |
---|

58 | |
---|

59 | forall(otype T, otype E) |
---|

60 | result(T, E) result_error(E error); |
---|

61 | */ |
---|

62 | |
---|

63 | forall(otype T, otype E) |
---|

64 | bool has_value(result(T, E) * this); |
---|

65 | |
---|

66 | forall(otype T, otype E) |
---|

67 | T get(result(T, E) * this); |
---|

68 | |
---|

69 | forall(otype T, otype E) |
---|

70 | E get_error(result(T, E) * this); |
---|

71 | |
---|

72 | forall(otype T, otype E) |
---|

73 | void set(result(T, E) * this, T value); |
---|

74 | |
---|

75 | forall(otype T, otype E) |
---|

76 | void set_error(result(T, E) * this, E error); |
---|

77 | |
---|

78 | // Local Variables: // |
---|

79 | // mode: c // |
---|

80 | // tab-width: 4 // |
---|

81 | // End: // |
---|