commit 937f18667d16f630100f78e1730c2485c573d59a Author: Johannes Theiner Date: Fri Mar 9 09:47:53 2018 +0100 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9d512c7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +cmake-build-debug +xcode_projects \ No newline at end of file diff --git a/.idea/C_CPP.iml b/.idea/C_CPP.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/C_CPP.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..79b3c94 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..05ae881 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/01_ENV/build.sh b/01_ENV/build.sh new file mode 100644 index 0000000..eeb81d7 --- /dev/null +++ b/01_ENV/build.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +# generate main.s, main.o, b.out +pcc -O0 -S main.c +as -o main.o main.s +#ld -o b.out main.o /lib/crt0.o /lib/crti.o -lc +pcc -o b.out main.o + +# generate a.out +pcc -O0 -g main.c + +# generate assembly intermixed with source code +objdump -S a.out > objdump-S_a.out.txt + diff --git a/01_ENV/clean.sh b/01_ENV/clean.sh new file mode 100644 index 0000000..889d8f2 --- /dev/null +++ b/01_ENV/clean.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +rm *.o *.s *.out + diff --git a/01_ENV/main.c b/01_ENV/main.c new file mode 100644 index 0000000..285a15f --- /dev/null +++ b/01_ENV/main.c @@ -0,0 +1,21 @@ +#include + +int global = 8150; + + +int sum(int,int); + +int sum(int a, int b){ + int result = 451; + result = a + b; + return result; +} + + +int main(int argc, char **argv) +{ + int local=4711; + printf("Hello, world!\nglobal=%d local=%d\n", global, local); + local = sum(global, local); + return local; +} diff --git a/01_ENV/main.s b/01_ENV/main.s new file mode 100644 index 0000000..f9a1224 --- /dev/null +++ b/01_ENV/main.s @@ -0,0 +1,58 @@ + .data + .align 4 + .globl global + .type global,@object + .size global,4 +global: + .long 8150 + .text + .align 4 + .globl sum + .type sum,@function +sum: + enter $8,$0 +.L461: +.L465: + movl $451,-4(%ebp) + movl 8(%ebp),%eax + addl 12(%ebp),%eax + movl %eax,-4(%ebp) + movl -4(%ebp),%eax + movl %eax,-8(%ebp) + jmp .L463 +.L463: + movl -8(%ebp),%eax + leave + ret + .size sum,.-sum + .align 4 + .globl main + .type main,@function +main: + enter $8,$0 +.L469: +.L473: + movl $4711,-4(%ebp) + pushl -4(%ebp) + pushl global + pushl $.L475 + call printf + addl $12, %esp + pushl -4(%ebp) + pushl global + call sum + addl $8, %esp + movl %eax,-4(%ebp) + movl -4(%ebp),%eax + movl %eax,-8(%ebp) + jmp .L471 +.L471: + movl -8(%ebp),%eax + leave + ret + .size main,.-main + .section .rodata + .size .L475,34 +.L475: + .ascii "Hello, world!\012global=%d local=%d\012\0" + .ident "PCC: Portable C Compiler 1.2.0.DEVEL 20160115 for i686-pc-linux-gnu" diff --git a/01_ENV/main_plain.c b/01_ENV/main_plain.c new file mode 100644 index 0000000..b5a353f --- /dev/null +++ b/01_ENV/main_plain.c @@ -0,0 +1,19 @@ +#include + +int global = 8150; + +int sum(int a, int b){ + int result = 451; + result = a + b; + return result; +} + + +int main(int argc, char **argv) +{ + int local=4711; + printf("Hello, world!\nglobal=%d local=%d\n", global, local); + local = sum(global, local); + return local; +} + diff --git a/01_ENV/objdump-S_a.out.txt b/01_ENV/objdump-S_a.out.txt new file mode 100644 index 0000000..f8aa422 --- /dev/null +++ b/01_ENV/objdump-S_a.out.txt @@ -0,0 +1,324 @@ + +a.out: file format elf32-i386 + + +Disassembly of section .init: + +08048278 <_init>: + 8048278: 53 push %ebx + 8048279: 83 ec 08 sub $0x8,%esp + 804827c: e8 8f 00 00 00 call 8048310 <__x86.get_pc_thunk.bx> + 8048281: 81 c3 7f 1d 00 00 add $0x1d7f,%ebx + 8048287: 8b 83 fc ff ff ff mov -0x4(%ebx),%eax + 804828d: 85 c0 test %eax,%eax + 804828f: 74 05 je 8048296 <_init+0x1e> + 8048291: e8 2a 00 00 00 call 80482c0 <__gmon_start__@plt> + 8048296: e8 45 01 00 00 call 80483e0 <__do_global_ctors_aux> + 804829b: 83 c4 08 add $0x8,%esp + 804829e: 5b pop %ebx + 804829f: c3 ret + +Disassembly of section .plt: + +080482a0 : + 80482a0: ff 35 04 a0 04 08 pushl 0x804a004 + 80482a6: ff 25 08 a0 04 08 jmp *0x804a008 + 80482ac: 00 00 add %al,(%eax) + ... + +080482b0 : + 80482b0: ff 25 0c a0 04 08 jmp *0x804a00c + 80482b6: 68 00 00 00 00 push $0x0 + 80482bb: e9 e0 ff ff ff jmp 80482a0 <_init+0x28> + +080482c0 <__gmon_start__@plt>: + 80482c0: ff 25 10 a0 04 08 jmp *0x804a010 + 80482c6: 68 08 00 00 00 push $0x8 + 80482cb: e9 d0 ff ff ff jmp 80482a0 <_init+0x28> + +080482d0 <__libc_start_main@plt>: + 80482d0: ff 25 14 a0 04 08 jmp *0x804a014 + 80482d6: 68 10 00 00 00 push $0x10 + 80482db: e9 c0 ff ff ff jmp 80482a0 <_init+0x28> + +Disassembly of section .text: + +080482e0 <_start>: + 80482e0: 31 ed xor %ebp,%ebp + 80482e2: 5e pop %esi + 80482e3: 89 e1 mov %esp,%ecx + 80482e5: 83 e4 f0 and $0xfffffff0,%esp + 80482e8: 50 push %eax + 80482e9: 54 push %esp + 80482ea: 52 push %edx + 80482eb: 68 30 85 04 08 push $0x8048530 + 80482f0: 68 d0 84 04 08 push $0x80484d0 + 80482f5: 51 push %ecx + 80482f6: 56 push %esi + 80482f7: 68 8c 84 04 08 push $0x804848c + 80482fc: e8 cf ff ff ff call 80482d0 <__libc_start_main@plt> + 8048301: f4 hlt + 8048302: 66 90 xchg %ax,%ax + 8048304: 66 90 xchg %ax,%ax + 8048306: 66 90 xchg %ax,%ax + 8048308: 66 90 xchg %ax,%ax + 804830a: 66 90 xchg %ax,%ax + 804830c: 66 90 xchg %ax,%ax + 804830e: 66 90 xchg %ax,%ax + +08048310 <__x86.get_pc_thunk.bx>: + 8048310: 8b 1c 24 mov (%esp),%ebx + 8048313: c3 ret + 8048314: 66 90 xchg %ax,%ax + 8048316: 66 90 xchg %ax,%ax + 8048318: 66 90 xchg %ax,%ax + 804831a: 66 90 xchg %ax,%ax + 804831c: 66 90 xchg %ax,%ax + 804831e: 66 90 xchg %ax,%ax + +08048320 <__ctors>: + 8048320: e8 34 01 00 00 call 8048459 <__x86.get_pc_thunk.ax> + 8048325: 05 db 1c 00 00 add $0x1cdb,%eax + 804832a: 56 push %esi + 804832b: 53 push %ebx + 804832c: 8d 64 24 fc lea -0x4(%esp),%esp + 8048330: 8d 88 24 ff ff ff lea -0xdc(%eax),%ecx + 8048336: 8b 11 mov (%ecx),%edx + 8048338: 83 fa ff cmp $0xffffffff,%edx + 804833b: 74 2b je 8048368 <__ctors+0x48> + 804833d: 8d 5a ff lea -0x1(%edx),%ebx + 8048340: 8d 34 91 lea (%ecx,%edx,4),%esi + 8048343: 8d 04 9d 00 00 00 00 lea 0x0(,%ebx,4),%eax + 804834a: 29 c6 sub %eax,%esi + 804834c: 85 d2 test %edx,%edx + 804834e: 74 0a je 804835a <__ctors+0x3a> + 8048350: ff 14 9e call *(%esi,%ebx,4) + 8048353: 85 db test %ebx,%ebx + 8048355: 8d 5b ff lea -0x1(%ebx),%ebx + 8048358: 75 f6 jne 8048350 <__ctors+0x30> + 804835a: 8d 64 24 04 lea 0x4(%esp),%esp + 804835e: 5b pop %ebx + 804835f: 5e pop %esi + 8048360: c3 ret + 8048361: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi + 8048368: 8b 71 04 mov 0x4(%ecx),%esi + 804836b: 85 f6 test %esi,%esi + 804836d: 74 eb je 804835a <__ctors+0x3a> + 804836f: ba 01 00 00 00 mov $0x1,%edx + 8048374: eb 04 jmp 804837a <__ctors+0x5a> + 8048376: 66 90 xchg %ax,%ax + 8048378: 89 c2 mov %eax,%edx + 804837a: 8d 42 01 lea 0x1(%edx),%eax + 804837d: 8b 1c 81 mov (%ecx,%eax,4),%ebx + 8048380: 85 db test %ebx,%ebx + 8048382: 75 f4 jne 8048378 <__ctors+0x58> + 8048384: eb b7 jmp 804833d <__ctors+0x1d> + 8048386: 8d 76 00 lea 0x0(%esi),%esi + 8048389: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi + +08048390 <__dtors>: + 8048390: e8 c4 00 00 00 call 8048459 <__x86.get_pc_thunk.ax> + 8048395: 05 6b 1c 00 00 add $0x1c6b,%eax + 804839a: 53 push %ebx + 804839b: 8d 64 24 f8 lea -0x8(%esp),%esp + 804839f: 8d 90 2c ff ff ff lea -0xd4(%eax),%edx + 80483a5: 89 d3 mov %edx,%ebx + 80483a7: 83 c3 04 add $0x4,%ebx + 80483aa: 8b 42 04 mov 0x4(%edx),%eax + 80483ad: 85 c0 test %eax,%eax + 80483af: 74 1a je 80483cb <__dtors+0x3b> + 80483b1: eb 0d jmp 80483c0 <__dtors+0x30> + 80483b3: 90 nop + 80483b4: 90 nop + 80483b5: 90 nop + 80483b6: 90 nop + 80483b7: 90 nop + 80483b8: 90 nop + 80483b9: 90 nop + 80483ba: 90 nop + 80483bb: 90 nop + 80483bc: 90 nop + 80483bd: 90 nop + 80483be: 90 nop + 80483bf: 90 nop + 80483c0: 8d 5b 04 lea 0x4(%ebx),%ebx + 80483c3: ff d0 call *%eax + 80483c5: 8b 03 mov (%ebx),%eax + 80483c7: 85 c0 test %eax,%eax + 80483c9: 75 f5 jne 80483c0 <__dtors+0x30> + 80483cb: 8d 64 24 08 lea 0x8(%esp),%esp + 80483cf: 5b pop %ebx + 80483d0: c3 ret + 80483d1: eb 0d jmp 80483e0 <__do_global_ctors_aux> + 80483d3: 90 nop + 80483d4: 90 nop + 80483d5: 90 nop + 80483d6: 90 nop + 80483d7: 90 nop + 80483d8: 90 nop + 80483d9: 90 nop + 80483da: 90 nop + 80483db: 90 nop + 80483dc: 90 nop + 80483dd: 90 nop + 80483de: 90 nop + 80483df: 90 nop + +080483e0 <__do_global_ctors_aux>: + 80483e0: e8 74 00 00 00 call 8048459 <__x86.get_pc_thunk.ax> + 80483e5: 05 1b 1c 00 00 add $0x1c1b,%eax + 80483ea: 8b 90 24 00 00 00 mov 0x24(%eax),%edx + 80483f0: 85 d2 test %edx,%edx + 80483f2: 74 04 je 80483f8 <__do_global_ctors_aux+0x18> + 80483f4: c3 ret + 80483f5: 8d 76 00 lea 0x0(%esi),%esi + 80483f8: c7 80 24 00 00 00 01 movl $0x1,0x24(%eax) + 80483ff: 00 00 00 + 8048402: e9 19 ff ff ff jmp 8048320 <__ctors> + 8048407: 89 f6 mov %esi,%esi + 8048409: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi + +08048410 <__do_global_dtors_aux>: + 8048410: 53 push %ebx + 8048411: e8 fa fe ff ff call 8048310 <__x86.get_pc_thunk.bx> + 8048416: 81 c3 ea 1b 00 00 add $0x1bea,%ebx + 804841c: 8d 64 24 f8 lea -0x8(%esp),%esp + 8048420: 8b 83 20 00 00 00 mov 0x20(%ebx),%eax + 8048426: 85 c0 test %eax,%eax + 8048428: 75 0f jne 8048439 <__do_global_dtors_aux+0x29> + 804842a: e8 61 ff ff ff call 8048390 <__dtors> + 804842f: c7 83 20 00 00 00 01 movl $0x1,0x20(%ebx) + 8048436: 00 00 00 + 8048439: 8d 64 24 08 lea 0x8(%esp),%esp + 804843d: 5b pop %ebx + 804843e: c3 ret + 804843f: 90 nop + +08048440 <__call___do_global_ctors_aux>: + 8048440: 8d 64 24 f4 lea -0xc(%esp),%esp + 8048444: 8d 64 24 0c lea 0xc(%esp),%esp + 8048448: c3 ret + 8048449: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi + +08048450 <__call___do_global_dtors_aux>: + 8048450: 8d 64 24 f4 lea -0xc(%esp),%esp + 8048454: 8d 64 24 0c lea 0xc(%esp),%esp + 8048458: c3 ret + +08048459 <__x86.get_pc_thunk.ax>: + 8048459: 90 nop + 804845a: 90 nop + 804845b: 90 nop + 804845c: 90 nop + 804845d: 90 nop + 804845e: 90 nop + 804845f: 90 nop + 8048460: 90 nop + 8048461: 8b 04 24 mov (%esp),%eax + 8048464: c3 ret + 8048465: 66 90 xchg %ax,%ax + 8048467: 90 nop + +08048468 : +int global = 8150; + + +int sum(int,int); + +int sum(int a, int b){ + 8048468: c8 08 00 00 enter $0x8,$0x0 + int result = 451; + 804846c: c7 45 fc c3 01 00 00 movl $0x1c3,-0x4(%ebp) + result = a + b; + 8048473: 8b 45 08 mov 0x8(%ebp),%eax + 8048476: 03 45 0c add 0xc(%ebp),%eax + 8048479: 89 45 fc mov %eax,-0x4(%ebp) + return result; + 804847c: 8b 45 fc mov -0x4(%ebp),%eax + 804847f: 89 45 f8 mov %eax,-0x8(%ebp) + 8048482: eb 00 jmp 8048484 +} + 8048484: 8b 45 f8 mov -0x8(%ebp),%eax + 8048487: c9 leave + 8048488: c3 ret + 8048489: 8d 76 00 lea 0x0(%esi),%esi + +0804848c
: + + +int main(int argc, char **argv) +{ + 804848c: c8 08 00 00 enter $0x8,$0x0 + int local=4711; + 8048490: c7 45 fc 67 12 00 00 movl $0x1267,-0x4(%ebp) + printf("Hello, world!\nglobal=%d local=%d\n", global, local); + 8048497: ff 75 fc pushl -0x4(%ebp) + 804849a: ff 35 1c a0 04 08 pushl 0x804a01c + 80484a0: 68 58 85 04 08 push $0x8048558 + 80484a5: e8 06 fe ff ff call 80482b0 + 80484aa: 83 c4 0c add $0xc,%esp + local = sum(global, local); + 80484ad: ff 75 fc pushl -0x4(%ebp) + 80484b0: ff 35 1c a0 04 08 pushl 0x804a01c + 80484b6: e8 ad ff ff ff call 8048468 + 80484bb: 83 c4 08 add $0x8,%esp + 80484be: 89 45 fc mov %eax,-0x4(%ebp) + return local; + 80484c1: 8b 45 fc mov -0x4(%ebp),%eax + 80484c4: 89 45 f8 mov %eax,-0x8(%ebp) + 80484c7: eb 00 jmp 80484c9 +} + 80484c9: 8b 45 f8 mov -0x8(%ebp),%eax + 80484cc: c9 leave + 80484cd: c3 ret + 80484ce: 66 90 xchg %ax,%ax + +080484d0 <__libc_csu_init>: + 80484d0: 55 push %ebp + 80484d1: 57 push %edi + 80484d2: 56 push %esi + 80484d3: 53 push %ebx + 80484d4: e8 37 fe ff ff call 8048310 <__x86.get_pc_thunk.bx> + 80484d9: 81 c3 27 1b 00 00 add $0x1b27,%ebx + 80484df: 83 ec 0c sub $0xc,%esp + 80484e2: 8b 6c 24 20 mov 0x20(%esp),%ebp + 80484e6: 8d b3 24 ff ff ff lea -0xdc(%ebx),%esi + 80484ec: e8 87 fd ff ff call 8048278 <_init> + 80484f1: 8d 83 24 ff ff ff lea -0xdc(%ebx),%eax + 80484f7: 29 c6 sub %eax,%esi + 80484f9: c1 fe 02 sar $0x2,%esi + 80484fc: 85 f6 test %esi,%esi + 80484fe: 74 25 je 8048525 <__libc_csu_init+0x55> + 8048500: 31 ff xor %edi,%edi + 8048502: 8d b6 00 00 00 00 lea 0x0(%esi),%esi + 8048508: 83 ec 04 sub $0x4,%esp + 804850b: ff 74 24 2c pushl 0x2c(%esp) + 804850f: ff 74 24 2c pushl 0x2c(%esp) + 8048513: 55 push %ebp + 8048514: ff 94 bb 24 ff ff ff call *-0xdc(%ebx,%edi,4) + 804851b: 83 c7 01 add $0x1,%edi + 804851e: 83 c4 10 add $0x10,%esp + 8048521: 39 f7 cmp %esi,%edi + 8048523: 75 e3 jne 8048508 <__libc_csu_init+0x38> + 8048525: 83 c4 0c add $0xc,%esp + 8048528: 5b pop %ebx + 8048529: 5e pop %esi + 804852a: 5f pop %edi + 804852b: 5d pop %ebp + 804852c: c3 ret + 804852d: 8d 76 00 lea 0x0(%esi),%esi + +08048530 <__libc_csu_fini>: + 8048530: f3 c3 repz ret + +Disassembly of section .fini: + +08048534 <_fini>: + 8048534: 53 push %ebx + 8048535: 83 ec 08 sub $0x8,%esp + 8048538: e8 d3 fd ff ff call 8048310 <__x86.get_pc_thunk.bx> + 804853d: 81 c3 c3 1a 00 00 add $0x1ac3,%ebx + 8048543: e8 c8 fe ff ff call 8048410 <__do_global_dtors_aux> + 8048548: 83 c4 08 add $0x8,%esp + 804854b: 5b pop %ebx + 804854c: c3 ret diff --git a/02_MENT/build.sh b/02_MENT/build.sh new file mode 100644 index 0000000..04a14d3 --- /dev/null +++ b/02_MENT/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash +clang++ -std=c++14 -I../helpers/ -o limits.out limits_println.cpp +clang++ -std=c++14 -I../helpers/ -o println.out printlnDemo.cpp diff --git a/02_MENT/limits.cpp b/02_MENT/limits.cpp new file mode 100644 index 0000000..45c47aa --- /dev/null +++ b/02_MENT/limits.cpp @@ -0,0 +1,20 @@ +#include +#include + +int main() +{ + std::cout << "type\tsizeof\tlowest\t\thighest\n"; + std::cout << "float\t" << sizeof(float) << '\t' + << std::numeric_limits::lowest() << '\t' + << std::numeric_limits::max() << '\n'; + std::cout << "double\t" << sizeof(double) << '\t' + << std::numeric_limits::lowest() << '\t' + << std::numeric_limits::max() << '\n'; + std::cout << "int\t" << sizeof(int) << '\t' + << std::numeric_limits::lowest() << '\t' + << std::numeric_limits::max() << '\n'; + std::cout << "long\t" << sizeof(long) << '\t' + << std::numeric_limits::lowest() << '\t' + << std::numeric_limits::max() << '\n'; +} + diff --git a/02_MENT/limits_println.cpp b/02_MENT/limits_println.cpp new file mode 100644 index 0000000..732d923 --- /dev/null +++ b/02_MENT/limits_println.cpp @@ -0,0 +1,21 @@ +#include "println.hpp" +#include + +int main() +{ + println("type\t sizeof\t\t lowest\t\t\t\t highest\n"); + println("float \t ",sizeof(float), "\t\t\t", + std::numeric_limits::lowest(), "\t\t", + std::numeric_limits::max()); + println("double\t ",sizeof(double), "\t\t\t", + std::numeric_limits::lowest(), "\t\t", + std::numeric_limits::max()); + println("int \t ",sizeof(int), "\t\t\t", + std::numeric_limits::lowest(), "\t\t\t", + std::numeric_limits::max()); + println("long \t ",sizeof(long), " \t\t", + std::numeric_limits::lowest(), '\t', + std::numeric_limits::max()); + + } + diff --git a/02_MENT/main_02_MENT.cpp b/02_MENT/main_02_MENT.cpp new file mode 100644 index 0000000..caa166f --- /dev/null +++ b/02_MENT/main_02_MENT.cpp @@ -0,0 +1,31 @@ +// file: main_02_MENT.cpp +// THIS IS C++, use clang++ + +#include "../helpers/println.hpp" +#include + +struct PascalString{ + int length; // number of chars used + char characters[256]; // chars of some character string +}; + +int hexDigitToInt(char hexDigit){ +int value = -1; +// TBD +return value; +} + +int hexStringToInt(PascalString binaryDigits){ +int returnValue = -1; + +return returnValue; +} + +int main(int argc, char** argv, char** envp){ + PascalString s = {3, '1', '0', '0'}; + PascalString s2 = {4, 'f', 'f', 'f', 'f'}; + println(hexStringToInt(s)); + println(hexStringToInt(s2)); + return 0; +} + diff --git a/02_MENT/printlnDemo.cpp b/02_MENT/printlnDemo.cpp new file mode 100644 index 0000000..66d1dc7 --- /dev/null +++ b/02_MENT/printlnDemo.cpp @@ -0,0 +1,17 @@ +#include "println.hpp" + + +int main() +{ + println("this program shows how to use println()"); + int i=1; + println(i); // type int + double d=2.78; + println(d); // type double + println(""); // just an empty line: + println("i=", i, " d=", d);// more than one + print("i=", i); // print all with separate statements + print(" d=", d); // no "ln" -> no newline + println(""); +} + diff --git a/02_MENT/typedMemory/typedMemory.xcodeproj/project.pbxproj b/02_MENT/typedMemory/typedMemory.xcodeproj/project.pbxproj new file mode 100644 index 0000000..814f6de --- /dev/null +++ b/02_MENT/typedMemory/typedMemory.xcodeproj/project.pbxproj @@ -0,0 +1,259 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 654370B41E9788E30085F153 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 654370B31E9788E30085F153 /* main.cpp */; }; + 654371471E9ED16D0085F153 /* typedMemory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 654371451E9ED16D0085F153 /* typedMemory.cpp */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 654370AE1E9788E30085F153 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 654370B01E9788E30085F153 /* typedMemory */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = typedMemory; sourceTree = BUILT_PRODUCTS_DIR; }; + 654370B31E9788E30085F153 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; + 654371451E9ED16D0085F153 /* typedMemory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = typedMemory.cpp; sourceTree = ""; }; + 654371461E9ED16D0085F153 /* typedMemory.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = typedMemory.hpp; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 654370AD1E9788E30085F153 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 654370A71E9788E30085F153 = { + isa = PBXGroup; + children = ( + 654370B21E9788E30085F153 /* typedMemory */, + 654370B11E9788E30085F153 /* Products */, + ); + sourceTree = ""; + }; + 654370B11E9788E30085F153 /* Products */ = { + isa = PBXGroup; + children = ( + 654370B01E9788E30085F153 /* typedMemory */, + ); + name = Products; + sourceTree = ""; + }; + 654370B21E9788E30085F153 /* typedMemory */ = { + isa = PBXGroup; + children = ( + 654370B31E9788E30085F153 /* main.cpp */, + 654371451E9ED16D0085F153 /* typedMemory.cpp */, + 654371461E9ED16D0085F153 /* typedMemory.hpp */, + ); + path = typedMemory; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 654370AF1E9788E30085F153 /* typedMemory */ = { + isa = PBXNativeTarget; + buildConfigurationList = 654370B71E9788E30085F153 /* Build configuration list for PBXNativeTarget "typedMemory" */; + buildPhases = ( + 654370AC1E9788E30085F153 /* Sources */, + 654370AD1E9788E30085F153 /* Frameworks */, + 654370AE1E9788E30085F153 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = typedMemory; + productName = typedMemory; + productReference = 654370B01E9788E30085F153 /* typedMemory */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 654370A81E9788E30085F153 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0820; + ORGANIZATIONNAME = HSEL; + TargetAttributes = { + 654370AF1E9788E30085F153 = { + CreatedOnToolsVersion = 8.2.1; + ProvisioningStyle = Automatic; + }; + }; + }; + buildConfigurationList = 654370AB1E9788E30085F153 /* Build configuration list for PBXProject "typedMemory" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 654370A71E9788E30085F153; + productRefGroup = 654370B11E9788E30085F153 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 654370AF1E9788E30085F153 /* typedMemory */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 654370AC1E9788E30085F153 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 654370B41E9788E30085F153 /* main.cpp in Sources */, + 654371471E9ED16D0085F153 /* typedMemory.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 654370B51E9788E30085F153 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + }; + name = Debug; + }; + 654370B61E9788E30085F153 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + }; + name = Release; + }; + 654370B81E9788E30085F153 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 654370B91E9788E30085F153 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 654370AB1E9788E30085F153 /* Build configuration list for PBXProject "typedMemory" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 654370B51E9788E30085F153 /* Debug */, + 654370B61E9788E30085F153 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 654370B71E9788E30085F153 /* Build configuration list for PBXNativeTarget "typedMemory" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 654370B81E9788E30085F153 /* Debug */, + 654370B91E9788E30085F153 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; +/* End XCConfigurationList section */ + }; + rootObject = 654370A81E9788E30085F153 /* Project object */; +} diff --git a/02_MENT/typedMemory/typedMemory.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/02_MENT/typedMemory/typedMemory.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..536168f --- /dev/null +++ b/02_MENT/typedMemory/typedMemory.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/02_MENT/typedMemory/typedMemory.xcodeproj/project.xcworkspace/xcuserdata/clink.xcuserdatad/UserInterfaceState.xcuserstate b/02_MENT/typedMemory/typedMemory.xcodeproj/project.xcworkspace/xcuserdata/clink.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..781d911 Binary files /dev/null and b/02_MENT/typedMemory/typedMemory.xcodeproj/project.xcworkspace/xcuserdata/clink.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/02_MENT/typedMemory/typedMemory.xcodeproj/xcuserdata/clink.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/02_MENT/typedMemory/typedMemory.xcodeproj/xcuserdata/clink.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..fe2b454 --- /dev/null +++ b/02_MENT/typedMemory/typedMemory.xcodeproj/xcuserdata/clink.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,5 @@ + + + diff --git a/02_MENT/typedMemory/typedMemory.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/typedMemory.xcscheme b/02_MENT/typedMemory/typedMemory.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/typedMemory.xcscheme new file mode 100644 index 0000000..8ad5a88 --- /dev/null +++ b/02_MENT/typedMemory/typedMemory.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/typedMemory.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/02_MENT/typedMemory/typedMemory.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/xcschememanagement.plist b/02_MENT/typedMemory/typedMemory.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..25d6d3f --- /dev/null +++ b/02_MENT/typedMemory/typedMemory.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + typedMemory.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 654370AF1E9788E30085F153 + + primary + + + + + diff --git a/02_MENT/typedMemory/typedMemory/main.cpp b/02_MENT/typedMemory/typedMemory/main.cpp new file mode 100644 index 0000000..1972ae4 --- /dev/null +++ b/02_MENT/typedMemory/typedMemory/main.cpp @@ -0,0 +1,73 @@ +// main.cpp +// typedMemory + +#include +#include +#include "typedMemory.hpp" + + + + +struct compund { + int theInt; + double theDouble; +}; + + +/* this illustrates that what the compiler needs to do + to store local variables in the stack frame. Compare + this to the code in main().*/ +/*void foobar(){ + unsigned int x = 0x04030201; + char c1 = 'C'; + char c2 = '+'; + char c3 = '+'; + char c4 = '!'; + double d1 = 16.0; + compund k1 = {0x04030201, 16.0}; + compund k2 = {0, 0.0}; +}*/ + + +int main(int argc, const char * argv[]) { + TypedMemory mem; + + mem.putUInt(0, 0x04030201); + mem.putChar(4,'C'); + mem.putChar(5,'+'); + mem.putChar(6,'+'); + mem.putChar(7,'!'); + mem.putDouble(0x30, 16.0 /*355.0/113.0*/); + + std::cout << std::setbase(16); + std::cout << "0x" << mem.getUInt(0) << std::endl; + std::cout << mem.getChar(4) + << mem.getChar(5) + << mem.getChar(6) + << mem.getChar(7) << std::endl; + std::cout << "0x" << mem.getUInt(4) << std::endl; + std::cout << mem.getDouble(0x30) << " (" << sizeof(double) << " bytes)" << std::endl; + + compund a = {0x04030201, 16.0}; + compund b = {0, 0.0}; + mem.putAnything(16, &a, sizeof(compund)); + mem.getAnything(16, &b, sizeof(compund)); + std::cout << "a = (0x" << a.theInt << ", " << a.theDouble << ")" << std::endl; + std::cout << "b = (0x" << b.theInt << ", " << b.theDouble << ")" << std::endl; + std::cout << std::setbase(10); + + std::cout << mem.hexDump() << std::endl; + + return 0; +} + + + + + + + + + + + diff --git a/02_MENT/typedMemory/typedMemory/typedMemory.cpp b/02_MENT/typedMemory/typedMemory/typedMemory.cpp new file mode 100644 index 0000000..ab70999 --- /dev/null +++ b/02_MENT/typedMemory/typedMemory/typedMemory.cpp @@ -0,0 +1,104 @@ +// typedMemory.cpp + +#include "typedMemory.hpp" +#include +#include + + +void TypedMemory::putChar(int position, unsigned char c) +{ + rawMemory[position] = reinterpret_cast(c); +} + +unsigned char TypedMemory::getChar(int position){ + return reinterpret_cast(rawMemory[position]); +} + +void TypedMemory::putUInt(int position, unsigned int i){ + int numBytes = sizeof(i); + unsigned int byteMask = 0xff << ((numBytes-1)*8); + for(int k=0; k> ((numBytes-1-k)*8); + byteMask >>= 8; + } + /* equvalent code for sizeof(unsigned int) == 4: + uint8_t byte_a = (i & 0xff); + uint8_t byte_b = (i & 0xff00) >> 8; + uint8_t byte_c = (i & 0xff0000) >> 16; + uint8_t byte_d = (i & 0xff000000) >> 24; + + rawMemory[position+0] = byte_d; + rawMemory[position+1] = byte_c; + rawMemory[position+2] = byte_b; + rawMemory[position+3] = byte_a; + */ + +} + + +unsigned int TypedMemory::getUInt(int position){ + unsigned int result = 0; + int numBytes = sizeof(result); + for(int i=0; i(&rawMemory[position]); + double * pd = reinterpret_cast(pv); + *pd=d; +} + +double TypedMemory::getDouble(int position){ + void * pv = reinterpret_cast(&rawMemory[position]); + double * pd = reinterpret_cast(pv); + return *pd; +} + +void TypedMemory::putAnything(int position, void* src, int size){ + for (int i=0; i(src)[i]; + } +} + +void TypedMemory::getAnything(int position, void* dest, int size){ + for (int i=0; i(dest)[i] = rawMemory[position+i]; + } +} + + +std::string TypedMemory::hexDump(){ + std::string result; + std::string printables; + std::ostringstream os; + + os << std::setbase(16); + int i=0; + while(i(rawMemory[i]); + os << " "; + if(std::isprint(rawMemory[i])){ + printables += static_cast(rawMemory[i]); + }else{ + printables += '.'; + } + i++; + } + os << printables << std::endl; + printables = ""; + } + + os << std::setbase(10); + result = os.str(); + return result; +} diff --git a/02_MENT/typedMemory/typedMemory/typedMemory.hpp b/02_MENT/typedMemory/typedMemory/typedMemory.hpp new file mode 100644 index 0000000..6e23d4c --- /dev/null +++ b/02_MENT/typedMemory/typedMemory/typedMemory.hpp @@ -0,0 +1,25 @@ +// typedMemory.hpp + +#ifndef typedMemory_hpp +#define typedMemory_hpp +#include +#include + +struct TypedMemory { + static const int RAWMEMORYSIZE=128;//1024; + uint8_t rawMemory[RAWMEMORYSIZE]; + + void putChar(int position, unsigned char c); // position in bytes starting at 0 + unsigned char getChar(int position); + // void putShort(int position); + // char getShort(int position); + void putUInt(int position, unsigned int i); + unsigned int getUInt(int position); + void putDouble(int position, double d); + double getDouble(int position); + void putAnything(int position, void* src, int size); + void getAnything(int position, void* dest, int size); + std::string hexDump(); +}; + +#endif diff --git a/03_FLOW_a/build.sh b/03_FLOW_a/build.sh new file mode 100644 index 0000000..9093d33 --- /dev/null +++ b/03_FLOW_a/build.sh @@ -0,0 +1,2 @@ +#!/bin/bash +clang++ -std=c++14 -I ../helpers -o flow.out main_mp2_FLOW_a.cpp ../helpers/AnsiConsole.cpp diff --git a/03_FLOW_a/main_mp2_FLOW_a.cpp b/03_FLOW_a/main_mp2_FLOW_a.cpp new file mode 100644 index 0000000..dd18cd6 --- /dev/null +++ b/03_FLOW_a/main_mp2_FLOW_a.cpp @@ -0,0 +1,137 @@ +#include /* file main_mp2_FLOW_a.cpp */ +#include "AnsiConsole.h" + +AnsiConsole console; int firstLine; int currentTick; Colors currentColor; +#define INITPRINT(label) {firstLine=__LINE__;console.printText(2*currentTick,0,label,Colors::BLACK);} +#define PRINT printLineNumber(__LINE__) +void printLineNumber(int lineNumber); + +void recurse(int); // forward declaration because of firstLine initialization +void start_Recursion(){ + INITPRINT("Recursion"); + PRINT;recurse(10); + PRINT; +} +void recurse(int turns){ + PRINT; if(turns>0){ + PRINT; recurse(turns - 1); + } + PRINT; +} + + + + + + + + + +void start_Sequence(void){ + INITPRINT("Sequence"); + PRINT; + PRINT; + PRINT; + PRINT; + PRINT; + PRINT; + PRINT; + PRINT; + PRINT; + PRINT; +} + + + + + + + +void start_SeqSelection(void){ + INITPRINT("Selection"); + PRINT; int b = 1; + PRINT; if (b == 1){ + PRINT; + PRINT; + PRINT; + PRINT; + PRINT; }else{ + PRINT; + PRINT; + PRINT; + PRINT; + PRINT; + }PRINT; + PRINT; +} + + + +void start_Iteration(void){ + INITPRINT("Iteration"); + PRINT; int i=9; + PRINT; while(i>=0){ + PRINT; i--; + }PRINT; + PRINT; +} + + +int func_1(int arg); + +// Sequence, Selection, Iteration, Subroutine +void start_subroutine(void){ + INITPRINT("Subroutine"); + PRINT; func_1(1); + PRINT; func_1(1); + PRINT; +} + +int func_1(int arg){ + PRINT; int local_1; + PRINT; + PRINT; + PRINT; + PRINT; return arg * local_1; +} + + + + +int main(int argc, const char * argv[]) { + console.clearScreen(); + currentColor = Colors::BLUE; + start_Sequence(); + currentColor = Colors::RED; + start_SeqSelection(); + currentColor = Colors::YELLOW; + start_subroutine(); + currentColor = Colors::GREEN; + start_Iteration(); + currentColor = Colors::CYAN; + start_Recursion(); + + //start_goto(); + //start_switch(); + //start_interrupt(); + //start_coroutine(); + //start_exception(); + std::string s; + std::cin >> s; + + return 0; +} + +void printLineNumber(int lineNumber){ + std::string line = std::to_string(lineNumber); + currentTick++; + console.printText(currentTick*2-1, 1+lineNumber-firstLine, line, currentColor); +} + + +/*void printLineNumber(int lineNumber){ + std::string line = std::to_string(lineNumber); + console.printText(currentTick*2, 1+lineNumber-firstLine, line, currentColor); + currentTick++; +}*/ + diff --git a/03_FLOW_b/build.sh b/03_FLOW_b/build.sh new file mode 100644 index 0000000..844f053 --- /dev/null +++ b/03_FLOW_b/build.sh @@ -0,0 +1,2 @@ +#!/bin/bash +clang++ -std=c++14 -o controlFlowIntr main_ISR.cpp diff --git a/03_FLOW_b/controlFlowIntr b/03_FLOW_b/controlFlowIntr new file mode 100644 index 0000000..dcccacc Binary files /dev/null and b/03_FLOW_b/controlFlowIntr differ diff --git a/03_FLOW_b/main_ISR.cpp b/03_FLOW_b/main_ISR.cpp new file mode 100644 index 0000000..8f87b34 --- /dev/null +++ b/03_FLOW_b/main_ISR.cpp @@ -0,0 +1,27 @@ +// file main_ISR.cpp +#include +#include +#include + +volatile int j; + +//extern "C" { +void ISR(int iarg){ + std::cout << "ISR j=" << j << "\n"; +} +//} + +void install_ISR(void){ + signal(SIGUSR1, ISR); +} + +int main(int argc, const char * argv[]) { + std::cout << "process ID = " << getpid() << "\n"; + install_ISR(); + for(int i=0; i<300*1000*1000; i++){ + i= i +10; i-=10; j=i; + } + std::cout << "done.\n"; + return 0; +} + diff --git a/03_FLOW_b/run.sh b/03_FLOW_b/run.sh new file mode 100644 index 0000000..b4b5f7d --- /dev/null +++ b/03_FLOW_b/run.sh @@ -0,0 +1,9 @@ +#!/bin/bash +./controlFlowIntr & +echo $! +sleep 1 +kill -SIGUSR1 $! +sleep 1 +kill -SIGUSR1 $! +kill -SIGUSR1 $! + diff --git a/03_FLOW_c/AP2-dc.cpp b/03_FLOW_c/AP2-dc.cpp new file mode 100644 index 0000000..5a545b3 --- /dev/null +++ b/03_FLOW_c/AP2-dc.cpp @@ -0,0 +1,239 @@ +// based on http://www.stroustrup.com/dc.c +// by Bjarne Stroustrup +// The desk calculator +// pp 107-117, sec 6.1, A Desk calculator +// No guarantees offered. Constructive comments to bs@research.att.com + + +/* + expr_list: + expression PRINT // PRINT is \n + expression PRINT expr_list + + expression: + expression + term + expression - term + term + + term: + term / power + term * power + power + + power: + power # primary // char '^' produces problems with terminal input + primary + + + primary: + NUMBER + ( expression ) + + +while statt for +erweitern um o,i oder HexaDezimal mit &, |, x, + */ + + +#include +#include +#include + +using namespace std; + +int no_of_errors; // note: default initialized to 0 +bool doPrintCalculations = true; + + +unsigned int error(const char* s) +{ + no_of_errors++; + cerr << "error: " << s << '\n'; + return 1; +} + +enum Token_value { + NUMBER, // '0' ... '9' + PLUS='+', MINUS='-', MUL='*', DIV='/', + PRINT='\n', POWER='#', LP='(', RP=')' +}; + +Token_value global_token = PRINT; +unsigned int number_value; + +unsigned int asciToInt(string string_value){ + unsigned int result = 0; + for(size_t i=0; i> number_value; + string string_value; + string_value = ch; + while (cin.get(ch) && isdigit(ch)) + string_value += ch; // string_value.push_back(ch); // to work around library bug + cin.putback(ch); + number_value = asciToInt(string_value); + return global_token=NUMBER; + } + default: + error("bad token"); + return global_token=PRINT; + } +} + + +unsigned int expression(); // cannot do without (indirect recursion) + + +unsigned int primary() // handle primaries +{ + Token_value current_token = get_token(); + + switch (current_token) { + case NUMBER:{ + unsigned int v = number_value; + get_token(); // proceed global_token to next token (i.e. operator or '\n') + return v; + } + case LP:{ + unsigned int e = expression(); + if (global_token != RP) return error(") expected"); + get_token(); // eat ')' in order to proceed global_token to next token + return e; + } + default: + return error("primary expected"); + } +} + +unsigned int power() // 2 ^ 3 +{ + unsigned int left = primary(); + unsigned int right = 0; + + for (;;) + switch (global_token) { + case POWER:{ + right = primary(); + if (doPrintCalculations) printf("%u # %u\n", left, right); + unsigned int base = left; + left = 1; + for (int i=0; i "; + cout << expression() << '\n'; + } + return no_of_errors; +} diff --git a/03_FLOW_c/build.sh b/03_FLOW_c/build.sh new file mode 100644 index 0000000..3674a68 --- /dev/null +++ b/03_FLOW_c/build.sh @@ -0,0 +1,2 @@ +#!/bin/bash +clang++ -std=c++14 -o dc.out AP2-dc.cpp diff --git a/04_UDEF/RationalNumber.cpp b/04_UDEF/RationalNumber.cpp new file mode 100644 index 0000000..fe25204 --- /dev/null +++ b/04_UDEF/RationalNumber.cpp @@ -0,0 +1,28 @@ +// file: RationalNumber.cpp +#include "RationalNumber.hpp" + +RationalNumber addRationalNumbers(RationalNumber left, RationalNumber right){ + RationalNumber result; + // add left and right + return result; +} + +RationalNumber operator+ (RationalNumber left, RationalNumber right){ + return addRationalNumbers(left, right); +} + +// for println() +std::string as_string(RationalNumber r){ + std::string result = "("; + result += std::to_string(r.zaehler); + result += "/"; + result += std::to_string(r.nenner); + result += ")"; + return result; +} + +/*std::ostream& operator<< (std::ostream& os, RationalNumber &toBePrinted){ + os << "(" << toBePrinted.zaehler << "/" + << toBePrinted.nenner << ")"; + return os; +}*/ diff --git a/04_UDEF/RationalNumber.hpp b/04_UDEF/RationalNumber.hpp new file mode 100644 index 0000000..160509c --- /dev/null +++ b/04_UDEF/RationalNumber.hpp @@ -0,0 +1,12 @@ +// file: RationalNumber.hpp +#include + +struct RationalNumber{ + int zaehler; + int nenner; +}; + +RationalNumber addRationalNumbers(RationalNumber left, RationalNumber right); +RationalNumber operator+ (RationalNumber left, RationalNumber right); +std::string as_string(RationalNumber); // for println() +//std::ostream& operator<< (std::ostream& os, RationalNumber &toBePrinted); // for cout diff --git a/04_UDEF/main_04_UDEF_a.cpp b/04_UDEF/main_04_UDEF_a.cpp new file mode 100644 index 0000000..92e5cc4 --- /dev/null +++ b/04_UDEF/main_04_UDEF_a.cpp @@ -0,0 +1,40 @@ +// file: main_04_UDEF_a.cpp +#include "../helpers/println.hpp" +#include "RationalNumber.hpp" +#include + +// location 1 + +// this declares an alias for type , which is called calctype +//typedef unsigned int calctype; +//typedef int calctype; +//typedef double calctype; +typedef RationalNumber calctype; + +// location 2 + + +void doCalculation(calctype a, calctype b){ + + calctype c = a + b; + +// here is some advanced computation on arguments a and b +// for(){ ... +// if(){ ... +// for(){ ... + + println("a = ", a); + println("b = ", b); + println("c = ", c); +} + + +int main(int argc, char** argv, char** envp){ + + calctype a; + calctype b; + + doCalculation(a,b); + + return 0; +} diff --git a/04_UDEF/main_04_UDEF_e.cpp b/04_UDEF/main_04_UDEF_e.cpp new file mode 100644 index 0000000..5e97943 --- /dev/null +++ b/04_UDEF/main_04_UDEF_e.cpp @@ -0,0 +1,52 @@ +// file main_04_UDEF_e.cpp +#include "../helpers/println.hpp" +#include + +const int bitsPerOctet=8; + +struct BinaryOctet { + bool evenParity; // set to true if number of '1' in bitsAsDigits is even, false otherwise + char bitsAsDigits[bitsPerOctet]; // bit values as chars + BinaryOctet(int x=0); + BinaryOctet(const BinaryOctet&) = default; +}; + +BinaryOctet::BinaryOctet(int x){ + // TODO: implement +} + + +BinaryOctet doCalculation(BinaryOctet a, BinaryOctet b){ + BinaryOctet result; + + for(; a != b; b--){ + a = a + 1; + a = a / b; + } + result = a + b; + + return result; +} + +// for println(); +std::string as_string(BinaryOctet a){ + std::string result = "("; + // TODO: implement + result += ")"; + return result; +} + +// for std::cout +/*std::ostream& operator<< (std::ostream& os, const BinaryOctet &toBePrinted){ + os << "(" << ")"; + return os; +}*/ + +int main(int argc, char **argv) +{ + BinaryOctet a = 0b00001111; + BinaryOctet b = 0b00000110; + println("result = ", doCalculation(a,b)); + //std::cout << "result = " << doCalculation(a,b) << std::endl; + return 0; +} diff --git a/05_OO/AnsiConsoleDemo.cpp b/05_OO/AnsiConsoleDemo.cpp new file mode 100644 index 0000000..136daf0 --- /dev/null +++ b/05_OO/AnsiConsoleDemo.cpp @@ -0,0 +1,29 @@ +#include +#include +#include "AnsiConsole.h" + +/* + see + https://en.wikipedia.org/wiki/ANSI_escape_code + https://gist.github.com/vratiu/9780109 + https://gist.github.com/RobinMalfait/7881398 + */ + + +int main(int argc, char **argv) +{ + ansiConsole.clearScreen(); + // x=1 and y=1 is the upper left corner + // x and y are more like column and row + ansiConsole.printText(4,4,"Hello, World!"); + + // draw a pixel, sort of + ansiConsole.printText(3,3,"*"); + // draw a line + for(int i=0;i<10;i++){ + ansiConsole.printText(2+i,2,"-", Colors::GREEN); + } + ansiConsole.printText(5,15,"end."); + + return 0; +} diff --git a/05_OO/build.sh b/05_OO/build.sh new file mode 100644 index 0000000..b56fae7 --- /dev/null +++ b/05_OO/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash +clang++ -std=c++14 -o shape_main.out -I ../helpers/ shapes_main.cpp ../helpers/AnsiConsole.cpp +clang++ -std=c++14 -o ansiConsole.out -I ../helpers/ AnsiConsoleDemo.cpp ../helpers/AnsiConsole.cpp diff --git a/05_OO/main_mp4_OO_a_vehicles.cpp b/05_OO/main_mp4_OO_a_vehicles.cpp new file mode 100644 index 0000000..9eeac3d --- /dev/null +++ b/05_OO/main_mp4_OO_a_vehicles.cpp @@ -0,0 +1,105 @@ +#include +#include + + +//====================================== + +class Vehicle { +protected: + int _numSeats; +public: + Vehicle(int numSeats=0);// may serve as default ctor (i.e. no arguments) + virtual ~Vehicle(); + virtual int payload() = 0; + int numSeats(); // a 'getter' method to get a value; no 'setter' here +}; + +//====================================== + +class Car : public Vehicle { +protected: + int _maxWeight; // german: zulässiges Gesamtgewicht +public: + Car(int numSeats, int maxWeight); + virtual int payload(); + +}; + +//====================================== + +class Truck : public Vehicle { +protected: + int _payload; +public: + Truck(int numSeats, int payload); + virtual int payload(); +}; + +//====================================== + +Vehicle::Vehicle(int numSeats){ + _numSeats = numSeats; +} + +Vehicle::~Vehicle(){ + std::cout << "destroying a Vehicle" << std::endl; +} + +int Vehicle::numSeats(){ + return _numSeats; +} + +//====================================== + +Car::Car(int numSeats, int maxWeight){ + _numSeats = numSeats; + _maxWeight = maxWeight; +} + +int Car::payload(){ + return _maxWeight - (_numSeats*75); +} + +//====================================== + +Truck::Truck(int numSeats, int payload){ + _numSeats = numSeats; + _payload = payload; +} + +int Truck::payload(){ + return _payload; +} + +//====================================== + + +void printVehicleInfo(Vehicle* v){ + std::cout << "typeid=`" << typeid(*v).name() << "`" + << " numSeats=" << v->numSeats() + << " payload=" << v->payload() << std::endl; +} + +int main(int argc, const char * argv[]) { + + Car* c = new Car(5, 1000); // create a new object of class Car in free store + Truck* t = new Truck(3, 7500); + + std::cout << "1" << std::endl; + std::cout << "c: numSeats=" << c->numSeats() << " payload=" << c->payload() << std::endl; + std::cout << "t: numSeats=" << t->numSeats() << " payload=" << t->payload() << std::endl; + + std::cout << std::endl << "2" << std::endl; + Vehicle* v = c; // a Car `is a` Vehicle => implicitly convertible + printVehicleInfo(v); + v = t; // a Truck `is a` Vehicle => implicitly convertible + printVehicleInfo(v); + + + // release memory occupied by t,c for use by future objects created by `new` + // do NOT release v. it is only an alias + delete t; + delete c; + + return 0; +} diff --git a/05_OO/main_mp4_OO_b.cpp b/05_OO/main_mp4_OO_b.cpp new file mode 100644 index 0000000..25160e8 --- /dev/null +++ b/05_OO/main_mp4_OO_b.cpp @@ -0,0 +1,198 @@ +// file main_mp4_OO_b.cpp +#include +#include + +//======================================= + +struct FooVal { + FooVal(int initialValue=0); + ~FooVal(); +private: + int _someValue; +}; + +//======================================= + +class FooBase { + FooVal _value; +public: + FooBase(); + FooBase(int initialValue); + virtual ~FooBase(); +}; + +//======================================= + +class FooDerived : public FooBase { + int _ival; +public: + FooDerived(int initialValue); + ~FooDerived(); +}; + +//======================================= + +class Bar { + FooBase *_helperObject; +public: + Bar(); + ~Bar(); +}; + +//======================================= + +FooVal::FooVal(int initialValue) +: _someValue(initialValue) +{ + std::cout << "FooVal::FooVal()" << std::endl; +} + +FooVal::~FooVal(){ + std::cout << "FooVal::~FooVal()" << std::endl; +} + +FooBase::FooBase(){ + std::cout << "FooBase::FooBase()" << std::endl; +} + +FooBase::FooBase(int initialValue) +: _value(initialValue) +{ + std::cout << "FooBase::FooBase(int)" << std::endl; +} + +FooBase::~FooBase(){ + std::cout << "FooBase::~FooBase(" << std::endl; +} + +FooDerived::FooDerived(int initialValue) +: FooBase(initialValue), _ival(0) +{ + std::cout << "FooDerived::FooDerived()" << std::endl; +} + +FooDerived::~FooDerived(){ + std::cout << "FooDerived::~FooDerived()" << std::endl; +} + +Bar::Bar(){ + _helperObject = new FooDerived(0); +} + +Bar::~Bar(){ + delete _helperObject; +} + + +struct StackObject { +private: + void* operator new(size_t size) noexcept { + bool noStackObjectOnHeap = false; + assert(noStackObjectOnHeap); + return nullptr; + } +}; + + +struct A : public StackObject { + A(){std::cout << "+A ";} + //A(const A&){std::cout << "+A";} + ~A(){std::cout << "-A ";} +}; + +struct B : public StackObject { + B(){std::cout << "+B ";} + //B(const B&){std::cout << "+B";} + ~B(){std::cout << "-B ";} +}; + + +struct C : public StackObject { + C(){std::cout << "+C ";} + //C(const C&){std::cout << "+C";} + ~C(){std::cout << "-C ";} +}; + +class HeapObject{ +public: + void* operator new (size_t size); + HeapObject(); + virtual ~HeapObject(); + static bool assertionsHold(); +protected: +private: + static int ctorCount; + static int dtorCount; + static int newCount; + // static void remove(HeapObject *); + HeapObject(const HeapObject&) = delete; + HeapObject& operator=(const HeapObject&) = delete; +}; + +int HeapObject::ctorCount = 0; +int HeapObject::dtorCount = 0; +int HeapObject::newCount = 0; + +void* HeapObject::operator new (size_t size){ + newCount++; + return new char[size]; +} + +HeapObject::HeapObject(){ + ctorCount++; +} + +HeapObject::~HeapObject(){ + dtorCount++; +} + +bool HeapObject::assertionsHold(){ + assert(ctorCount == newCount); // all objects have been allocated on heap + assert(ctorCount == dtorCount); // all objects have been deleted + return true; +} + + +class K : public HeapObject +{ +public: + K(){std::cout << "+K ";} + ~K(){std::cout << "-K ";} +}; + +class L { +public: + L(){std::cout << "+L ";} + ~L(){std::cout << "-L ";} +}; + + +class M { +public: + M(){std::cout << "+M ";} + ~M(){std::cout << "-M ";} +}; + + + +int main(int argc, const char * argv[]) { + Bar * bar = new Bar(); + // ... + delete bar; // implies "delete _helperObject"; + + FooBase *obj = new FooDerived(7); + delete obj; + + { + C c; + K* k = new K(); + delete k; + } + + HeapObject::assertionsHold(); + std::cout << " ENDE" << std::endl; + return 0; +} + + + diff --git a/05_OO/shapes_main.cpp b/05_OO/shapes_main.cpp new file mode 100644 index 0000000..fc7b247 --- /dev/null +++ b/05_OO/shapes_main.cpp @@ -0,0 +1,87 @@ +#include +#include +#include "AnsiConsole.h" + +struct Position{ + int x; + int y; + Position(int x_=0, int y_=0){ x=x_;y=y_;} +}; + +class Point{ +protected: + Position _position; +public: + Point(int x=0, int y=0); + void draw(); +}; + +Point::Point(int x, int y){ + _position = Position(x,y); +} + +void Point::draw(){ + ansiConsole.printText(_position.x,_position.y,"*", Colors::RED); +} + +class Circle{ +protected: + Position _position; + int _radius; +public: + Circle(int x=0, int y=0, int radius=0); + void draw(); +}; + +Circle::Circle(int x, int y, int radius){ + _position = Position(x,y); + _radius=radius; +} + +void Circle::draw(){ + /* see https://de.wikibooks.org/wiki/Formelsammlung_Mathematik:_Geometrie + * Höhensatz des Euklid + * */ + int x_start = _position.x - _radius/2; + int x_stop = _position.x + _radius/2; + + for(int i=x_start; i<=x_stop; i++){ + double x_relative = double(i) - double(x_start); + double h = sqrt(x_relative*(x_stop-x_start-x_relative)); + ansiConsole.printText(_position.x + int(x_relative)- _radius/2, + _position.y +h,"#", + Colors::GREEN); + ansiConsole.printText(_position.x + int(x_relative)- _radius/2, + _position.y -h,"#", + Colors::GREEN); + + } +} + +int main(int argc, char **argv) +{ + // x=1 and y=1 is the upper left corner + // x and y are more like column and row + ansiConsole.printText(5,5,"Hello, World!"); + + Point* p = new Point(10,10); + p->draw(); + + Point* p2 = new Point(2,10); + p2->draw(); + + + Circle* c = new Circle(30, 15, 10); + c->draw(); + + Point* p3= new Point(30,15); + p3->draw(); + + + delete p; + delete p2; + delete p3; + delete c; + + return 0; +} diff --git a/06_POLY/main_mp5_POLY.cpp b/06_POLY/main_mp5_POLY.cpp new file mode 100644 index 0000000..0fc6517 --- /dev/null +++ b/06_POLY/main_mp5_POLY.cpp @@ -0,0 +1,281 @@ +// file main_mp5_POLY.cpp +#include +#include + +class Base { +public: + void overriddenMethod(); + void overriddenMethod(int); + void overriddenMethod(std::string); + void nonVirtualMethod(void); + virtual void virtualMethod(void); + /* + virtual void virtualAndOverridden(void); + virtual void virtualAndOverridden(int); + virtual void virtualAndOverridden(std::string);*/ +}; + +class Derived_1 : public Base { +public: + Derived_1(); + ~Derived_1(); + void nonVirtualMethod(void); + virtual void virtualMethod(void); + +/* virtual void virtualAndOverridden(void); + virtual void virtualAndOverridden(int); + virtual void virtualAndOverridden(std::string);*/ +}; + +class Derived_2 : public Derived_1 { +public: + void nonVirtualMethod(void); + virtual void virtualMethod(void); +}; + +// see https://isocpp.org/wiki/faq/strange-inheritance#calling-virtuals-from-ctors +Derived_1::Derived_1(){ + virtualMethod(); // 6a +} + +Derived_1::~Derived_1(){ + virtualMethod(); // 6b +} + +// ------------------- +void Base::overriddenMethod(void){ + std::cout << "Base::overriddenMethod(void)" << std::endl; +} + +void Base::overriddenMethod(int){ + std::cout << "Base::overriddenMethod(int)" << std::endl; +} + +void Base::overriddenMethod(std::string){ + std::cout << "Base::overriddenMethod(std::string)" << std::endl; +} + +void Base::nonVirtualMethod(void){ + std::cout << "Base::nonVirtualMethod(void)" << std::endl; +} + +void Base::virtualMethod(void){ + std::cout << "Base::virtualMethod" << std::endl; +} + + +/* +void Base::virtualAndOverridden(void){ + std::cout << "Base::virtualAndOverridden(void)" << std::endl; +} + +void Base::virtualAndOverridden(int){ + std::cout << "Base::virtualAndOverridden(int)" << std::endl; +} + +void Base::virtualAndOverridden(std::string){ + std::cout << "Base::virtualAndOverridden(std::string)" << std::endl; +} +*/ + +// ------------------- +void Derived_1::nonVirtualMethod(void){ + std::cout << "Derived_1::nonVirtualMethod" << std::endl; +} +void Derived_1::virtualMethod(void){ + std::cout << "Derived_1::virtualMethod" << std::endl; +} + + +/* +void Derived_1::virtualAndOverridden(void){ + std::cout << "Derived_1::virtualAndOverridden(void)" << std::endl; +} + +void Derived_1::virtualAndOverridden(int){ + std::cout << "Derived_1::virtualAndOverridden(int)" << std::endl; +} + +void Derived_1::virtualAndOverridden(std::string){ + std::cout << "Derived_1::virtualAndOverridden(std::string)" << std::endl; +} +*/ + + +// ------------------- +void Derived_2::nonVirtualMethod(void){ + std::cout << "Derived_2::nonVirtualMethod" << std::endl; +} +void Derived_2::virtualMethod(void){ + std::cout << "Derived_2::virtualMethod" << std::endl; +} + + + +/* + illustrates binding of method invocations + compile time vs. run time binding + */ + +void foobar(void){ + + std::cout << "6a) "; + Derived_2* pR = new Derived_2(); + + Base* pBase = pR; + Derived_1* pDerived_1 = pR; + Derived_2* pDerived_2 = pR; + + std::cout << "1) "; + pBase->virtualMethod(); // 1) + + std::cout << "2) "; + pBase->nonVirtualMethod(); // 2) + + std::cout << "3) "; + pDerived_2->virtualMethod(); // 3) + + std::cout << "4) "; + pDerived_2->nonVirtualMethod(); // 4) + + std::cout << "5) "; + static_cast(pDerived_2)->nonVirtualMethod(); // 5) + + std::cout << "7) "; + static_cast(pDerived_2)->nonVirtualMethod(); // 7) + + std::cout << "8) "; + pDerived_1->nonVirtualMethod(); // 8) + + std::cout << "9) "; + pDerived_1->virtualMethod(); // 9) + + std::cout << "10a) "; + pBase->Base::virtualMethod(); // 10a) + + std::cout << "10b) "; + pDerived_2->Derived_1::virtualMethod(); // 10b) + + std::cout << "11 "; + pDerived_2->overriddenMethod(17); // 11) + + std::cout << "12 "; + pDerived_2->overriddenMethod(); // 12) + + std::cout << "13 "; + pDerived_2->overriddenMethod(std::string("x")); // 13) + + std::cout << "14 "; + dynamic_cast(pBase)->virtualMethod(); // 14) + + std::cout << "15 "; + Base* baseObject = new Base(); + Derived_2* d2Object = dynamic_cast(baseObject); + if(d2Object){ // 15) + std::cout << "+" << std::endl; + }else{ + std::cout << "-" << std::endl; + } + + /* + std::cout << "16 "; + pDerived_2->virtualAndOverridden(17); // 16) + + std::cout << "17 "; + pDerived_2->virtualAndOverridden(); // 17) + + std::cout << "18 "; + pDerived_2->virtualAndOverridden(std::string("x")); // 18) + */ + + + std::cout << "6b) "; + delete pR; +} + +/* + void foo(){ + for(int i=0; inonVirtualMethod2(); + delete ps; + } + } + + void bar(int i){ + Base s; + s.nonVirtualMethod2(); + if(i>0){ + bar(i-1); + } + }*/ + +typedef void (*funcPointer_void_void)(void); + +void sing_gingle(void){ + std::cout << "gingle "; +} + +void sing_bells(void){ + std::cout << "bells "; +} + +void sing_surf(void){ + std::cout << "surf "; +} + +void sing_safari(void){ + std::cout << "surfin safari "; +} + +std::vector songOfSeason(int currentTemperatureCelsius) { + std::vector result; + + if(currentTemperatureCelsius <= 0){ + result.push_back(sing_gingle); + result.push_back(sing_bells); + result.push_back(sing_gingle); + result.push_back(sing_bells); + }else{ + result.push_back(sing_surf); + result.push_back(sing_surf); + result.push_back(sing_safari); + result.push_back(sing_surf); + result.push_back(sing_surf); + result.push_back(sing_safari); + } + + return result; +} + +void sing(int currentTemperatureCelsius){ + std::vector song = songOfSeason(currentTemperatureCelsius); + + // traditional C-style for-loop + for(int i=0; i + +// good: encapsulation +// good: separation of interface and implementation +// good: arbitrary element type +// good: arbitrary capacity +// bad: implementation in .hpp +// bad: compiler error messages are difficult to read + +template +struct genericStack { + int tos; // top of stack, i.e. index of next write/push + ElementType elements[capacity]; +public: + genericStack(); + void push(ElementType element); + ElementType pop(); + int size(); // number of elements pushed + bool isEmpty(); + void clear(); + void print(); +}; + + +// ============= implementation ============= + +template +genericStack::genericStack() +: tos(0) +{ + +} + +template +void genericStack::push(ElementType element){ + elements[tos++] = element; +} + +template +ElementType genericStack::pop(){ + return elements[--tos]; +} + +template +int genericStack::size(){ // number of elements pushed + return tos; +} + +template +bool genericStack::isEmpty(){ + return tos == 0; +} + +template +void genericStack::clear(){ + tos = 0; +} + +template +void genericStack::print(){ + std::cout << size() << " of " << capacity << " allocated." << std::endl; + for (int i=0; i + +const int intStack::capacity; + +intStack::intStack() +: tos(0) +{ + +} + +void intStack::push(int element){ + elements[tos++] = element; +} + +int intStack::pop(){ + return elements[--tos]; +} + +int intStack::size(){ // number of elements pushed + return tos; +} + +bool intStack::isEmpty(){ + return tos == 0; +} + +void intStack::clear(){ + tos = 0; +} + +void intStack::print(){ + std::cout << size() << " of " << capacity << " allocated." << std::endl; + for (int i=0; i +#include "intStack.hpp" +#include "genericStack.hpp" +#include +#include + + +void use_intStack(){ + intStack s_1; + for(int i=0; i<10;i++){ + s_1.push(i*i); + } + std::cout << "s_1 : " << std::endl; + s_1.print(); + // replace top element by 4711: + s_1.pop(); + s_1.push(4711); + // swap topmost two elements: + int tmp1 = s_1.pop(); + int tmp2 = s_1.pop(); + s_1.push(tmp1); + s_1.push(tmp2); + std::cout << "draining s_1 : " << std::endl; + while(!s_1.isEmpty()){ + std::cout << s_1.pop() << std::endl; + } +} + + +void use_genericStack(){ + genericStack s_2; + genericStack s_3; + for(int i=0; i<10;i++){ + s_2.push(i*i); + s_3.push(i*i * 1.1); + } + s_2.print(); + s_3.print(); +} + +void use_std_containers(){ + std::vector v; + v.push_back(17); // append an element at the end + int i = v.back(); // get last element + int j = v[0]; // access by subscript operator + if ((i==j) && (i==17)){ // + v.pop_back(); // remove last element + v.clear(); // remove all elements + } + long s = v.size(); // get size; size() <= max_size() + std::list l; + l.push_back(17); // append an element at the end + l.push_front(s); // put an element in front of the list +} + +void printVector(const std::vector& v){ + for(int j=0; j v(100); + for(int i=0; i<10; i++){ + v[i*i] = i; + } + v.push_back(17); + printVector(v); + std::sort(v.begin(), v.end()); + printVector(v); + std::transform(v.begin(), v.end(), v.begin(), + [](int i) { return i*10; }); // use lambda expression here + printVector(v); +} + +int main(int argc, const char * argv[]) { + std::cout << "use_intStack()" << std::endl; + std::cout << "--------------" << std::endl; + use_intStack(); + std::cout << "use_genericStack()" << std::endl; + std::cout << "------------------" << std::endl; + use_genericStack(); + + std::cout << "use_std_containers()" << std::endl; + std::cout << "------------------" << std::endl; + use_std_containers(); + std::cout << "use_std_algorithms()" << std::endl; + std::cout << "------------------" << std::endl; + use_std_algorithms(); + + return 0; +} diff --git a/07_STD/grundgeruest.cpp b/07_STD/grundgeruest.cpp new file mode 100644 index 0000000..b969ed8 --- /dev/null +++ b/07_STD/grundgeruest.cpp @@ -0,0 +1,17 @@ +// based on example from http://en.cppreference.com/w/cpp/numeric/random/rand +#include +#include +#include + +struct BinaryOctet { + bool evenParity; + char bitsAsDigits[bitsPerOctet]; +}; + +int main() +{ + std::srand(std::time(0)); // use current time as seed for random generator + int random_variable = std::rand(); + std::cout << "Random value on [0 " << RAND_MAX << "]: " + << random_variable << '\n'; +} diff --git a/08_PTRN/Car.cpp b/08_PTRN/Car.cpp new file mode 100644 index 0000000..d787391 --- /dev/null +++ b/08_PTRN/Car.cpp @@ -0,0 +1,19 @@ +#include "Car.hpp" + +Car::Car(std::string model, int maxWeight) +: Vehicle(model) +{ + _maxWeight = maxWeight; +} + +int Car::maxWeight(){ + return _maxWeight; +} + +int Car::payload_kg(){ + return _maxWeight - 75 * 5; // subtract weight of passangers +} + +Vehicle* Car::clone(){ + return new Car(model(), _maxWeight); +} diff --git a/08_PTRN/Car.hpp b/08_PTRN/Car.hpp new file mode 100644 index 0000000..ad92b28 --- /dev/null +++ b/08_PTRN/Car.hpp @@ -0,0 +1,18 @@ +#ifndef Car_hpp +#define Car_hpp + +#include "Vehicle.hpp" + + +class Car : public Vehicle { + int _maxWeight; +public: + Car(std::string model, int maxWeight); + int maxWeight(); + virtual int payload_kg(); + virtual Vehicle* clone(); + //virtual Vehicle* newInstance(); +}; + + +#endif diff --git a/08_PTRN/Logger.cpp b/08_PTRN/Logger.cpp new file mode 100644 index 0000000..29df18d --- /dev/null +++ b/08_PTRN/Logger.cpp @@ -0,0 +1,15 @@ +// file Logger.cpp +#include "Logger.hpp" + +Logger* Logger::_theInstance = nullptr; + +Logger* Logger::getInstance(){ + if (!_theInstance){ + _theInstance = new StdoutLogger(); + } + return _theInstance; +} + +void StdoutLogger::log(std::string message, std::string file, int line){ + std::cerr << message << " in " << file << " line " << line << std::endl; +} diff --git a/08_PTRN/Logger.hpp b/08_PTRN/Logger.hpp new file mode 100644 index 0000000..9b3006c --- /dev/null +++ b/08_PTRN/Logger.hpp @@ -0,0 +1,19 @@ +// file Logger.hpp +#ifndef Logger_hpp +#define Logger_hpp + +#include + +class Logger { + static Logger* _theInstance; +public: + virtual void log(std::string message, std::string file="", int line=0) = 0; + static Logger* getInstance(); +}; + +class StdoutLogger: public Logger { +public: + void log(std::string message, std::string file="", int line=0); +}; + +#endif diff --git a/08_PTRN/Truck.cpp b/08_PTRN/Truck.cpp new file mode 100644 index 0000000..4a2ce96 --- /dev/null +++ b/08_PTRN/Truck.cpp @@ -0,0 +1,16 @@ +#include "Truck.hpp" + +Truck::Truck(std::string model, int payload_kg) +: Vehicle(model) +{ + _payload_kg = payload_kg; +} + +int Truck::payload_kg(){ + return _payload_kg; +} + + +Vehicle* Truck::clone(){ + return new Truck(model(),_payload_kg); +} diff --git a/08_PTRN/Truck.hpp b/08_PTRN/Truck.hpp new file mode 100644 index 0000000..0e3ea26 --- /dev/null +++ b/08_PTRN/Truck.hpp @@ -0,0 +1,17 @@ +#ifndef Truck_hpp +#define Truck_hpp + +#include "Vehicle.hpp" + + +class Truck : public Vehicle { + int _payload_kg; // max number kilograms to load +public: + Truck(std::string model, int payload_kg); + virtual int payload_kg(); + virtual Vehicle* clone(); + //virtual Vehicle* newInstance(); +}; + +#endif + diff --git a/08_PTRN/Vehicle.cpp b/08_PTRN/Vehicle.cpp new file mode 100644 index 0000000..c4b73d7 --- /dev/null +++ b/08_PTRN/Vehicle.cpp @@ -0,0 +1,15 @@ +#include "Vehicle.hpp" + +Vehicle::Vehicle(std::string model){ + this->_model = model; +} + +Vehicle::~Vehicle(){ +} + +std::string Vehicle::model(){ + return _model; +} + + + diff --git a/08_PTRN/Vehicle.hpp b/08_PTRN/Vehicle.hpp new file mode 100644 index 0000000..350940e --- /dev/null +++ b/08_PTRN/Vehicle.hpp @@ -0,0 +1,18 @@ +#ifndef Vehicle_hpp +#define Vehicle_hpp + +#include + +class Vehicle { + std::string _model; +public: + Vehicle(std::string model); + virtual ~Vehicle(); + std::string model(); + virtual int payload_kg() = 0; + virtual Vehicle* clone() {return nullptr;} // idiom "virtual constructor" + //virtual Vehicle* newInstance() = 0; // idiom "virtual constructor" +}; + + +#endif diff --git a/08_PTRN/VehicleFactory.cpp b/08_PTRN/VehicleFactory.cpp new file mode 100644 index 0000000..e0bc75f --- /dev/null +++ b/08_PTRN/VehicleFactory.cpp @@ -0,0 +1,19 @@ +// file VehicleFactory.cpp +#include "VehicleFactory.hpp" +#include "Car.hpp" +#include "Truck.hpp" + +/* + A factory creates objects based un runtime information + a) within the process (data values, Types i.e.e virtual methods) + b) input from files or user input + Th is simple Factory differentiates only based on a value. + */ +Vehicle* vehicleForPayload(std::string model, int weight){ + if (weight < 3500){ + return new Car(model, weight); + }else{ + return new Truck(model, weight); + } +} + diff --git a/08_PTRN/VehicleFactory.hpp b/08_PTRN/VehicleFactory.hpp new file mode 100644 index 0000000..d568cd7 --- /dev/null +++ b/08_PTRN/VehicleFactory.hpp @@ -0,0 +1,10 @@ +// file VehicleFactory.hpp +#ifndef VehicleFactory_hpp +#define VehicleFactory_hpp + +#include "Vehicle.hpp" + +Vehicle* vehicleForPayload(std::string model, int weight); + + +#endif diff --git a/08_PTRN/main.cpp b/08_PTRN/main.cpp new file mode 100644 index 0000000..bcbed14 --- /dev/null +++ b/08_PTRN/main.cpp @@ -0,0 +1,71 @@ +#include "Car.hpp" +#include "Truck.hpp" +#include "Logger.hpp" +#include "VehicleFactory.hpp" + +#include +#include + +void workOnCopy_naive(std::vector vehicles){ + std::vector tempVec; + for (int i=0; i(currentVehicle); // RTTI type check + Truck* truckToCopy = dynamic_cast(currentVehicle);// may be nullptr + if(carToCopy){ + tempVec.push_back(new Car(carToCopy->model(), carToCopy->maxWeight())); // type dependency to Car + }else if(truckToCopy){ + tempVec.push_back(new Truck(truckToCopy->model(), truckToCopy->payload_kg())); // type dependecy + }else{ + // TODO: what do we do here? + // Did someone add a new class to the code base? + return; // BUG: copies aren't free'd + } + } + // work on copies ... + // ... + for(auto vehi : tempVec){ + std::cout << vehi->model() << " " << vehi->payload_kg() << " kg" << std::endl; + } + for (int i=0; i vehicles){ // uses RAII, virtual ctor + + class RAIIvector { // local RAII helper class + public: + std::vector tempVec; + ~RAIIvector(){ + for(auto vehi : tempVec){ + delete vehi; + } + tempVec.clear(); + } + }; + RAIIvector rv; + + for(auto vehi : vehicles){ + rv.tempVec.push_back(vehi->clone()); + } + // work on copies ... + // ... + for(auto vehi : rv.tempVec){ + std::cout << vehi->model() << " " << vehi->payload_kg() << " kg" << std::endl; + } + // compiler WILL invoke RAIIvector::~RAIIvector() here +} + + +int main(int argc, const char * argv[]) { + std::vector vehicles; + vehicles.push_back(vehicleForPayload("Volkswagen Golf", 900)); // use factory for construction + vehicles.push_back(vehicleForPayload("Magirus Deutz", 18*1000)); + Logger::getInstance()->log("work naively", __FILE__, __LINE__); + workOnCopy_naive(vehicles); + Logger::getInstance()->log("work smartly", __FILE__, __LINE__); + workOnCopy_smart(vehicles); + return 0; +} diff --git a/10_PITF/banking_base_rawptr.cpp b/10_PITF/banking_base_rawptr.cpp new file mode 100644 index 0000000..94adf9d --- /dev/null +++ b/10_PITF/banking_base_rawptr.cpp @@ -0,0 +1,121 @@ +#include +#include +#include +#include "println.hpp" + + +struct StackObject { +private: + void* operator new(size_t size) noexcept { + bool noStackObjectOnHeap = false; + assert(noStackObjectOnHeap); + return nullptr; + } +}; + + +class HeapObject{ +public: + void* operator new (size_t size); + HeapObject(); + virtual ~HeapObject(); + static bool assertionsHold(); +protected: +private: + static int ctorCount; + static int dtorCount; + static int newCount; + // static void remove(HeapObject *); + HeapObject(const HeapObject&) = delete; + HeapObject& operator=(const HeapObject&) = delete; +}; + +int HeapObject::ctorCount = 0; +int HeapObject::dtorCount = 0; +int HeapObject::newCount = 0; + +void* HeapObject::operator new (size_t size){ + newCount++; + return new char[size]; +} + +HeapObject::HeapObject(){ + ctorCount++; +} + +HeapObject::~HeapObject(){ + dtorCount++; +} + +bool HeapObject::assertionsHold(){ + assert(ctorCount == newCount); // all objects have been allocated on heap + assert(ctorCount == dtorCount); // all objects have been deleted + return true; +} + +typedef double MoneyUnitType; // should be fixed point class + +class Cash : public HeapObject { +public: + MoneyUnitType _value; + Cash(MoneyUnitType value) : _value(value){} +}; + +typedef std::vector Wallet; + +Wallet consumerWallet_A; +Wallet consumerWallet_B; + +Cash * createCashFor(int i){ + return new Cash(static_cast(i)); +} + +void flushWallet(Wallet& toBeEmptied){ // should be in dtor of sorrounding class + for(int i=0; i + +LifeCycleProbe::LifeCycleProbe(){ + this->id=0; + std::cout << "default ctor id=" << id << std::endl; +#ifdef HAS_RESOURCE_POINTER + resource = new int; +#endif +} + +LifeCycleProbe::LifeCycleProbe(int id){ + this->id=id; + std::cout << "ctor(int) id=" << id << std::endl; +#ifdef HAS_RESOURCE_POINTER + resource = new int; +#endif +} + + +LifeCycleProbe::LifeCycleProbe(const LifeCycleProbe& other){ + std::cout << "copy ctor (source id=" << other.id + << " to id=" << other.id + 9 << ")" << std::endl; + this->id=other.id + 9; +#ifdef HAS_RESOURCE_POINTER + this->resource = other.resource; +#endif +} + +LifeCycleProbe& LifeCycleProbe::operator=(const LifeCycleProbe& other){ + std::cout << "assignment (old id=" << this->id + << " source id=" << other.id + << " new id=" << other.id + 11 << ")" << std::endl; + this->id = other.id + 11; + return *this; +} + + +LifeCycleProbe::~LifeCycleProbe(){ + std::cout << "dtor id=" << id << std::endl; +#ifdef HAS_RESOURCE_POINTER + std::cout << "deleting resource" << *resource << std::endl; + delete resource; +#endif +} + +void LifeCycleProbe::printID(){ + std::cout << "printID() id=" << id << std::endl; +} + + diff --git a/10_PITF/doubleDelete/LifeCycleProbe.hpp b/10_PITF/doubleDelete/LifeCycleProbe.hpp new file mode 100644 index 0000000..c5accda --- /dev/null +++ b/10_PITF/doubleDelete/LifeCycleProbe.hpp @@ -0,0 +1,23 @@ +// LifeCycleProbe.hpp +// DoubleDelete + +#ifndef LifeCycleProbe_hpp +#define LifeCycleProbe_hpp + +//#define HAS_RESOURCE_POINTER + +class LifeCycleProbe { + int id; +#ifdef HAS_RESOURCE_POINTER + int *resource; +#endif +public: + LifeCycleProbe(); + LifeCycleProbe(int id); + LifeCycleProbe(const LifeCycleProbe&); + LifeCycleProbe& operator=(const LifeCycleProbe&); + ~LifeCycleProbe(); + void printID(); +}; + +#endif diff --git a/10_PITF/doubleDelete/main.cpp b/10_PITF/doubleDelete/main.cpp new file mode 100644 index 0000000..02bd943 --- /dev/null +++ b/10_PITF/doubleDelete/main.cpp @@ -0,0 +1,38 @@ +// main.cpp +// DoubleDelete + + +#include "LifeCycleProbe.hpp" +#include + +void callByPointer(LifeCycleProbe* p){ + p->printID(); +} + +void callByReference(LifeCycleProbe& r){ + r.printID(); +} + +void callByValue(LifeCycleProbe v){ + v.printID(); +} + +int main(int argc, const char * argv[]) { + + LifeCycleProbe probe(1000); + + std::cout << "three invocations ===========" << std::endl; + callByPointer(&probe); + callByReference(probe); + callByValue(probe); + + { + std::cout << "assigment ===========" << std::endl; + LifeCycleProbe blockProbe(2000); + blockProbe = probe; + blockProbe.printID(); + } + + std::cout << "The End. ===========" << std::endl; + return 0; +} diff --git a/10_PITF/main_objectSlicing.cpp b/10_PITF/main_objectSlicing.cpp new file mode 100644 index 0000000..c48a868 --- /dev/null +++ b/10_PITF/main_objectSlicing.cpp @@ -0,0 +1,67 @@ +// main.cpp +// objectSlicing + +#include +#include + +class Base{ + int _a; +public: + Base(){} + virtual ~Base() {} + Base(int aa) :_a(aa) {} + int value_a(); + virtual int value_virtual(); +}; + +int Base::value_a(){ + return _a; +} + +int Base::value_virtual(){ + return _a; +} + +class Derived : public Base { + int _b; +public: + Derived(int x, int y) : Base(x), _b(y) {} + virtual int value_virtual(); +}; + +int Derived::value_virtual(){ + return _b; +} + +void passByPointer(Base* bp){ + std::cout << "->value_a() = " << bp->value_a() << std::endl; + std::cout << "->value_virtual() = " << bp->value_virtual() << std::endl; +} + +void passByValue(Base b){ + std::cout << ".value_a() = " << b.value_a() << std::endl; + std::cout << ".value_virtual() = " << b.value_virtual() << std::endl; +} + +int main(int argc, const char * argv[]) { + Derived d(1,2); + + std::cout << "d.value_virtual() = " << d.value_virtual() << std::endl; + + std::cout << std::endl << "pass pointer to base class " << std::endl; + passByPointer(&d); // pass pointer to base class + + std::cout << std::endl << "pass by value (i.e. object of class Base) " << std::endl; + passByValue(d); // pass Base-object by value -> object slicing: d is "transformed" int an object of class Base + + std::cout << std::endl << "store Derived objects in std::vector" << std::endl; + std::vector v; + v.push_back(d); // object slicing + std::cout << ".value_a() = " << v[0].value_a() << std::endl; + std::cout << ".value_virtual() = " << v[0].value_virtual() << std::endl; + + return 0; +} + + + diff --git a/11_PUTT/CopyOnWrite/CopyOnWrite.xcodeproj/project.pbxproj b/11_PUTT/CopyOnWrite/CopyOnWrite.xcodeproj/project.pbxproj new file mode 100644 index 0000000..14d1bd8 --- /dev/null +++ b/11_PUTT/CopyOnWrite/CopyOnWrite.xcodeproj/project.pbxproj @@ -0,0 +1,245 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 65413E911CEB65E5008BE849 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65413E901CEB65E5008BE849 /* main.cpp */; }; + 65413E991CEB6612008BE849 /* OneByOneMatrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65413E971CEB6612008BE849 /* OneByOneMatrix.cpp */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 65413E8B1CEB65E5008BE849 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 65413E8D1CEB65E5008BE849 /* CopyOnWrite */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = CopyOnWrite; sourceTree = BUILT_PRODUCTS_DIR; }; + 65413E901CEB65E5008BE849 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; + 65413E971CEB6612008BE849 /* OneByOneMatrix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OneByOneMatrix.cpp; sourceTree = ""; }; + 65413E981CEB6612008BE849 /* OneByOneMatrix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OneByOneMatrix.h; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 65413E8A1CEB65E5008BE849 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 65413E841CEB65E5008BE849 = { + isa = PBXGroup; + children = ( + 65413E8F1CEB65E5008BE849 /* CopyOnWrite */, + 65413E8E1CEB65E5008BE849 /* Products */, + ); + sourceTree = ""; + }; + 65413E8E1CEB65E5008BE849 /* Products */ = { + isa = PBXGroup; + children = ( + 65413E8D1CEB65E5008BE849 /* CopyOnWrite */, + ); + name = Products; + sourceTree = ""; + }; + 65413E8F1CEB65E5008BE849 /* CopyOnWrite */ = { + isa = PBXGroup; + children = ( + 65413E901CEB65E5008BE849 /* main.cpp */, + 65413E971CEB6612008BE849 /* OneByOneMatrix.cpp */, + 65413E981CEB6612008BE849 /* OneByOneMatrix.h */, + ); + path = CopyOnWrite; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 65413E8C1CEB65E5008BE849 /* CopyOnWrite */ = { + isa = PBXNativeTarget; + buildConfigurationList = 65413E941CEB65E5008BE849 /* Build configuration list for PBXNativeTarget "CopyOnWrite" */; + buildPhases = ( + 65413E891CEB65E5008BE849 /* Sources */, + 65413E8A1CEB65E5008BE849 /* Frameworks */, + 65413E8B1CEB65E5008BE849 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = CopyOnWrite; + productName = CopyOnWrite; + productReference = 65413E8D1CEB65E5008BE849 /* CopyOnWrite */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 65413E851CEB65E5008BE849 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0620; + ORGANIZATIONNAME = HSEL; + TargetAttributes = { + 65413E8C1CEB65E5008BE849 = { + CreatedOnToolsVersion = 6.2; + }; + }; + }; + buildConfigurationList = 65413E881CEB65E5008BE849 /* Build configuration list for PBXProject "CopyOnWrite" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 65413E841CEB65E5008BE849; + productRefGroup = 65413E8E1CEB65E5008BE849 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 65413E8C1CEB65E5008BE849 /* CopyOnWrite */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 65413E891CEB65E5008BE849 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 65413E911CEB65E5008BE849 /* main.cpp in Sources */, + 65413E991CEB6612008BE849 /* OneByOneMatrix.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 65413E921CEB65E5008BE849 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.9; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + }; + name = Debug; + }; + 65413E931CEB65E5008BE849 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.9; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + }; + name = Release; + }; + 65413E951CEB65E5008BE849 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 65413E961CEB65E5008BE849 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 65413E881CEB65E5008BE849 /* Build configuration list for PBXProject "CopyOnWrite" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 65413E921CEB65E5008BE849 /* Debug */, + 65413E931CEB65E5008BE849 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 65413E941CEB65E5008BE849 /* Build configuration list for PBXNativeTarget "CopyOnWrite" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 65413E951CEB65E5008BE849 /* Debug */, + 65413E961CEB65E5008BE849 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; +/* End XCConfigurationList section */ + }; + rootObject = 65413E851CEB65E5008BE849 /* Project object */; +} diff --git a/11_PUTT/CopyOnWrite/CopyOnWrite.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/11_PUTT/CopyOnWrite/CopyOnWrite.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..62b8b09 --- /dev/null +++ b/11_PUTT/CopyOnWrite/CopyOnWrite.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/11_PUTT/CopyOnWrite/CopyOnWrite.xcodeproj/project.xcworkspace/xcuserdata/clink.xcuserdatad/UserInterfaceState.xcuserstate b/11_PUTT/CopyOnWrite/CopyOnWrite.xcodeproj/project.xcworkspace/xcuserdata/clink.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..21ac3ed Binary files /dev/null and b/11_PUTT/CopyOnWrite/CopyOnWrite.xcodeproj/project.xcworkspace/xcuserdata/clink.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/11_PUTT/CopyOnWrite/CopyOnWrite.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/CopyOnWrite.xcscheme b/11_PUTT/CopyOnWrite/CopyOnWrite.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/CopyOnWrite.xcscheme new file mode 100644 index 0000000..ae4057b --- /dev/null +++ b/11_PUTT/CopyOnWrite/CopyOnWrite.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/CopyOnWrite.xcscheme @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/11_PUTT/CopyOnWrite/CopyOnWrite.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/xcschememanagement.plist b/11_PUTT/CopyOnWrite/CopyOnWrite.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..a513042 --- /dev/null +++ b/11_PUTT/CopyOnWrite/CopyOnWrite.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + CopyOnWrite.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 65413E8C1CEB65E5008BE849 + + primary + + + + + diff --git a/11_PUTT/CopyOnWrite/CopyOnWrite/OneByOneMatrix.cpp b/11_PUTT/CopyOnWrite/CopyOnWrite/OneByOneMatrix.cpp new file mode 100644 index 0000000..921f8d8 --- /dev/null +++ b/11_PUTT/CopyOnWrite/CopyOnWrite/OneByOneMatrix.cpp @@ -0,0 +1,77 @@ +// +// OneByOneMatrix.cpp +// CopyOnWrite +// +// Created by clink on 17/05/16. +// Copyright (c) 2016 HSEL. All rights reserved. +// + +#include "OneByOneMatrix.h" + + +#include + +int OneByOneMatrix::s_instanceCounter=0; + + +OneByOneMatrix::OneByOneMatrix() +: m_value(-1), m_referenceCounter(0) +{ + s_instanceCounter++; +} + +OneByOneMatrix::OneByOneMatrix(int initialValue) +: m_value(initialValue), m_referenceCounter(0) +{ + s_instanceCounter++; +} + +OneByOneMatrix::OneByOneMatrix(const OneByOneMatrix& source) +: m_value(source.m_value), m_referenceCounter(source.m_referenceCounter) +{ + s_instanceCounter++; +} + +OneByOneMatrix::~OneByOneMatrix(){ + s_instanceCounter--; +} + +/* + int OneByOneMatrix::value(void) const { + return m_value; + }*/ + +OneByOneMatrix OneByOneMatrix::operator+(const OneByOneMatrix & other){ + return OneByOneMatrix(m_value + other.m_value); +} + +OneByOneMatrix::operator int(){ + return m_value; +} + +OneByOneMatrix& OneByOneMatrix::operator ++(int i){ + m_value++; + return *this; +} + + +bool OneByOneMatrix::operator==(const OneByOneMatrix& other){ + return this->m_value == other.m_value; +} + +bool OneByOneMatrix::operator!=(const OneByOneMatrix& other){ + return !(*this==other); +} + + + +bool OneByOneMatrix::instanceCountExceeds(int max) +{ + bool retval = s_instanceCounter>max; + if (retval){ + std::cout << OneByOneMatrix::s_instanceCounter << " > max=" << max << std::endl; + } + return retval; +} + + diff --git a/11_PUTT/CopyOnWrite/CopyOnWrite/OneByOneMatrix.h b/11_PUTT/CopyOnWrite/CopyOnWrite/OneByOneMatrix.h new file mode 100644 index 0000000..0eccc69 --- /dev/null +++ b/11_PUTT/CopyOnWrite/CopyOnWrite/OneByOneMatrix.h @@ -0,0 +1,42 @@ +// +// OneByOneMatrix.h +// CopyOnWrite +// +// Created by clink on 17/05/16. +// Copyright (c) 2016 HSEL. All rights reserved. +// + +#ifndef __CopyOnWrite__OneByOneMatrix__ +#define __CopyOnWrite__OneByOneMatrix__ + + +class OneByOneMatrix { + + int m_value; + + int m_referenceCounter; // refcounting + static int s_instanceCounter; // assertions +public: + OneByOneMatrix(); + explicit OneByOneMatrix(int initialValue); + OneByOneMatrix(const OneByOneMatrix&); + ~OneByOneMatrix(); + + explicit operator int(); + OneByOneMatrix operator+(const OneByOneMatrix & other); + OneByOneMatrix& operator ++(int); + bool operator==(const OneByOneMatrix& other); + bool operator!=(const OneByOneMatrix& other); + + friend class OneByOneMatrix_CopyOnWrite; + static bool instanceCountExceeds(int max); // assertions +}; + +// imagine this class as an abstraction for very large matrices + +class LargeCowMatrix { + +}; + + +#endif /* defined(__CopyOnWrite__OneByOneMatrix__) */ diff --git a/11_PUTT/CopyOnWrite/CopyOnWrite/main.cpp b/11_PUTT/CopyOnWrite/CopyOnWrite/main.cpp new file mode 100644 index 0000000..9941c93 --- /dev/null +++ b/11_PUTT/CopyOnWrite/CopyOnWrite/main.cpp @@ -0,0 +1,86 @@ +// +// main.cpp +// leistungstestatSurrogat +// +// Created by clink on 11/12/14. +// Copyright (c) 2014 HSEL. All rights reserved. +// + +#include + + +#include "OneByOneMatrix.h" + +int failCounter=0; + +typedef int NumberType; +//typedef OneByOneMatrix NumberType; +//typedef LargeCowMatrix NumberType; + + +void simpleTests(){ + NumberType i1(1); + NumberType i2(2); + NumberType i3=i1+i2; + + if (i3!=NumberType(3)){ + failCounter++; + std::cout << "fail!" << std::endl; + } + + i3++; + if (i3!=NumberType(4)){ + failCounter++; + std::cout << "fail!" << std::endl; + } + + i3=i1; + if (i3!=NumberType(1)){ + failCounter++; + std::cout << "fail!" << std::endl; + } + + if (OneByOneMatrix::instanceCountExceeds(3)){ + failCounter++; + } +} + +void arrayTests(){ + { + const int BUFSIZE=1000; + NumberType singletonValue(4711); + NumberType numbers[BUFSIZE]; + bool didFail=false; + + for(int i=0; i(color) << "m"; // blue + std::cout << text; + std::cout << "\033[0m\n"; // reset attributes +} + + + diff --git a/helpers/AnsiConsole.h b/helpers/AnsiConsole.h new file mode 100644 index 0000000..1d3ad39 --- /dev/null +++ b/helpers/AnsiConsole.h @@ -0,0 +1,34 @@ + +#include + +enum class Colors { + BLACK = 30, + RED = 31, + GREEN = 32, + YELLOW = 33, + BLUE = 34, + MAGENTA = 35, + CYAN = 36, + WHITE = 37 +}; + +class AnsiConsole { + // protected: + // can only be used by members of AnsiConsole and its + // derived classes +protected: + void hideCursor(); + void showCursor(); + void pushCursorPos(); + void popCursorPos(); + +public: + AnsiConsole(); + ~AnsiConsole(); + void clearScreen(); + void printText(int x, int y, std::string text, Colors color=Colors::BLUE); +}; + +extern AnsiConsole ansiConsole; + + diff --git a/helpers/println.hpp b/helpers/println.hpp new file mode 100644 index 0000000..7de0382 --- /dev/null +++ b/helpers/println.hpp @@ -0,0 +1,124 @@ +// +// println.hpp +// printline + + + +#ifndef println_hpp +#define println_hpp + +/* + based on: http://stackoverflow.com/questions/16084379/system-out-println-function-syntax-in-c/16085135#16085135 + initial Author: http://stackoverflow.com/users/264338/mkaes + */ + +#include +#include +#include +using namespace std; + +/* +template +void printer(T t) +{ + std::cout << t << std::endl; +} + +template +void printer(T t, U ...u) +{ + std::cout << t; + printer(u...); +}*/ + +//namespace std { + //string to_string(const string s); + //string to_string(const char* s); + + /* + inline string to_string(const string s){ + return s; + } + + inline string to_string(const char* s){ + return string(s); + }*/ + +//} + + + +/* +void println(T t) +{ + std::cout << std::to_string(t) << std::endl; +} + +template +void println(T t, U ...u) +{ + std::cout << std::to_string(t); + println(u...); +} +*/ + + +//namespace { + +// from: https://stackoverflow.com/questions/16605967/set-precision-of-stdto-string-when-converting-floating-point-values +template +std::string to_string_with_precision(const T a_value, const int n = 6) +{ + std::ostringstream out; + out << std::setprecision(n) << std::scientific << a_value; + return out.str(); +} + +template +std::string as_string(T t){ + using namespace std; + return to_string_with_precision(t); + //return to_string(t); +} + + +template <> + std::string as_string(const char * s){ + return std::string(s); +} + +template <> +std::string as_string(std::string s){ + return s; +} +//} + +template +void println(T t) +{ + std::cout << as_string(t) << std::endl; +} + +template +void println(T t, U ...u) +{ + std::cout << as_string(t); + println(u...); +} + +template +void print(T t) +{ + std::cout << as_string(t); +} + +template +void print(T t, U ...u) +{ + std::cout << as_string(t); + print(u...); +} + + + +#endif /* println_hpp */ diff --git a/xcode_projects/02_MENT_gg/02_MENT_gg.xcodeproj/project.pbxproj b/xcode_projects/02_MENT_gg/02_MENT_gg.xcodeproj/project.pbxproj new file mode 100644 index 0000000..1a36243 --- /dev/null +++ b/xcode_projects/02_MENT_gg/02_MENT_gg.xcodeproj/project.pbxproj @@ -0,0 +1,253 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 6590867D1EE9FA9400A93466 /* main_02_MENT.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6590867C1EE9FA9400A93466 /* main_02_MENT.cpp */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 6590866E1EE9F98F00A93466 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 659086701EE9F98F00A93466 /* 02_MENT_gg */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = 02_MENT_gg; sourceTree = BUILT_PRODUCTS_DIR; }; + 6590867C1EE9FA9400A93466 /* main_02_MENT.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = main_02_MENT.cpp; path = ../../../02_MENT/main_02_MENT.cpp; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 6590866D1EE9F98F00A93466 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 659086671EE9F98F00A93466 = { + isa = PBXGroup; + children = ( + 659086721EE9F98F00A93466 /* 02_MENT_gg */, + 659086711EE9F98F00A93466 /* Products */, + ); + sourceTree = ""; + }; + 659086711EE9F98F00A93466 /* Products */ = { + isa = PBXGroup; + children = ( + 659086701EE9F98F00A93466 /* 02_MENT_gg */, + ); + name = Products; + sourceTree = ""; + }; + 659086721EE9F98F00A93466 /* 02_MENT_gg */ = { + isa = PBXGroup; + children = ( + 6590867C1EE9FA9400A93466 /* main_02_MENT.cpp */, + ); + path = 02_MENT_gg; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 6590866F1EE9F98F00A93466 /* 02_MENT_gg */ = { + isa = PBXNativeTarget; + buildConfigurationList = 659086771EE9F98F00A93466 /* Build configuration list for PBXNativeTarget "02_MENT_gg" */; + buildPhases = ( + 6590866C1EE9F98F00A93466 /* Sources */, + 6590866D1EE9F98F00A93466 /* Frameworks */, + 6590866E1EE9F98F00A93466 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = 02_MENT_gg; + productName = 02_MENT_gg; + productReference = 659086701EE9F98F00A93466 /* 02_MENT_gg */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 659086681EE9F98F00A93466 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0820; + ORGANIZATIONNAME = HSEL; + TargetAttributes = { + 6590866F1EE9F98F00A93466 = { + CreatedOnToolsVersion = 8.2.1; + ProvisioningStyle = Automatic; + }; + }; + }; + buildConfigurationList = 6590866B1EE9F98F00A93466 /* Build configuration list for PBXProject "02_MENT_gg" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 659086671EE9F98F00A93466; + productRefGroup = 659086711EE9F98F00A93466 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 6590866F1EE9F98F00A93466 /* 02_MENT_gg */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 6590866C1EE9F98F00A93466 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 6590867D1EE9FA9400A93466 /* main_02_MENT.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 659086751EE9F98F00A93466 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + }; + name = Debug; + }; + 659086761EE9F98F00A93466 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + }; + name = Release; + }; + 659086781EE9F98F00A93466 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 659086791EE9F98F00A93466 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 6590866B1EE9F98F00A93466 /* Build configuration list for PBXProject "02_MENT_gg" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 659086751EE9F98F00A93466 /* Debug */, + 659086761EE9F98F00A93466 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 659086771EE9F98F00A93466 /* Build configuration list for PBXNativeTarget "02_MENT_gg" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 659086781EE9F98F00A93466 /* Debug */, + 659086791EE9F98F00A93466 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; +/* End XCConfigurationList section */ + }; + rootObject = 659086681EE9F98F00A93466 /* Project object */; +} diff --git a/xcode_projects/02_MENT_gg/02_MENT_gg.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/xcode_projects/02_MENT_gg/02_MENT_gg.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..c08ac4e --- /dev/null +++ b/xcode_projects/02_MENT_gg/02_MENT_gg.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/xcode_projects/02_MENT_gg/02_MENT_gg.xcodeproj/project.xcworkspace/xcuserdata/clink.xcuserdatad/UserInterfaceState.xcuserstate b/xcode_projects/02_MENT_gg/02_MENT_gg.xcodeproj/project.xcworkspace/xcuserdata/clink.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..0dae52c Binary files /dev/null and b/xcode_projects/02_MENT_gg/02_MENT_gg.xcodeproj/project.xcworkspace/xcuserdata/clink.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/xcode_projects/02_MENT_gg/02_MENT_gg.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/02_MENT_gg.xcscheme b/xcode_projects/02_MENT_gg/02_MENT_gg.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/02_MENT_gg.xcscheme new file mode 100644 index 0000000..3c4ce31 --- /dev/null +++ b/xcode_projects/02_MENT_gg/02_MENT_gg.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/02_MENT_gg.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xcode_projects/02_MENT_gg/02_MENT_gg.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/xcschememanagement.plist b/xcode_projects/02_MENT_gg/02_MENT_gg.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..f5cb70f --- /dev/null +++ b/xcode_projects/02_MENT_gg/02_MENT_gg.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + 02_MENT_gg.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 6590866F1EE9F98F00A93466 + + primary + + + + + diff --git a/xcode_projects/limits2/limits2.xcodeproj/project.pbxproj b/xcode_projects/limits2/limits2.xcodeproj/project.pbxproj new file mode 100644 index 0000000..13a800a --- /dev/null +++ b/xcode_projects/limits2/limits2.xcodeproj/project.pbxproj @@ -0,0 +1,255 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 659086601EE9EC6200A93466 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6590865F1EE9EC6200A93466 /* main.cpp */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 6590865A1EE9EC6200A93466 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 6590865C1EE9EC6200A93466 /* limits2 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = limits2; sourceTree = BUILT_PRODUCTS_DIR; }; + 6590865F1EE9EC6200A93466 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; + 659086661EE9ECC100A93466 /* println.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = println.hpp; path = ../../../helpers/println.hpp; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 659086591EE9EC6200A93466 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 659086531EE9EC6200A93466 = { + isa = PBXGroup; + children = ( + 6590865E1EE9EC6200A93466 /* limits2 */, + 6590865D1EE9EC6200A93466 /* Products */, + ); + sourceTree = ""; + }; + 6590865D1EE9EC6200A93466 /* Products */ = { + isa = PBXGroup; + children = ( + 6590865C1EE9EC6200A93466 /* limits2 */, + ); + name = Products; + sourceTree = ""; + }; + 6590865E1EE9EC6200A93466 /* limits2 */ = { + isa = PBXGroup; + children = ( + 659086661EE9ECC100A93466 /* println.hpp */, + 6590865F1EE9EC6200A93466 /* main.cpp */, + ); + path = limits2; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 6590865B1EE9EC6200A93466 /* limits2 */ = { + isa = PBXNativeTarget; + buildConfigurationList = 659086631EE9EC6200A93466 /* Build configuration list for PBXNativeTarget "limits2" */; + buildPhases = ( + 659086581EE9EC6200A93466 /* Sources */, + 659086591EE9EC6200A93466 /* Frameworks */, + 6590865A1EE9EC6200A93466 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = limits2; + productName = limits2; + productReference = 6590865C1EE9EC6200A93466 /* limits2 */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 659086541EE9EC6200A93466 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0820; + ORGANIZATIONNAME = HSEL; + TargetAttributes = { + 6590865B1EE9EC6200A93466 = { + CreatedOnToolsVersion = 8.2.1; + ProvisioningStyle = Automatic; + }; + }; + }; + buildConfigurationList = 659086571EE9EC6200A93466 /* Build configuration list for PBXProject "limits2" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 659086531EE9EC6200A93466; + productRefGroup = 6590865D1EE9EC6200A93466 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 6590865B1EE9EC6200A93466 /* limits2 */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 659086581EE9EC6200A93466 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 659086601EE9EC6200A93466 /* main.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 659086611EE9EC6200A93466 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + }; + name = Debug; + }; + 659086621EE9EC6200A93466 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + }; + name = Release; + }; + 659086641EE9EC6200A93466 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 659086651EE9EC6200A93466 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 659086571EE9EC6200A93466 /* Build configuration list for PBXProject "limits2" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 659086611EE9EC6200A93466 /* Debug */, + 659086621EE9EC6200A93466 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 659086631EE9EC6200A93466 /* Build configuration list for PBXNativeTarget "limits2" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 659086641EE9EC6200A93466 /* Debug */, + 659086651EE9EC6200A93466 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; +/* End XCConfigurationList section */ + }; + rootObject = 659086541EE9EC6200A93466 /* Project object */; +} diff --git a/xcode_projects/limits2/limits2.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/xcode_projects/limits2/limits2.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..c99cd96 --- /dev/null +++ b/xcode_projects/limits2/limits2.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/xcode_projects/limits2/limits2.xcodeproj/project.xcworkspace/xcuserdata/clink.xcuserdatad/UserInterfaceState.xcuserstate b/xcode_projects/limits2/limits2.xcodeproj/project.xcworkspace/xcuserdata/clink.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..6637b37 Binary files /dev/null and b/xcode_projects/limits2/limits2.xcodeproj/project.xcworkspace/xcuserdata/clink.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/xcode_projects/limits2/limits2.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/limits2.xcscheme b/xcode_projects/limits2/limits2.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/limits2.xcscheme new file mode 100644 index 0000000..3527a29 --- /dev/null +++ b/xcode_projects/limits2/limits2.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/limits2.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xcode_projects/limits2/limits2.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/xcschememanagement.plist b/xcode_projects/limits2/limits2.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..5fe8a4f --- /dev/null +++ b/xcode_projects/limits2/limits2.xcodeproj/xcuserdata/clink.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + limits2.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 6590865B1EE9EC6200A93466 + + primary + + + + + diff --git a/xcode_projects/limits2/limits2/main.cpp b/xcode_projects/limits2/limits2/main.cpp new file mode 100644 index 0000000..3fd3576 --- /dev/null +++ b/xcode_projects/limits2/limits2/main.cpp @@ -0,0 +1,26 @@ +// main.cpp +// limits2 + + + +#include "../../../helpers/println.hpp" +#include + + +int main() +{ + println("type\t sizeof\t\t lowest\t\t\t\t highest\n"); + println("float \t ",sizeof(float), "\t\t\t", + std::numeric_limits::lowest(), "\t\t", + std::numeric_limits::max()); + println("double\t ",sizeof(double), "\t\t\t", + std::numeric_limits::lowest(), "\t\t", + std::numeric_limits::max()); + println("int \t ",sizeof(int), "\t\t\t", + std::numeric_limits::lowest(), "\t\t\t", + std::numeric_limits::max()); + println("long \t ",sizeof(long), " \t\t", + std::numeric_limits::lowest(), '\t', + std::numeric_limits::max()); + + }