いろいろなテクニック.Nucleo と DISCO-F746 用.

Dependencies:   Array_Matrix mbed

Revision:
0:bb939e0bc6e2
Child:
1:bbb9f0c3e523
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Oct 15 11:41:48 2017 +0000
@@ -0,0 +1,142 @@
+//------------------------------------------------------------
+//  使用例:Nucleo と DISCO-746 が対象
+//
+//  mbed 公式ライブラリリビジョン 153 で OK
+//  2017/10/15, Copyright (c) 2017 MIKAMI, Naoki
+//------------------------------------------------------------
+
+#include "mbed.h"
+#pragma diag_suppress 870       // マルチバイト文字使用の warning 抑制のため
+
+//------------------------------------------------------------------------------
+//  以下で,行頭の「//」を削除して有効にした define 文 に対応する処理が実行される
+//
+//#define MY_MATH                 // 1. 算術関数の例
+//#define MY_SORT                 // 2. STL のソートの例
+//#define DYNAMIC_POLYMORPHISM    // 3. 実行時ポリモーフィズム
+//#define STL_VECTOR              // 4. STL の vecotr の例
+//#define MY_NEW                  // 5. new 演算子のメモリ割り当てエラーを検出の例
+//#define FUNCTION_OBJECT         // 6. function object の例
+//#define FUNCTION_POINTER        // 7. 関数ポインタの例
+//#define FUNCTION_POINTER_IN_CLASS   // 8. クラス内で関数ポインタを使う例
+//#define PASS_ARRAY_CONSTRUCTOR  // 9. コンストラクタに渡した Array<> を使う例
+//#define REFERENCE_ARRAY         // 10. 異なる型の Array クラスの参照の代入の例
+//#define GET_PERIPHERAL_ADDRESS  // 11. ピンの名前に対応するペリフェラルのアドレスを取得
+//#define UNION_EXAMPLE           // 12. union の使用例
+//#define INITIALIZE_STRUCT       // 13. 構造体の初期化
+//#define STRUCT_COPY             // 14. 同じ構造で異なる構造体のコピー
+#define COMPOOUND_LITERAL       // 15. 複合リテラルの使用例
+//
+//  有効にすべき define 文はここまで
+//------------------------------------------------------------------------------
+
+#include "MyMath.hpp"                   // 1. 算術関数の例
+#include "MySort.hpp"                   // 2. STL を使うソートの例
+#include "PolyMorphism.hpp"             // 3. 実行時ポリモーフィズム
+#include "MyVector.hpp"                 // 4. STL の vecotr の例
+#include "MyNew.hpp"                    // 5. new 演算子のメモリ割り当てエラーを検出の例
+#include "FunctionObject.hpp"           // 6. function object の例
+#include "FunctionPointer.hpp"          // 7. function pointer の例
+#include "FunctionPointerInClass.hpp"   // 8. クラス内で関数ポインタを使う例
+#include "PassArrayConstructor.hpp"     // 9. コンストラクタに渡した Array<> を使う例
+#include "ReferenceArray.hpp"           // 10. 異なる型の Array クラスの参照の代入の例
+#include "PeripheralAddress.hpp"        // 11. ピンの名前に対応するペリフェラルのアドレスを取得
+#include "UnionExample.hpp"             // 12. union の使用例
+#include "InitializeStruct.hpp"         // 13. 構造体の初期化
+#include "StructCopy.hpp"               // 14. 同じ構造で異なる構造体のコピー
+#include "CompoundLiteral.hpp"          // 15. 複合リテラルの使用例
+
+int main()
+{
+    printf("\r\n2017/10/15 12:54\r\n");
+//------------------------------------------------------------
+// 1 : 算術関数の例
+#ifdef MY_MATH
+    MyMath();
+#endif  // MY_MATH
+
+//------------------------------------------------------------
+// 2 : STL を使うソートの例
+#ifdef MY_SORT
+    MySort();
+#endif
+
+//------------------------------------------------------------
+// 3 : 実行時ポリモーフィズム
+#ifdef DYNAMIC_POLYMORPHISM
+    MyPolyMorphism();
+#endif
+
+//------------------------------------------------------------
+// 4 : STL の vecotr の例
+#ifdef STL_VECTOR
+    MyVector();
+#endif
+
+//------------------------------------------------------------
+// 5 : new 演算子のメモリ割り当てエラーを検出の例
+#ifdef MY_NEW
+    MyNew();
+#endif
+
+//------------------------------------------------------------
+// 6. function object の例
+#ifdef FUNCTION_OBJECT
+    MyFunctionObject();
+#endif
+    
+//------------------------------------------------------------
+// 7. function pointer の例
+#ifdef FUNCTION_POINTER
+    MyFunctionPointer();
+#endif
+
+//------------------------------------------------------------
+// 8. クラス内で関数ポインタを使う例
+#ifdef FUNCTION_POINTER_IN_CLASS
+    MyFunctionPointerClass();
+#endif
+
+//------------------------------------------------------------
+// 9. コンストラクタに渡した Array<> を使う例
+#ifdef PASS_ARRAY_CONSTRUCTOR       
+    MyPassArrayConstructor();
+#endif
+
+//------------------------------------------------------------
+// 10. 異なる型の Array クラスの参照の代入の例
+#ifdef REFERENCE_ARRAY
+    ReferenceArray();
+#endif
+
+//------------------------------------------------------------
+// 11. ピンの名前に対応するペリフェラルのアドレスを取得
+#ifdef GET_PERIPHERAL_ADDRESS
+    PeripheralAddress();
+#endif
+
+//------------------------------------------------------------
+// 12. union の使用例
+#ifdef UNION_EXAMPLE
+    UnionExample();
+#endif
+
+//------------------------------------------------------------
+// 13. 構造体の初期化
+#ifdef INITIALIZE_STRUCT
+    InitializeStruct();
+#endif
+
+//------------------------------------------------------------
+// 14. 同じ構造で異なる構造体のコピー
+#ifdef STRUCT_COPY
+    StructureCopy();    
+#endif
+
+//------------------------------------------------------------
+// 15. 複合リテラルの使用例
+#ifdef COMPOOUND_LITERAL
+    CompoundLiteral();
+#endif
+    while (true) {}
+}