File: ExceptionTest_Fib_Impl.cc

package info (click to toggle)
babel 0.10.2-1
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 43,932 kB
  • ctags: 29,707
  • sloc: java: 74,695; ansic: 73,142; cpp: 40,649; sh: 18,411; f90: 10,062; fortran: 6,727; python: 6,406; makefile: 3,866; xml: 118; perl: 48
file content (142 lines) | stat: -rw-r--r-- 4,529 bytes parent folder | download
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// 
// File:          ExceptionTest_Fib_Impl.cc
// Symbol:        ExceptionTest.Fib-v1.0
// Symbol Type:   class
// Babel Version: 0.10.2
// Description:   Server-side implementation for ExceptionTest.Fib
// 
// WARNING: Automatically generated; only changes within splicers preserved
// 
// babel-version = 0.10.2
// 
#include "ExceptionTest_Fib_Impl.hh"

#line 14 "../../../../babel/regression/exceptions/libCxx/ExceptionTest_Fib_Impl.cc"
// DO-NOT-DELETE splicer.begin(ExceptionTest.Fib._includes)
#include "ExceptionTest_NegativeValueException.hh"
#include "ExceptionTest_TooDeepException.hh"
#include "ExceptionTest_TooBigException.hh"
// DO-NOT-DELETE splicer.end(ExceptionTest.Fib._includes)
#line 20 "ExceptionTest_Fib_Impl.cc"

// user-defined constructor.
void ExceptionTest::Fib_impl::_ctor() {
#line 22 "../../../../babel/regression/exceptions/libCxx/ExceptionTest_Fib_Impl.cc"
  // DO-NOT-DELETE splicer.begin(ExceptionTest.Fib._ctor)
  // add construction details here
  // DO-NOT-DELETE splicer.end(ExceptionTest.Fib._ctor)
#line 28 "ExceptionTest_Fib_Impl.cc"
}

// user-defined destructor.
void ExceptionTest::Fib_impl::_dtor() {
#line 29 "../../../../babel/regression/exceptions/libCxx/ExceptionTest_Fib_Impl.cc"
  // DO-NOT-DELETE splicer.begin(ExceptionTest.Fib._dtor)
  // add destruction details here
  // DO-NOT-DELETE splicer.end(ExceptionTest.Fib._dtor)
#line 37 "ExceptionTest_Fib_Impl.cc"
}

// static class initializer.
void ExceptionTest::Fib_impl::_load() {
#line 36 "../../../../babel/regression/exceptions/libCxx/ExceptionTest_Fib_Impl.cc"
  // DO-NOT-DELETE splicer.begin(ExceptionTest.Fib._load)
  // guaranteed to be called at most once before any other method in this class
  // DO-NOT-DELETE splicer.end(ExceptionTest.Fib._load)
#line 46 "ExceptionTest_Fib_Impl.cc"
}

// user-defined static methods: (none)

// user-defined non-static methods:
/**
 * <p>
 * Generate the requested Fibonacci number or generate exceptions if
 * the input Fibonacci number is invalid or if any of the maximum depth
 * or maximum value parameters are exceeded.  The last argument of the
 * method should be zero.
 * </p>
 * <p>
 * The algorithm should be similar to the <code>Java</code> code below.
 * </p>
 * <pre>
 * public int getFib(int n, int max_depth, int max_value, int depth)
 *     throws NegativeValueException, FibException {
 * 
 *   if (n < 0) {
 *     throw new NegativeValueException("n negative");
 * 
 *   } else if (depth > max_depth) {
 *     throw new TooDeepException("too deep");
 * 
 *   } else if (n == 0) {
 *     return 1;
 * 
 *   } else if (n == 1) {
 *     return 1;
 * 
 *   } else {
 *     int a = getFib(n-1, max_depth, max_value, depth+1);
 *     int b = getFib(n-2, max_depth, max_value, depth+1);
 *     if (a + b > max_value) {
 *       throw new TooBigException("too big");
 *     }
 *     return a + b;
 *   }
 * } 
 * </pre>
 */
int32_t
ExceptionTest::Fib_impl::getFib (
  /* in */ int32_t n,
  /* in */ int32_t max_depth,
  /* in */ int32_t max_value,
  /* in */ int32_t depth ) 
throw ( 
  ::ExceptionTest::NegativeValueException, 
  ::ExceptionTest::FibException
){
#line 91 "../../../../babel/regression/exceptions/libCxx/ExceptionTest_Fib_Impl.cc"
  // DO-NOT-DELETE splicer.begin(ExceptionTest.Fib.getFib)
  if (n < 0) {
    NegativeValueException ex = NegativeValueException::_create();
    ex.setNote("n negative");
    ex.add(__FILE__, __LINE__, "ExceptionTest::Fib_impl::getFib");
    throw ex;

  } else if (depth > max_depth) {
    TooDeepException ex = TooDeepException::_create();
    ex.setNote("too deep");
    ex.add(__FILE__, __LINE__, "ExceptionTest::Fib_impl::getFib");
    FibException ex2 = ex;
    throw ex2;

  } else if (n == 0) {
    return 1;

  } else if (n == 1) {
    return 1;

  } else {
    int32_t a = self.getFib(n-1, max_depth, max_value, depth+1);
    int32_t b = self.getFib(n-2, max_depth, max_value, depth+1);
    if (a + b > max_value) {
      TooBigException ex = TooBigException::_create();
      ex.setNote("too big");
      ex.add(__FILE__, __LINE__, "ExceptionTest::Fib_impl::getFib");
      FibException ex2 = ex;
      throw ex2;
    }
    return a + b;
  }
  // DO-NOT-DELETE splicer.end(ExceptionTest.Fib.getFib)
#line 133 "ExceptionTest_Fib_Impl.cc"
}


#line 127 "../../../../babel/regression/exceptions/libCxx/ExceptionTest_Fib_Impl.cc"
// DO-NOT-DELETE splicer.begin(ExceptionTest.Fib._misc)
// Put miscellaneous code here
// DO-NOT-DELETE splicer.end(ExceptionTest.Fib._misc)
#line 141 "ExceptionTest_Fib_Impl.cc"