File: Add.cpp

package info (click to toggle)
aleph 0.9.0-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,460 kB
  • ctags: 5,520
  • sloc: cpp: 30,907; makefile: 1,973; sh: 506; lisp: 193
file content (42 lines) | stat: -rw-r--r-- 1,789 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
// ---------------------------------------------------------------------------
// - Add.cpp                                                                 -
// - aleph api example - add function example                                -
// ---------------------------------------------------------------------------
// - This program is free software;  you can redistribute it  and/or  modify -
// - it provided that this copyright notice is kept intact.                  -
// -                                                                         -
// - This program  is  distributed in  the hope  that it will be useful, but -
// - without  any  warranty;  without  even   the   implied    warranty   of -
// - merchantability or fitness for a particular purpose.  In no event shall -
// - the copyright holder be liable for any  direct, indirect, incidental or -
// - special damages arising in any way out of the use of this software.     -
// ---------------------------------------------------------------------------
// - copyright (c) 1999-2003 amaury darsch                                   -
// ---------------------------------------------------------------------------

#include "Vector.hpp"
#include "Integer.hpp"
#include "Apicalls.hpp"

namespace example {
  // use the aleph namespace
  using namespace aleph;
  
  // add function implementation
  Object* api_add (Runnable* robj, Nameset* nset, Cons* args) {
    // evaluate the arguments in a vector
    Vector* argv = Vector::eval (robj, nset, args);
    try {
      // compute the result
      long result = argv->getint (0) + argv->getint (1);
      // clean the vector
      delete argv;
      // generate result
      return new Integer (result);
    } catch (...) {
      delete argv;
      throw;
    }
  }
}