C++ 050 Memory Static Params
C++ 050 Memory Static Params
Parameters
c
raise_reset_program() on_reset_program() on_ignition_off() t
raise_reset_all_programs() on_reset_all_programs() on_ignition_on() i
raise_eeprom_changed() on_eeprom_changed() reset_program() o
raise_memlev el_down() reset_all_programs() n
<<ctor>> init()
raise_memlev el_up() Create()
Impl_Tripdistance_A UDI C
Impl_Tripdistance
Program a
Data_Adapter l
c
calc_v alue() : v oid u
display () : v oid Imp_Triptime_Alarm l
ignition_on() : v oid Impl_Triptime_A larm_A UDI a
ignition_off() : void t
i
reset() : v oid Impl_Triptime o
<<?>> eeprom_changed() : ... n
need_recalc() : bool
Impl_Mean_C onsumption_A U DI S
Impl_Mean_C onsumption e
Impl_Average_Speed
clear()
Impl_Range
write_str()
<<draft>> w rite_sy mbol()
<<ctor>> init()
D
i
s
Display _Triptime_A larm_A U DI p
Display_Triptime_A larm l
Display_V alue a
O SEK-VGC y
(from SYS) show(v alue : dword) : v oid Display _Mean_C onsumtion_A U DI
Display _Mean_C onsumption S
e
c
t
i
O SEK-win32 Display_C urrent_C onsumption_A U DIo
Display _C urrent_C onsumption
(from SYS) n
"classes " of lefthand coloumns in the middel build up the trip computer core. The classes on the right side all
coloumn act as inerface to A ll code has to be independent of manufacturer. belong to the A UDI package
hareware and O S. They and are not part of the main class
are declared abstract in the The Impl_XXX and Display_XXX classes describe what flav ours of program hierarchy.
main class hierarchy and functionality are expected
implemented in several They are included to show where
SYS packages. the main class hierarchy has to be
expanded for manufactorer's
requirements
Wrap-Up
Advanced Programming Techniques, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 2
Part One
Advanced Programming Techniques, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 3
To be done: Copy constructor for matrix
Life demo
Naive copy constructor
Advanced Programming Techniques, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 4
Shallow and deep copy
Shallow copy
Original Changes of the dynamic data
Pointer attribute
made by either the original or
copy Dyn. Data the copied object are visible
to both
Copy
Pointer attribute
Deep copy
Changes of the dynamic data
Original made by either the original or
Dyn. Data
Pointer attribute the copied object are effect
copy only the object that made the
change
Copy Dyn. Data
Pointer attribute
Advanced Programming Techniques, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 5
General procedure
Advanced Programming Techniques, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 6
Copy constructor: Rules of thumb
Advanced Programming Techniques, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 7
Part Two
Advanced Programming Techniques, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 8
Member versus static variables
m1.
object m1 memberVariable
class::
staticVariable
m2.
object m2 memberVariable
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, adapted by Prof. Dr.-Ing. M. Lipp 27/11/14 9
Keyword static
#ifndef MEMBER_H
#define MEMBER_H
class member
{
public:
int memberVariable;
static int staticVariable;
};
#endif
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, adapted by Prof. Dr.-Ing. M. Lipp 27/11/14 10
Declaration
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, adapted by Prof. Dr.-Ing. M. Lipp 27/11/14 11
Usage
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, adapted by Prof. Dr.-Ing. M. Lipp 27/11/14 12
Don't mix up: Static Variables in Functions
When using the static members in functions, the variables gets a fixed
address on the heap instead on the stack. Consequences:
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, adapted by Prof. Dr.-Ing. M. Lipp 27/11/14 13
Static Operations
Life Demo:
Counting instances
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, adapted by Prof. Dr.-Ing. M. Lipp 27/11/14 14
Part Three
Advanced Programming Techniques, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 15
Passing Parameters
There are several ways to pass data to and from functions and
operations:
Call by value function(int parameter)
Pointer function(int* parameter)
Call by reference function(int& parameter)
Return value result = function()
C++ language
extension
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, adapted by Prof. Dr.-Ing. M. Lipp 27/11/14 16
Some pro’s and con’s
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, adapted by Prof. Dr.-Ing. M. Lipp 27/11/14 17
Using const
Compromise:
int a;
a=2*para1;
//para1 = a; //Will be rejected by compiler
return a;
}
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, adapted by Prof. Dr.-Ing. M. Lipp 27/11/14 18
Arrays
Conventions:
Declaration: int a[6];
First element a[0]
Last element a[n-1]
Pointer arithmetrics: &a[1] = &a[0] + 1 ( == sizeof(int))
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, adapted by Prof. Dr.-Ing. M. Lipp 27/11/14 19
Arrays - Access
Content
a[position] //Index
*(a+position) //Pointer
Address
a //Address of first Element
&a[0] //Address of first Element
&a[1] //Address of second element
a+1 //Address of second element
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, adapted by Prof. Dr.-Ing. M. Lipp 27/11/14 20
Passing arrays as parameters
func(int* array)
func(int array[])
func(int array[6])
Note the difference: &array now points to the pointer located on the
stack
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, adapted by Prof. Dr.-Ing. M. Lipp 27/11/14 21
Arrays of more dimensions
More dimensional arrays are possible in C++ but must be handled with
care
Conventions
Declaration: int a[3][2]
First element: a[0][0]
Last element: a[2][1]
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, adapted by Prof. Dr.-Ing. M. Lipp 27/11/14 22
Design recommendations
Pointer for data structures which require pointer arithmetic's e.g. for
iterators. Example arrays.
Advanced Programming Techniques Prof. Dr.-Ing. P. Fromm, adapted by Prof. Dr.-Ing. M. Lipp 27/11/14 23
Wrap-Up
Advanced Programming Techniques, Prof. Dr.-Ing. P. Fromm, Prof. Dr.-Ing. M. Lipp 27/11/14 24