mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-09-12 08:10:07 +00:00
* ob-C.el: handling of non-homogeneous tables, support for table header, support for iterating over table cells. (org-babel-expand-body:C++): uncomment (org-babel-C-execute): cosmetic changes (org-babel-C-expand-C): add support for table columns names, add support for table dimensions, add standard includes (org-babel-C-val-to-C-type): rewrite to support non-homogeneous tables cells (org-babel-C-table-sizes-to-C): new function to gain access to the table dimensions (org-babel-C-utility-header-to-C): (org-babel-C-header-to-C): new functions to generate support for table header. * ob-C-test.org: added D sibling tests similar to C++, added non-homogeneous table example for C++ and D * test-ob-C.el: new tests for D and non-homogeneous tables (ob-C/simple-program): (ob-C/simple-program): (ob-D/simple-program): (ob-C/integer-var): (ob-D/integer-var): (ob-C/two-integer-var): (ob-D/two-integer-var): (ob-C/string-var): (ob-D/string-var): (ob-C/preprocessor): (ob-C/table): (ob-D/table): (ob-C/list-var): (ob-D/list-var): (ob-C/vector-var): (ob-D/vector-var): (ob-C/list-list-var): (ob-D/list-list-var): (ob-C/inhomogeneous_table): (ob-D/inhomogeneous_table): add compiler availability check (ob-D/simple-program): (ob-D/integer-var): (ob-D/two-integer-var): (ob-D/string-var): (ob-D/table): (ob-D/list-var): (ob-D/vector-var): (ob-D/list-list-var): (ob-D/inhomogeneous_table): add D unit tests (ob-C/inhomogeneous_table): (ob-D/inhomogeneous_table): add non-homogeneous table unit tests
159 lines
3.6 KiB
Org Mode
159 lines
3.6 KiB
Org Mode
#+Title: a collection of examples for ob-C tests
|
|
#+OPTIONS: ^:nil
|
|
* Simple tests
|
|
:PROPERTIES:
|
|
:ID: fa6db330-e960-4ea2-ac67-94bb845b8577
|
|
:END:
|
|
#+source: simple
|
|
#+begin_src cpp :includes "<iostream>" :results silent
|
|
std::cout << 42;
|
|
return 0;
|
|
#+end_src
|
|
|
|
#+source: simple
|
|
#+begin_src D :results silent
|
|
writefln ("%s", 42);
|
|
#+end_src
|
|
|
|
#+source: integer_var
|
|
#+begin_src cpp :var q=12 :includes "<iostream>" :results silent
|
|
std::cout << q;
|
|
return 0;
|
|
#+end_src
|
|
|
|
#+source: integer_var
|
|
#+begin_src D :var q=12 :results silent
|
|
writefln ("%s", q);
|
|
#+end_src
|
|
|
|
#+source: two_var
|
|
#+begin_src cpp :var q=12 :var p=10 :includes "<iostream>" :results silent
|
|
std::cout << p+q;
|
|
return 0;
|
|
#+end_src
|
|
|
|
#+source: two_var
|
|
#+begin_src D :var q=12 :var p=10 :results silent
|
|
writefln ("%s", p+q);
|
|
#+end_src
|
|
|
|
#+source: string_var
|
|
#+begin_src cpp :var q="word" :includes '(<iostream> <cstring>) :results silent
|
|
std::cout << q << ' ' << std::strlen(q);
|
|
return 0;
|
|
#+end_src
|
|
|
|
#+source: string_var
|
|
#+begin_src D :var q="word" :results silent
|
|
writefln ("%s %s", q, q.length);
|
|
#+end_src
|
|
|
|
#+source: define
|
|
#+begin_src cpp :defines N 42 :includes "<iostream>" :results silent
|
|
std::cout << N;
|
|
return 0;
|
|
#+end_src
|
|
|
|
* Array
|
|
:PROPERTIES:
|
|
:ID: 2df1ab83-3fa3-462a-a1f3-3aef6044a874
|
|
:END:
|
|
#+source: array
|
|
#+begin_src cpp :includes "<iostream>" :results vector :results silent
|
|
for (int i=1; i<3; i++) {
|
|
std::cout << i << '\n';
|
|
}
|
|
return 0;
|
|
#+end_src
|
|
|
|
#+source: array
|
|
#+begin_src D :results vector :results silent
|
|
foreach (i; 1..3)
|
|
writefln ("%s", i);
|
|
#+end_src
|
|
|
|
* Matrix
|
|
:PROPERTIES:
|
|
:ID: cc65d6b3-8e8e-4f9c-94cd-f5a00cdeceb5
|
|
:END:
|
|
#+name: C-matrix
|
|
| 1 | 2 |
|
|
| 3 | 4 |
|
|
|
|
#+source: list_var
|
|
#+begin_src cpp :var a='("abc" "def") :includes "<iostream>" :results silent
|
|
std::cout << a[0] << a[1] << sizeof(a)/sizeof(*a) << '\n';
|
|
#+end_src
|
|
|
|
#+source: list_var
|
|
#+begin_src D :var a='("abc" "def") :results silent
|
|
writefln ("%s%s%s", a[0], a[1], a.length);
|
|
#+end_src
|
|
|
|
#+source: vector_var
|
|
#+begin_src cpp :var a='[1 2] :includes "<iostream>" :results silent
|
|
std::cout << a[0] << a[1] << sizeof(a)/sizeof(*a) << '\n';
|
|
#+end_src
|
|
|
|
#+source: vector_var
|
|
#+begin_src D :var a='[1 2] :results silent
|
|
writefln ("%s%s%s", a[0], a[1], a.length);
|
|
#+end_src
|
|
|
|
#+source: list_list_var
|
|
#+begin_src cpp :var q=C-matrix :includes "<iostream>" :results silent
|
|
std::cout << q[0][0] << ' ' << q[1][0] << '\n'
|
|
<< q[0][1] << ' ' << q[1][1] << '\n'; // transpose
|
|
#+end_src
|
|
|
|
#+source: list_list_var
|
|
#+begin_src D :var q=C-matrix :results silent
|
|
writefln ("%s %s", q[0][0], q[1][0]);
|
|
writefln ("%s %s", q[0][1], q[1][1]); // transpose
|
|
#+end_src
|
|
|
|
* Inhomogeneous table
|
|
:PROPERTIES:
|
|
:ID: e112bc2e-419a-4890-99c2-7ac4779531cc
|
|
:END:
|
|
|
|
#+tblname: tinomogen
|
|
| day | quty |
|
|
|-----------+------|
|
|
| monday | 34 |
|
|
| tuesday | 41 |
|
|
| wednesday | 56 |
|
|
| thursday | 17 |
|
|
| friday | 12 |
|
|
| saturday | 7 |
|
|
| sunday | 4 |
|
|
|
|
#+source: inhomogeneous_table
|
|
#+begin_src cpp :var tinomogen=tinomogen :results silent
|
|
int main()
|
|
{
|
|
int i, j;
|
|
for (i=0; i<tinomogen_rows; i++) {
|
|
for (j=0; j<tinomogen_cols; j++)
|
|
printf ("%s ", tinomogen[i][j]);
|
|
printf ("\n");
|
|
}
|
|
printf ("Friday %s\n", tinomogen_h(4,"day"));
|
|
return 0;
|
|
}
|
|
#+end_src
|
|
|
|
#+source: inhomogeneous_table
|
|
#+begin_src D :var tinomogen=tinomogen :results silent
|
|
import std.stdio;
|
|
void main()
|
|
{
|
|
for (int i=0; i<tinomogen_rows; i++) {
|
|
for (int j=0; j<tinomogen_cols; j++)
|
|
writef ("%s ", tinomogen[i][j]);
|
|
writeln();
|
|
}
|
|
writefln ("Friday %s\n", tinomogen_h(4,"day"));
|
|
}
|
|
#+end_src
|