1 /// This is the head comment of a file. 2 3 /************************************************************************* 4 *\CopyRight: 2015.9.21-NOW,Feel free to use and modify those codes. And 5 any modifications or copies shall remain these sentence for the purpose 6 of further development and code sharing. 7 *\Module/Sys: [M]/[S]Test 8 *\Version: 1.0.0.0 9 *\Description:Use for the describ of the functions of the file. 10 *\Author: CityForNaive 11 *\Date: 2015.9.21 12 *\History: <Date> <Dev> <Behavior> 13 *\ 2015.9.21 CityForNaive Build. 14 *************************************************************************/ 15 16 #pragma once /// Use this as first option. 17 18 #ifndef _COMMENT_H_ 19 #define _COMMENT_H_ 20 #endif // _COMMENT_H_ 21 22 /// Comments of the definations as follow. 23 24 #define _TEST_SUCCEED 1 /** Test succeed. */ 25 #define _TEST_PARTIAL_SUCCEED 2 /** Test partial succeed. */ 26 #define _TEST_FAILED 0 /** Test failed. */ 27 28 /// This is the description of a class or a struct. 29 30 /** 31 *\Description:Use for the test functions. 32 *\Methods: 1.SetTester : Set the basic param of the test 33 2.GetTester : Get the result of a test. 34 *\Other: This is a C based class. 35 */ 36 class TestClass 37 : public TestBaseClass 38 { 39 public: 40 TestClass( void ); 41 virtual ~TestClass( void ); 42 43 public: 44 /** 45 *\Description:Set function for the test class. 46 *\Input: 1.const int& param1, the first param of the func. 47 2.const int& param2, the second param of the func. 48 *\Output: None. 49 *\Return: const int : _TEST_SUCCEED, succeed 50 _TEST_PARTIAL_SUCCEED, partial succeed 51 _TEST_FAILED, failed. 52 *\Other: None. 53 */ 54 const int SetTester( const int& param1, const int& param2 ); 55 56 /** 57 *\Description:Get the result of a test. 58 *\Input: 1.const int& token1, the first token of the func. 59 2.const int& token2, the second token of the func. 60 *\Output: 1.int& result, the result of the test. 61 *\Return: const int : _TEST_SUCCEED, succeed 62 _TEST_PARTIAL_SUCCEED, partial succeed 63 _TEST_FAILED, failed. 64 *\Other: None. 65 */ 66 const int GetTester( const int& token1, const int& token2, 67 int& result ); 68 69 private: 70 int m_iParamFrst; /// The first param of the test. 71 int m_iParamScnd; /// The second param of the test. 72 }; // TestClass 73 74 /// The comments in detailed code lines. 75 76 /// I intended that the implementation of a method shall be in another file. 77 78 /** Set function for the test class. */ 79 int TestClass::SetTester( const int& param1, const int& param2 ) 80 { 81 int rtnVal; // The return value of this function 82 rtnVal = _TEST_FAILED; 83 84 // Set the param of the test 85 if ( param1 >= 0 && param2 >= 0 ) 86 { 87 rtnVal = _TEST_SUCCEED; 88 } 89 else if ( param1 >= 0 || param2 >= 0 ) 90 { 91 rtnVal = _TEST_PARTIAL_SUCCEED; 92 } 93 else 94 { 95 rtnVal = _TEST_FAILED; 96 } 97 98 m_iParamFrst = param1; 99 m_iParamScnd = param2; 100 101 return rtnVal; 102 } 103 104 /** Get the result of a test. */ 105 int TestClass::GetTester( const int& token1, const int& token2, int& result ) 106 { 107 int rtnVal; // The return value of this function 108 rtnVal = _TEST_FAILED; 109 110 // Judge the token to decide the result 111 if ( token1 == m_iParamFrst && token2 == m_iParamScnd ) 112 { 113 result = m_iParamFrst * m_iParamScnd; 114 rtnVal = _TEST_SUCCEED; 115 } 116 else if ( token1 == m_iParamFrst || token2 == m_iParamScnd ) 117 { 118 result = m_iParamFrst / m_iParamScnd; 119 rtnVal = _TEST_PARTIAL_SUCCEED; 120 } 121 else 122 { 123 result = 0; 124 rtnVal = _TEST_FAILED; 125 } 126 127 return rtnVal; 128 } 129 130 /// For interface that we just write the brief of the function. 131 132 class __declspec( novtable ) ITestInterface 133 { 134 public: 135 /** This is a function of the interface. */ 136 virtual void func( const int& param, const char* charParam ) = 0; 137 }; 138 139 /// here we can also use EXTERN_C instead of extern "C" if under VS. 140 extern "C" __declspec( dllexport ) ITestInterface* getTestInterface();
以上是换了一家公司之后,根据公司内部的 code rule 自己整理的自己以后进行编码的参考格式(当然,现在这家并不是做什么开源项目的:3>)
时间: 2024-10-21 02:58:09