/
class_OvoviviparousBeing.erl
70 lines (43 loc) · 1.99 KB
/
class_OvoviviparousBeing.erl
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
% Copyright (C) 2003-2019 Olivier Boudeville
%
% This file is part of the Ceylan-WOOPER examples.
%
% It has been placed in the public domain.
%
% Author: Olivier Boudeville [olivier (dot) boudeville (at) esperide (dot) com]
-module(class_OvoviviparousBeing).
% Determines what are the mother classes of this class (if any):
-define( superclasses, [] ).
-define( class_attributes, [ { eggs_count, "A number of eggs" } ] ).
% Allows to define WOOPER base variables and methods for that class:
-include("wooper.hrl").
% Import common types without module prefix:
-include("ecosystem_types.hrl").
% Constructs a new Ovoviviparous being (parameter-less constructor).
-spec construct( wooper:state() ) -> wooper:state() .
construct( State ) ->
% In order to test the crash of a constructor: non_existing:crash(),
setAttribute( State, eggs_count, 0 ).
% This useless destructor overriding was made to silence Dialyzer (which is not
% able to determine that this function will never be called, as WOOPER performs
% the appropriate test is made beforehand):
%
-spec destruct( wooper:state() ) -> wooper:state().
destruct( State ) ->
% In order to test the crash of a destructor: non_existing:crash(),
State.
% Method implementations.
% Let's say an average means something here:
% (this ought to be a static method, as it does not depend on a state)
-spec getMeanEggsCount( wooper:state() ) -> const_request_return( egg_count() ).
getMeanEggsCount( State ) ->
wooper:const_return_result( 1000 ).
% Returns the number of eggs this ovoviviparous laid:
-spec getEggsLaidCount( wooper:state() ) -> const_request_return( egg_count() ).
getEggsLaidCount( State ) ->
wooper:const_return_result( ?getAttr(eggs_count) ).
% Increases the number of eggs that this ovoviviparous being laid:
-spec layEggs( wooper:state(), egg_count() ) -> oneway_return().
layEggs( State, NumberOfNewEggs ) ->
NewEggCount = ?getAttr(eggs_count) + NumberOfNewEggs,
wooper:return_state( setAttribute( State, eggs_count, NewEggCount ) ).