Posts
[C++]使用Cppcheck靜態分析工具輔助檢查C++程式潛在問題
Syntax: cppcheck [OPTIONS] [files or paths]
If a directory is given instead of a filename, *.cpp, *.cxx, *.cc, *.c++, *.c, *.tpp, and *.txx files are checked recursively from the given directory.
Options: –append=<file> This allows you to provide information about functions by providing an implementation for them. –check-config Check cppcheck configuration. The normal code analysis is disabled by this flag. -D<ID> By default Cppcheck checks all configurations. Use -D to limit the checking.
read morePosts
[C#].NET 4.5 New Feature - Regex match with timeout
AppDomain.CurrentDomain.SetData("REGEX_DEFAULT_MATCH_TIMEOUT", TimeSpan.FromSeconds(2)); isMatch = IsMatch(input, pattern); Console.WriteLine(); isMatch = IsMatch(input, pattern, TimeSpan.FromSeconds(4)); } static Boolean IsMatch(string input, string pattern) { try { return Regex.IsMatch(input, pattern, RegexOptions.None); } catch (RegexMatchTimeoutException ex) { // handle exception Console.WriteLine("Match timed out!"); Console.WriteLine("- Timeout interval specified: " + ex.MatchTimeout); Console.WriteLine("- Pattern: " + ex.Pattern); Console.WriteLine("- Input: " + ex.Input); } return false; } static Boolean IsMatch(string input, string pattern, TimeSpan timeout) { try { return Regex.
read morePosts
[C++]C++ Nativated Property With Event Code Snippet
#pragma region Public Property public: declspec(property(get=Get$field$,put=Set$field$)) $type$ m_$field$; #pragma endregion
#pragma region Event public: __event void $field$Changing(void* sender, $eventArgs$* e); __event void $field$Changed(void* sender, $eventArgs$* e); #pragma endregion
#pragma region Property Process Method public: inline $type$ Get_$field$() { return _$field$; }
inline void Set_$field$($type$ value) { if(_$field$ == value) return; $eventArgs$ e; On$field$Changing(&e); _$field$ = value; On$field$Changed(&e); } #pragma endregion
#pragma region Protected Method protected: void On$field$Changing($eventArgs$* e) { __raise $field$Changing(this, e); }
read morePosts
[C++]C++ Nativated Property Code Snippet
#pragma region Public Property public: declspec(property(get=Get$field$,put=Set$field$)) $type$ m_$field$; #pragma endregion
#pragma region Property Process Method public: inline $type$ Get_$field$() { return _$field$; }
inline void Set_$field$($type$ value) { if(_$field$ == value) return; _$field$ = value; } #pragma endregion]]></Code> </Snippet> </CodeSnippet> </CodeSnippets>
read morePosts
[C++]C++ Create GUID
GUID *pguid = new GUID; CoCreateGuid(pguid); // Convert the GUID to a string UuidToString(pguid, (RPC_WSTR*)&guidStr); delete pguid; return wstring(guidStr); }
#include “stdafx.h” #include <objbase.h> #include <string>
using namespace std;
wstring GetGUID() { _TUCHAR *guidStr = NULL;
GUID *pguid = new GUID; CoCreateGuid(pguid); // Convert the GUID to a string UuidToString(pguid, (RPC_WSTR*)&guidStr); delete pguid; return wstring(guidStr); }
int _tmain(int argc, _TCHAR* argv[]) { wstring guid = GetGUID(); wprintf(guid.c_str()); return 0; }
read more