1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2013 Alexis Laferrière <alexis.laf@xymus.net>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Module wrapping the C++ class vector<int>
18 module test_ffi_cpp_callbacks
26 # Nit class over C++'s vector<int>
27 extern class CppVector in "C++" `{vector<int>*`}
31 return new vector
<int
>();
34 # Adds an element to the end of the vector
35 fun push(v: Int) in "C++" `{
39 # Pops an element from the end of the vector
40 fun pop: Int in "C++" `{
41 long val
= self-
>back
();
46 fun safe_pop_with_default(default_return: Int): Int import report_error in "C++" `{
48 CppVector_report_error(self);
49 return default_return
;
51 long val
= self-
>back
();
57 private fun report_error do print "Vector is empty!"
68 print a.safe_pop_with_default(1234)
69 print a.safe_pop_with_default(1234)
70 print a.safe_pop_with_default(1234)
71 print a.safe_pop_with_default(1234)