fi [rad] | fi [deg] | cos(x+fi) | sin(x+fi) | cos(fi-x) | sin(fi-x) | ||
-pi | -180 | -cos(x) | -sin(x) | -cos(x) | sin(x) | ||
-pi/2 | -90 | sin(x) | -cos(x) | -sin(x) | -cos(x) | ||
0 | 0 | cos(x) | sin(x) | cos(x) | -sin(x) | ||
+pi/2 | 90 | -sin(x) | cos(x) | sin(x) | cos(x) | ||
+pi | 180 | -cos(x) | -sin(x) | -cos(x) | sin(x) | ||
2019-01-24
Trigonometric Identities
Phase rotation table of sin and cos
C++ Inheritance
Inheritance is a feature in which you can have a class inherit variables and methods from another class without writing them over and over from scratch.
operator ":" is used to specify inheritance
In the class header you inherit the definition
Derived : Parent
The derived constructor will call the default parent constructor if you declare the constructor naked. Same for the destructor.
it is possible for the derived constructor to call the initialized parent constructor with the operator ":" in the implementation.
The parent constructor will be called BEFORE the derived constructor.
The parent destructor will be called AFTER the derived destructor.
This is valid for methods as well. You can have two methods with the same name in derived and parent class, and the derived implementation will be favored.
Example.
In your program you need to handle humans and students.
Humans have several characteristics. Name, age and gender.
Students have several characteristics. Name, age, gender and id.
Student has all the characteristics of a human with some additions.
Inheritance allows the class student to inherit all the variables and methods from the class human while adding some that are unique to the class student.
Full code
First I define the parent class with header and implementation.
Parent Class Header
XXX
Parent Class Implementation
XXX
With this I defined the class human with the characteristics Name, age and gender.
Now to Make the class student I can Inherit Name, age and gender from the parent class human, while adding just variables and handler for the last characteristic the id which is unique to the Derived class
Derived Class Header
END
Derived Class Implementation
END
operator ":" is used to specify inheritance
In the class header you inherit the definition
Derived : Parent
The derived constructor will call the default parent constructor if you declare the constructor naked. Same for the destructor.
it is possible for the derived constructor to call the initialized parent constructor with the operator ":" in the implementation.
The parent constructor will be called BEFORE the derived constructor.
The parent destructor will be called AFTER the derived destructor.
This is valid for methods as well. You can have two methods with the same name in derived and parent class, and the derived implementation will be favored.
Example.
In your program you need to handle humans and students.
Humans have several characteristics. Name, age and gender.
Students have several characteristics. Name, age, gender and id.
Student has all the characteristics of a human with some additions.
Inheritance allows the class student to inherit all the variables and methods from the class human while adding some that are unique to the class student.
Full code
First I define the parent class with header and implementation.
Parent Class Header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**************************************************************************** | |
** Parent Class | |
** Human | |
***************************************************************************** | |
** PARAMETER: | |
** RETURN: | |
** DESCRIPTION: | |
****************************************************************************/ | |
class Human | |
{ | |
//Visible to all | |
public: | |
///-------------------------------------------------------------------------- | |
/// CONSTRUCTORS | |
///-------------------------------------------------------------------------- | |
//Empty constructor | |
Human( void ); | |
//Initialized constructor | |
Human( bool f_male, int age, std::string name ); | |
///-------------------------------------------------------------------------- | |
/// DESTRUCTORS | |
///-------------------------------------------------------------------------- | |
//Default destructor | |
~Human( void ); | |
///-------------------------------------------------------------------------- | |
/// SETTERS | |
///-------------------------------------------------------------------------- | |
//set the age of the human | |
bool set_age( int age ); | |
//set the gender of the human | |
bool set_gender( bool f_male ); | |
//set the name of the human | |
bool set_name( std::string name ); | |
///-------------------------------------------------------------------------- | |
/// GETTERS | |
///-------------------------------------------------------------------------- | |
//Get the age of the human | |
int get_age( void ); | |
//get the gender of the human | |
bool get_gender( void ); | |
//get the name of the human | |
std::string get_name( void ); | |
///-------------------------------------------------------------------------- | |
/// TESTERS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// PUBLIC METHODS | |
///-------------------------------------------------------------------------- | |
//Show Human parameters | |
bool show( void ); | |
///-------------------------------------------------------------------------- | |
/// PUBLIC VARS | |
///-------------------------------------------------------------------------- | |
const int min_age = 0; | |
//Visible to derived classes | |
protected: | |
///-------------------------------------------------------------------------- | |
/// PROTECTED METHODS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// PROTECTED VARS | |
///-------------------------------------------------------------------------- | |
//Visible only inside the class | |
private: | |
///-------------------------------------------------------------------------- | |
/// PRIVATE METHODS | |
///-------------------------------------------------------------------------- | |
//Here so that i can easly copy the code. | |
bool dummy( void ); | |
///-------------------------------------------------------------------------- | |
/// PRIVATE VARS | |
///-------------------------------------------------------------------------- | |
//true = the human is male. | false = the human is female | |
bool g_f_male; | |
//age of the human | |
int g_age; | |
//name of the human | |
std::array<char, MAX_NAME_LENGTH> g_name; | |
}; //End Class: Human |
Parent Class Implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**************************************************************************** | |
** Empty constructor | |
** | |
***************************************************************************** | |
** PARAMETER: | |
** RETURN: | |
** DESCRIPTION: | |
****************************************************************************/ | |
Human::Human( void ) | |
{ | |
///-------------------------------------------------------------------------- | |
/// STATIC VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// LOCAL VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// CHECK | |
///-------------------------------------------------------------------------- | |
//Trace Enter | |
DENTER(); | |
///-------------------------------------------------------------------------- | |
/// INITIALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// BODY | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// FINALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// RETURN | |
///-------------------------------------------------------------------------- | |
//Trace Return | |
DRETURN(); | |
return; | |
} //end constructor: void | |
/**************************************************************************** | |
** Initialized constructor | |
** Human | bool, int | |
***************************************************************************** | |
** PARAMETER: | |
** RETURN: | |
** DESCRIPTION: | |
****************************************************************************/ | |
Human::Human( bool f_male, int age, string name ) | |
{ | |
///-------------------------------------------------------------------------- | |
/// STATIC VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// LOCAL VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// CHECK | |
///-------------------------------------------------------------------------- | |
//Trace Enter | |
DENTER_ARG("gender: %s, age: %d\n", GENDER_TO_STR(f_male), age ); | |
///-------------------------------------------------------------------------- | |
/// INITIALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// BODY | |
///-------------------------------------------------------------------------- | |
//Set class variabiles | |
this -> set_gender( f_male ); | |
this -> set_age( age ); | |
this -> set_name( name ); | |
///-------------------------------------------------------------------------- | |
/// FINALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// RETURN | |
///-------------------------------------------------------------------------- | |
//Trace Return | |
DRETURN(); | |
return; | |
} //end constructor: void | |
/**************************************************************************** | |
***************************************************************************** | |
** DESTRUCTORS | |
***************************************************************************** | |
****************************************************************************/ | |
/**************************************************************************** | |
** Empty Destructor | |
** | |
***************************************************************************** | |
** PARAMETER: | |
** RETURN: | |
** DESCRIPTION: | |
****************************************************************************/ | |
Human::~Human( void ) | |
{ | |
///-------------------------------------------------------------------------- | |
/// STATIC VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// LOCAL VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// CHECK | |
///-------------------------------------------------------------------------- | |
//Trace Enter | |
DENTER(); | |
///-------------------------------------------------------------------------- | |
/// INITIALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// BODY | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// FINALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// RETURN | |
///-------------------------------------------------------------------------- | |
//Trace Return | |
DRETURN(); | |
return; | |
} //end empty constructor | |
/**************************************************************************** | |
***************************************************************************** | |
** SETTERS | |
***************************************************************************** | |
****************************************************************************/ | |
/**************************************************************************** | |
** Public Setter | |
** set_gender | bool | |
***************************************************************************** | |
** PARAMETER: | |
** RETURN: | |
** DESCRIPTION: | |
****************************************************************************/ | |
bool Human::set_gender( bool f_male ) | |
{ | |
///-------------------------------------------------------------------------- | |
/// STATIC VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// LOCAL VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// CHECK | |
///-------------------------------------------------------------------------- | |
//Trace Enter | |
DENTER_ARG("gender: %s\n", GENDER_TO_STR(f_male)); | |
///-------------------------------------------------------------------------- | |
/// INITIALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// BODY | |
///-------------------------------------------------------------------------- | |
//Set the gender | |
this -> g_f_male = f_male; | |
///-------------------------------------------------------------------------- | |
/// FINALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// RETURN | |
///-------------------------------------------------------------------------- | |
//Trace Return | |
DRETURN(); | |
return false; //OK | |
} //end function: set_gender | bool | |
/**************************************************************************** | |
** Public Setter | |
** set_age | int | |
***************************************************************************** | |
** PARAMETER: | |
** RETURN: | |
** DESCRIPTION: | |
****************************************************************************/ | |
bool Human::set_age( int age ) | |
{ | |
///-------------------------------------------------------------------------- | |
/// STATIC VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// LOCAL VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// CHECK | |
///-------------------------------------------------------------------------- | |
//Trace Enter | |
DENTER_ARG("age: %d\n", age); | |
if ((age < MIN_AGE) || (age > MAX_AGE)) | |
{ | |
return true; //Fail: bad age | |
} | |
///-------------------------------------------------------------------------- | |
/// INITIALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// BODY | |
///-------------------------------------------------------------------------- | |
this -> g_age = age; | |
///-------------------------------------------------------------------------- | |
/// FINALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// RETURN | |
///-------------------------------------------------------------------------- | |
//Trace Return | |
DRETURN(); | |
return false; //OK | |
} //end function: set_age | int | |
/**************************************************************************** | |
** Public Method | |
** set_name | std::string | |
***************************************************************************** | |
** PARAMETER: | |
** RETURN: | |
** DESCRIPTION: | |
** Set name of the human | |
****************************************************************************/ | |
bool Human::set_name( std::string name ) | |
{ | |
///-------------------------------------------------------------------------- | |
/// STATIC VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// LOCAL VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// CHECK | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// INITIALIZATIONS | |
///-------------------------------------------------------------------------- | |
//Trace Enter | |
DENTER_ARG("name: %s\n", &name[0]); | |
//if: bad size | |
if (name.size() >= this -> g_name.size() ) | |
{ | |
DPRINT("ERR: bad size | source: %d dest: %d\n", name.size(), this -> g_name.size()); | |
return true; //FAIL | |
} | |
///-------------------------------------------------------------------------- | |
/// BODY | |
///-------------------------------------------------------------------------- | |
//Copy name | |
std::copy( name.begin(), name.end(), this -> g_name.begin() ); | |
//append terminator | |
this -> g_name[ name.size() ] = '\0'; | |
///-------------------------------------------------------------------------- | |
/// FINALIZATIONS | |
///-------------------------------------------------------------------------- | |
//Trace Return | |
DRETURN(); | |
return false; //OK | |
} //end method: set_name | std::string | |
/**************************************************************************** | |
***************************************************************************** | |
** GETTERS | |
***************************************************************************** | |
****************************************************************************/ | |
/**************************************************************************** | |
** Public Getter | |
** get_gender | void | |
***************************************************************************** | |
** PARAMETER: | |
** RETURN: | |
** DESCRIPTION: | |
****************************************************************************/ | |
bool Human::get_gender( void ) | |
{ | |
///-------------------------------------------------------------------------- | |
/// STATIC VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// LOCAL VARIABILE | |
///-------------------------------------------------------------------------- | |
bool f_ret; | |
///-------------------------------------------------------------------------- | |
/// CHECK | |
///-------------------------------------------------------------------------- | |
//Trace Enter | |
DENTER(); | |
///-------------------------------------------------------------------------- | |
/// INITIALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// BODY | |
///-------------------------------------------------------------------------- | |
f_ret = this -> g_f_male; | |
///-------------------------------------------------------------------------- | |
/// FINALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// RETURN | |
///-------------------------------------------------------------------------- | |
//Trace Return | |
DRETURN_ARG( "%s\n" ,GENDER_TO_STR( f_ret )); | |
return f_ret; | |
} //end function: | |
/**************************************************************************** | |
** Public Getter | |
** get_age | void | |
***************************************************************************** | |
** PARAMETER: | |
** RETURN: | |
** DESCRIPTION: | |
****************************************************************************/ | |
int Human::get_age( void ) | |
{ | |
///-------------------------------------------------------------------------- | |
/// STATIC VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// LOCAL VARIABILE | |
///-------------------------------------------------------------------------- | |
int age; | |
///-------------------------------------------------------------------------- | |
/// CHECK | |
///-------------------------------------------------------------------------- | |
//Trace Enter | |
DENTER(); | |
///-------------------------------------------------------------------------- | |
/// INITIALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// BODY | |
///-------------------------------------------------------------------------- | |
age = this -> g_age; | |
///-------------------------------------------------------------------------- | |
/// FINALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// RETURN | |
///-------------------------------------------------------------------------- | |
//Trace Return | |
DRETURN_ARG("age: %d\n", age); | |
return age; | |
} //end function: get_age | void |
With this I defined the class human with the characteristics Name, age and gender.
Now to Make the class student I can Inherit Name, age and gender from the parent class human, while adding just variables and handler for the last characteristic the id which is unique to the Derived class
Derived Class Header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**************************************************************************** | |
** Derived Class | |
** Student | |
***************************************************************************** | |
** PARAMETER: | |
** RETURN: | |
** DESCRIPTION: | |
** Class Student inherit from class Human | |
** A student is a special type of human | |
****************************************************************************/ | |
class Student: public Human | |
{ | |
//Visible to all | |
public: | |
///-------------------------------------------------------------------------- | |
/// CONSTRUCTORS | |
///-------------------------------------------------------------------------- | |
//Empty constructor | |
Student( void ); | |
//Initialized constructor | |
Student( bool f_male, int age, std::string name, int id ); | |
///-------------------------------------------------------------------------- | |
/// DESTRUCTORS | |
///-------------------------------------------------------------------------- | |
//Default destructor | |
~Student( void ); | |
///-------------------------------------------------------------------------- | |
/// SETTERS | |
///-------------------------------------------------------------------------- | |
//Set student id | |
bool set_id( int id ); | |
///-------------------------------------------------------------------------- | |
/// GETTERS | |
///-------------------------------------------------------------------------- | |
//Get student id | |
int get_id( void ); | |
///-------------------------------------------------------------------------- | |
/// TESTERS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// PUBLIC METHODS | |
///-------------------------------------------------------------------------- | |
//Base class has a method show of the same name. This wins out hiding Human::show() | |
bool show( void ); | |
///-------------------------------------------------------------------------- | |
/// PUBLIC VARS | |
///-------------------------------------------------------------------------- | |
//Visible to derived classes | |
protected: | |
///-------------------------------------------------------------------------- | |
/// PROTECTED METHODS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// PROTECTED VARS | |
///-------------------------------------------------------------------------- | |
//Visible only inside the class | |
private: | |
///-------------------------------------------------------------------------- | |
/// PRIVATE METHODS | |
///-------------------------------------------------------------------------- | |
//Here so that i can easly copy the code. | |
bool dummy( void ); | |
///-------------------------------------------------------------------------- | |
/// PRIVATE VARS | |
///-------------------------------------------------------------------------- | |
//student id number | |
int g_id; | |
}; //End Class: Student |
Derived Class Implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**************************************************************************** | |
** Empty Constructor | |
** Student | void | |
***************************************************************************** | |
** PARAMETER: | |
** RETURN: | |
** DESCRIPTION: | |
****************************************************************************/ | |
Student::Student( void ) | |
{ | |
///-------------------------------------------------------------------------- | |
/// STATIC VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// LOCAL VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// CHECK | |
///-------------------------------------------------------------------------- | |
//Trace Enter main | |
DENTER(); | |
///-------------------------------------------------------------------------- | |
/// INITIALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// BODY | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// FINALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// RETURN | |
///-------------------------------------------------------------------------- | |
//Trace Return | |
DRETURN(); | |
return; | |
} //end constructor: Student | void | |
/**************************************************************************** | |
** Initialized constructor | |
** Student | int | |
***************************************************************************** | |
** PARAMETER: | |
** RETURN: | |
** DESCRIPTION: | |
** By default only the empty constructor Human::Human(void) is executed | |
** In this case I specifically call the initialized constructor with given parameters | |
** The parent constructor Human is executed before the derived constructor | |
****************************************************************************/ | |
Student::Student( bool f_male, int age, std::string name, int id ) : Human( f_male, age, name ) | |
{ | |
///-------------------------------------------------------------------------- | |
/// STATIC VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// LOCAL VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// CHECK | |
///-------------------------------------------------------------------------- | |
//Trace Enter main | |
DENTER_ARG("gender: %s, age: %d, name: %s, id: %d\n", GENDER_TO_STR(f_male), age, &name[0], id ); | |
///-------------------------------------------------------------------------- | |
/// INITIALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// BODY | |
///-------------------------------------------------------------------------- | |
//Set class variabiles | |
this -> set_id( id ); | |
///-------------------------------------------------------------------------- | |
/// FINALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// RETURN | |
///-------------------------------------------------------------------------- | |
//Trace Return | |
DRETURN(); | |
return; | |
} //end constructor: | |
/**************************************************************************** | |
***************************************************************************** | |
** DESTRUCTORS | |
***************************************************************************** | |
****************************************************************************/ | |
/**************************************************************************** | |
** Default Destructor | |
** | |
***************************************************************************** | |
** PARAMETER: | |
** RETURN: | |
** DESCRIPTION: | |
****************************************************************************/ | |
Student::~Student( void ) | |
{ | |
///-------------------------------------------------------------------------- | |
/// STATIC VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// LOCAL VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// CHECK | |
///-------------------------------------------------------------------------- | |
//Trace Enter main | |
DENTER(); | |
///-------------------------------------------------------------------------- | |
/// INITIALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// BODY | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// FINALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// RETURN | |
///-------------------------------------------------------------------------- | |
//Trace Return | |
DRETURN(); | |
return; | |
} //end empty constructor | |
/**************************************************************************** | |
***************************************************************************** | |
** SETTERS | |
***************************************************************************** | |
****************************************************************************/ | |
/**************************************************************************** | |
** Public Setter | |
** set_id | int | |
***************************************************************************** | |
** PARAMETER: | |
** RETURN: | |
** DESCRIPTION: | |
****************************************************************************/ | |
bool Student::set_id( int id ) | |
{ | |
///-------------------------------------------------------------------------- | |
/// STATIC VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// LOCAL VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// CHECK | |
///-------------------------------------------------------------------------- | |
//Trace Enter main | |
DENTER_ARG("id: %d\n", id); | |
if (id < 0) | |
{ | |
//bad age | |
return true; | |
} | |
///-------------------------------------------------------------------------- | |
/// INITIALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// BODY | |
///-------------------------------------------------------------------------- | |
g_id = id; | |
///-------------------------------------------------------------------------- | |
/// FINALIZATIONS | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// RETURN | |
///-------------------------------------------------------------------------- | |
//Trace Return | |
DRETURN(); | |
return false; //OK | |
} //end function: set_id | int | |
/**************************************************************************** | |
***************************************************************************** | |
** GETTERS | |
***************************************************************************** | |
****************************************************************************/ | |
/**************************************************************************** | |
***************************************************************************** | |
** TESTERS | |
***************************************************************************** | |
****************************************************************************/ | |
/**************************************************************************** | |
***************************************************************************** | |
** PUBLIC METHODS | |
***************************************************************************** | |
****************************************************************************/ | |
/**************************************************************************** | |
** Public Method | |
** show | void | |
***************************************************************************** | |
** PARAMETER: | |
** RETURN: | |
** DESCRIPTION: | |
** There is a method show in the base class Human | |
** I declare a show method for the derived class Student | |
** This method hides the Human::show method | |
** I can explicitally call Human::show and expand it without rewriting more code | |
****************************************************************************/ | |
bool Student::show( void ) | |
{ | |
///-------------------------------------------------------------------------- | |
/// STATIC VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// LOCAL VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// CHECK | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// INITIALIZATIONS | |
///-------------------------------------------------------------------------- | |
//Trace Enter | |
DENTER(); | |
///-------------------------------------------------------------------------- | |
/// BODY | |
///-------------------------------------------------------------------------- | |
//Explicitaly call the Human show method | |
this -> Human::show(); | |
//Expand the Human::Show method with what's needed by Student::show | |
cout << "Student parameters" << endl; | |
cout << "Id: " << this -> g_id << endl; | |
///-------------------------------------------------------------------------- | |
/// FINALIZATIONS | |
///-------------------------------------------------------------------------- | |
//Trace Return | |
DRETURN(); | |
return false; //OK | |
} //end method: show | void | |
/**************************************************************************** | |
***************************************************************************** | |
** PRIVATE METHODS | |
***************************************************************************** | |
****************************************************************************/ | |
/**************************************************************************** | |
** Public Method | |
** | |
***************************************************************************** | |
** PARAMETER: | |
** RETURN: | |
** DESCRIPTION: | |
****************************************************************************/ | |
bool Student::dummy( void ) | |
{ | |
///-------------------------------------------------------------------------- | |
/// STATIC VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// LOCAL VARIABILE | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// CHECK | |
///-------------------------------------------------------------------------- | |
if (false) | |
{ | |
std::cerr << __FUNCTION__ << ":\n"; | |
return true; //Fail | |
} | |
///-------------------------------------------------------------------------- | |
/// INITIALIZATIONS | |
///-------------------------------------------------------------------------- | |
//Trace Enter main | |
DENTER(); | |
///-------------------------------------------------------------------------- | |
/// BODY | |
///-------------------------------------------------------------------------- | |
///-------------------------------------------------------------------------- | |
/// FINALIZATIONS | |
///-------------------------------------------------------------------------- | |
//Trace Return from main | |
DRETURN(); | |
return false; //OK | |
} //end method: |
2019-01-23
QT Signals Slots
Signals and slots are like direct links. It's an event system where a signal will pass its arguments to the connected slot. It's similar to python and probably the most peculiar feature of QT.
The Signal slots paradigm makes GUI desing a lot simpler. Something happens->do something else. They are also thread safe for good measure.
Internally QT will translate signals slots and connect in real C++ code in meta C++ files before the real compilation begins.
Here I added a slot to the main class. It's a public method with a macro definition used by QT for his translation into real C++ code.
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
public Q_SLOTS:
void txt_update( int num );
private:
Ui::MainWindow *ui;
};
The slots take care of writing an integer inside a line control
void MainWindow::txt_update( int num ) { User::Qt_utils::qline_show_int( ui ->txt, num ); }
I have an object with a signal. The signal too is public and declared as macro.
class Sender : public QObject { Q_OBJECT public: Sender(); Q_SIGNALS: void send( int num ); };
Here is the code inside the constructor of the main window.
I create the sender object.
I call directly the slot to update the control and initialize it.
I connect the sender output with the slot input.
I call the sender object which will pass it's argument to the slot automagically!
//I can call a slot directly //This slot is set to update the txt control wint an integer when called this -> txt_update( 0 ); //QT will actually add more c++ files to handle signals and slots in real C++ code //Connect the signal coming from the sender class to the slot of the Main Window class //singal and slot must have same arguments in this style of connect connect ( &my_tx, //Reference to source signal object &Sender::send, //Reference to the source signal method. It's just the definition and it's not tied to the individual object. this, //Reference to the dest slot object. In this case I use the current class instance &MainWindow::txt_update //Reference to the dest slot method. It's just the definition and it's not tied to the individual object. ); //I can send a signal by simply calling the method directly //This will cause the slot of the main class to be activated with the same argument of the sender signal my_tx.send( 17 );
QT Add a new Kit
Create a new compiler with the binaries
This is the easy part.
ABI is not functional, is just used to
sign the compiler and for QT to detect inconsistencies.
Here is
where things get hard
QMAKE create a makefile. It uses .pro
and a configuration file stored in the mkspec folder of the QT kit to
configure everything. You need QMAKE.CONF and QPLATFORMDEFS.H
configured properly for everything to works and for the makefile to
be done the right way.
QT needs to be built USING the kit
compiler in order to generate all the QT dll.
Those .dll are required for the binary
to work and have to be bundled with the application.
STATIC:
Creating a static application with QT
is a nightmare. In order to do it you need static libs, not dinamic
link libraries, and to do so you need to recompile QT the right way
with the right compiler to generate them.
After that you need to configure the
kit to make a static compilation.
“Shadow built” is used to output in
a folder different from the source project
“qmake” is the command line that is
effectively being executed to create the makefile
“make” is used to call the compiler
with all dependencies and generate the binaries
“Build environment” is used to add
the paths required to build, like the compiler include and lib
folders, the compiler binaries, etc...
The hardest thing to do is to configure
QMAKE to generate the makefile the right way with all dependencies.
This is the final thing that ties all
together
“File System Name” is useless
“Sysroot” is used to specify the
system libraries. Works without but results in the binary duplicating
some dependency/library.
“Compiler” is the one specified in
the compiler slide
“QT Version” specifies the binaries
and QT dll to use. If you target arm you need the QT dll compiled for
arm to bundle with the binary for it to work
Qt mkspec is where the configuration
file used by qmake to generate the makefile lay
To deploy an application so that it can
be executed without the QT toolchain you need to bundle in all the
.dll dependencies.
The easiest way to do so is to execute
and bring in the .dll that causes trouble.
Take care to bundle the right .dll. One
compiled for another architecture, or with the right architecture but
the wrong compiler won't work. You can find the .dll of QT here:
Each kit in the /bin folder has all the
.dll compiled with the kit. You need to bundle them with the
executable of your project or setup a system variable to tell where
to find them.
2019-01-22
Unit of Measures
Sheet 1: Unit Measures
Unit | SI | SI+N | SI+V | SI+W | SI+J | |||
Distance | Meter | m | m | |||||
Mass | Kilogram | Kg | Kg | |||||
Time | Second | s | s | |||||
Current | Ampere | A | A | |||||
Speed | m/s | |||||||
Acceleration | m/s2 | |||||||
Jerk | m/s3 | |||||||
Force[N]=mass[Kilograms]*Acceleration[m/s2] | Force | Newton | N | Kg*m/s2 | ||||
Energy[J]=Torque[N*m]*Angle[rad] | Torque | Kg*m2/s2 | N*m/rad | J/rad | ||||
Charge | Coulomb | C | A*s | |||||
Voltage[V]=Power[Kg*m2/s2]/Current[A] | Voltage | Volt | V | Kg*m2/s2/A | ||||
Angular Inertia | J | Kg*m2 | ||||||
Capacitance | Farad | F | s4*A2/m2/Kg | A*s/V | ||||
Inductance | Henry | H | Kg*m2/s2/A2 | V*s/A | J/A2 | |||
Electric Field[V/m]=Voltage[V]/Distance[m] | Electric Field | E | Kg*m/A/s3 | V/m | ||||
Magnetic Field | Tesla | T | Kg/A/s2 | N/A/m | V*s/m2 | J/A/m2 | ||
Energy[J]=Force[N]*Displacement[m] | Energy | Joule | J | Kg*m2/s2 | N*m | |||
Energy[J]=int{Power[W]*dt[S]} | Energy | Joule | J | W*s | ||||
Energy[J]=0.5*Voltage[V]^2*Capacitance[F] | ||||||||
Energy[J]=0.5*Current[A]^2*Inductance[H] | ||||||||
Energy[J] = electrostatic permeattivity[F/m] *Electric field[V/m]^2 *volume[m3] | ||||||||
Energy[J] = 1/magnetic permeability[H/m] *Magnetic Field[T]^2 *volume[m3] | ||||||||
Power[W]=Voltage[V]*Current[A] | Power | Watt | W | Kg*m2/s2 | V*A | |||
Power | Power | Watt | W | V*A | ||||
Volumetric Density | ro | Kg/m3 | ||||||
Charge Density | ro_q | C/m3 | ||||||
Current Density | J | A/m2 | ||||||
Resistence | Ohm | Ohm | Kg*m2/s3/A2 | V/A | ||||
Magnetic Field [T] = magnetic constant [H/m] *Current[A] /2pi /Distance[m] | ||||||||
Force[N] = Length[m] * Current [A] x Magnetic Field [T] |
Subscribe to:
Posts (Atom)