From a497251fb991220b5d0df2532d623cf1614d320f Mon Sep 17 00:00:00 2001 From: hxf0223 Date: Sat, 11 May 2024 14:38:47 +0800 Subject: [PATCH] add more cpp blogs --- ...2023-05-5-clang-tidy-rule-file-sample-1.md | 73 ++++ ...2023-05-5-clang-tidy-rule-file-sample-2.md | 405 ++++++++++++++++++ _posts/2023-05-5-cpp-code-snippet.md | 109 +++++ _posts/2023-05-5-design-modes-for-all.md | 110 +++++ _posts/2023-05-5-good-cpp-repo-on-github.md | 14 + ...610-install qt5 on ubuntu 22.04 for VTK.md | 24 ++ 6 files changed, 735 insertions(+) create mode 100644 _posts/2023-05-5-clang-tidy-rule-file-sample-1.md create mode 100644 _posts/2023-05-5-clang-tidy-rule-file-sample-2.md create mode 100644 _posts/2023-05-5-cpp-code-snippet.md create mode 100644 _posts/2023-05-5-design-modes-for-all.md create mode 100644 _posts/2023-05-5-good-cpp-repo-on-github.md create mode 100644 _posts/2023-0610-install qt5 on ubuntu 22.04 for VTK.md diff --git a/_posts/2023-05-5-clang-tidy-rule-file-sample-1.md b/_posts/2023-05-5-clang-tidy-rule-file-sample-1.md new file mode 100644 index 0000000..080acec --- /dev/null +++ b/_posts/2023-05-5-clang-tidy-rule-file-sample-1.md @@ -0,0 +1,73 @@ +--- +title: clang-tidy rule file sample [1] +date: 2023-05-5 +0800 # 2022-01-01 13:14:15 +0800 只写日期也行;不写秒也行;这样也行 2022-03-09T00:55:42+08:00 +categories: [cpp] +tags: [cpp] # TAG names should always be lowercase + +# 以下默认false +math: true +mermaid: true +# pin: true +--- + +文件名:`.clang-tidy` +部分检查项目中文解释:[selfboot/ClangTidyChecks](https://github.com/selfboot/ClangTidyChecks) + +```text +Checks: > +  -*, +  bugprone-*, +  -bugprone-easily-swappable-parameters, +  -bugprone-narrowing-conversions, +  -bugprone-exception-escape, +  clang-analyzer-*, +  -clang-analyzer-unix.Malloc, +  -clang-analyzer-deadcode.DeadStores, +  misc-*, +  -misc-non-private-member-variables-in-classes, +  -misc-confusable-identifiers, +  -misc-unused-parameters, +  -misc-const-correctness, +  modernize-*, +  -modernize-concat-nested-namespaces, +  -modernize-avoid-c-arrays, +  -modernize-use-trailing-return-type, +  -modernize-redundant-void-arg, +  -modernize-use-using, +  -modernize-use-nodiscard, +  -modernize-use-auto, +  -performance-unnecessary-value-param, +  portability-*, +  readability-*, +  -readability-avoid-const-params-in-decls, +  -readability-convert-member-functions-to-static, +  -readability-isolate-declaration, +  -readability-identifier-length, +  -readability-named-parameter, +  -readability-magic-numbers, +  -readability-redundant-access-specifiers, +  +CheckOptions: +- { key: readability-identifier-naming.NamespaceCase,            value: lower_case } +- { key: readability-identifier-naming.ClassCase,                value: CamelCase  } +- { key: readability-identifier-naming.StructCase,               value: CamelCase  } +- { key: readability-identifier-naming.MemberCase,               value: camelBack  } +- { key: readability-identifier-naming.TemplateParameterCase,    value: CamelCase  } +- { key: readability-identifier-naming.FunctionCase,             value: camelBack  } +- { key: readability-identifier-naming.VariableCase,             value: lower_case } +- { key: readability-identifier-naming.ParameterCase,            value: camelBack  } +- { key: readability-identifier-naming.MacroDefinitionCase,      value: UPPER_CASE } +- { key: readability-identifier-naming.EnumConstantCase,         value: CamelCase } +- { key: readability-identifier-naming.EnumConstantPrefix,       value: k         } +- { key: readability-identifier-naming.ConstexprVariableCase,    value: CamelCase } +- { key: readability-identifier-naming.ConstexprVariablePrefix,  value: k         } +- { key: readability-identifier-naming.GlobalConstantCase,       value: CamelCase } +- { key: readability-identifier-naming.GlobalConstantPrefix,     value: k         } +- { key: readability-identifier-naming.MemberConstantCase,       value: CamelCase } +- { key: readability-identifier-naming.MemberConstantPrefix,     value: k         } +- { key: readability-identifier-naming.StaticConstantCase,       value: CamelCase } +- { key: readability-identifier-naming.StaticConstantPrefix,     value: k         } +``` + + + diff --git a/_posts/2023-05-5-clang-tidy-rule-file-sample-2.md b/_posts/2023-05-5-clang-tidy-rule-file-sample-2.md new file mode 100644 index 0000000..d3c0e7c --- /dev/null +++ b/_posts/2023-05-5-clang-tidy-rule-file-sample-2.md @@ -0,0 +1,405 @@ +--- +title: clang-tidy rule file sample [2] +date: 2023-05-5 +0800 # 2022-01-01 13:14:15 +0800 只写日期也行;不写秒也行;这样也行 2022-03-09T00:55:42+08:00 +categories: [cpp] +tags: [cpp] # TAG names should always be lowercase + +# 以下默认false +math: true +mermaid: true +# pin: true +--- + +文件名:`.clang-tidy` +引用自 [cnl/.clang-tidy at main · johnmcfarlane/cnl (github.com)](https://github.com/johnmcfarlane/cnl/blob/main/.clang-tidy) + +```text +--- +Checks: > + *, + -abseil-*, + -altera-*, + -android-*, + -cert-err58-cpp, + -clang-analyzer-osx.*, + -cppcoreguidelines-avoid-magic-numbers, + -darwin-dispatch-once-nonstatic, + -fuchsia-*, + -google-build-using-namespace, + -google-readability-namespace-comments, + -google-runtime-int, + -google-runtime-references, + -hicpp-named-parameter, + -hicpp-signed-bitwise, + -llvm-namespace-comment, + -llvm-qualified-auto, + -llvmlibc-*, + -modernize-use-trailing-return-type, + -objc-*, + -openmp-*, + -readability-identifier-length, + -readability-implicit-bool-conversion, + -readability-magic-numbers, + -readability-named-parameter, + -readability-qualified-auto, + -zircon-*, + -bugprone-easily-swappable-parameters, + -cppcoreguidelines-pro-bounds-array-to-pointer-decay, + -cppcoreguidelines-pro-bounds-constant-array-index, + -cppcoreguidelines-pro-bounds-pointer-arithmetic, + -cppcoreguidelines-pro-type-vararg, + -google-readability-todo, + -hicpp-avoid-c-arrays, + -hicpp-no-array-decay, + -hicpp-vararg, + -misc-definitions-in-headers, + -misc-no-recursion, + -modernize-avoid-c-arrays, + -modernize-concat-nested-namespaces, + -modernize-unary-static-assert, + -readability-avoid-const-params-in-decls, + -readability-function-cognitive-complexity, + +WarningsAsErrors: '*' +HeaderFilterRegex: '.*' +AnalyzeTemporaryDtors: false +FormatStyle: none +User: john +CheckOptions: + - key: cert-dcl16-c.NewSuffixes + value: 'L;LL;LU;LLU' + - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic + value: '1' + - key: google-readability-braces-around-statements.ShortStatementLines + value: '1' + - key: google-readability-function-size.StatementThreshold + value: '800' + - key: google-readability-namespace-comments.ShortNamespaceLines + value: '10' + - key: google-readability-namespace-comments.SpacesBeforeComments + value: '2' + - key: modernize-loop-convert.MaxCopySize + value: '16' + - key: modernize-loop-convert.MinConfidence + value: reasonable + - key: modernize-loop-convert.NamingStyle + value: CamelCase + - key: modernize-pass-by-value.IncludeStyle + value: llvm + - key: modernize-replace-auto-ptr.IncludeStyle + value: llvm + - key: modernize-use-nullptr.NullMacros + value: 'NULL' + + + # because _impl isn't technically lower_case + # - key: readability-identifier-naming.NamespaceCase + # value: lower_case + - key: readability-identifier-naming.InlineNamespaceCase + value: lower_case + - key: readability-identifier-naming.EnumConstantCase + value: lower_case + # - key: readability-identifier-naming.ConstexprVariableCase + # value: lower_case + - key: readability-identifier-naming.ConstantMemberCase + value: lower_case + - key: readability-identifier-naming.PrivateMemberCase + value: lower_case + - key: readability-identifier-naming.ProtectedMemberCase + value: lower_case + - key: readability-identifier-naming.PublicMemberCase + value: lower_case + - key: readability-identifier-naming.MemberCase + value: lower_case + # - key: readability-identifier-naming.ClassConstantCase + # value: lower_case + # - key: readability-identifier-naming.ClassMemberCase + # value: lower_case + # - key: readability-identifier-naming.GlobalConstantCase + # value: lower_case + - key: readability-identifier-naming.GlobalConstantPointerCase + value: lower_case + - key: readability-identifier-naming.GlobalPointerCase + value: lower_case + # - key: readability-identifier-naming.GlobalVariableCase + # value: lower_case + - key: readability-identifier-naming.LocalConstantCase + value: lower_case + - key: readability-identifier-naming.LocalConstantPointerCase + value: lower_case + - key: readability-identifier-naming.LocalPointerCase + value: lower_case + - key: readability-identifier-naming.LocalVariableCase + value: lower_case + - key: readability-identifier-naming.StaticConstantCase + value: lower_case + - key: readability-identifier-naming.StaticVariableCase + value: lower_case + # - key: readability-identifier-naming.ConstantCase + # value: lower_case + # - key: readability-identifier-naming.VariableCase + # value: lower_case + - key: readability-identifier-naming.ConstantParameterCase + value: lower_case + - key: readability-identifier-naming.ParameterPackCase + value: lower_case + - key: readability-identifier-naming.ParameterCase + value: lower_case + - key: readability-identifier-naming.PointerParameterCase + value: lower_case + - key: readability-identifier-naming.ConstantPointerParameterCase + value: lower_case + - key: readability-identifier-naming.AbstractClassCase + value: lower_case + - key: readability-identifier-naming.StructCase + value: lower_case + - key: readability-identifier-naming.ClassCase + value: lower_case + - key: readability-identifier-naming.UnionCase + value: lower_case + - key: readability-identifier-naming.EnumCase + value: lower_case + - key: readability-identifier-naming.GlobalFunctionCase + value: lower_case + # - key: readability-identifier-naming.ConstexprFunctionCase + # value: lower_case + - key: readability-identifier-naming.FunctionCase + value: lower_case + # - key: readability-identifier-naming.ConstexprMethodCase + # value: lower_case + - key: readability-identifier-naming.VirtualMethodCase + value: lower_case + # - key: readability-identifier-naming.ClassMethodCase + # value: lower_case + - key: readability-identifier-naming.PrivateMethodCase + value: lower_case + - key: readability-identifier-naming.ProtectedMethodCase + value: lower_case + - key: readability-identifier-naming.PublicMethodCase + value: lower_case + - key: readability-identifier-naming.MethodCase + value: lower_case + - key: readability-identifier-naming.TypedefCase + value: lower_case + # https://bugs.llvm.org/show_bug.cgi?id=46752 + # - key: readability-identifier-naming.TypeTemplateParameterCase + # value: CamelCase + - key: readability-identifier-naming.ValueTemplateParameterCase + value: CamelCase + - key: readability-identifier-naming.TemplateTemplateParameterCase + value: CamelCase + # https://bugs.llvm.org/show_bug.cgi?id=46752 + # - key: readability-identifier-naming.TemplateParameterCase + # value: CamelCase + - key: readability-identifier-naming.TypeAliasCase + value: lower_case + - key: readability-identifier-naming.MacroDefinitionCase + value: UPPER_CASE + - key: readability-identifier-naming.ObjcIvarCase + value: lower_case + - key: readability-identifier-naming.NamespacePrefix + value: '' + - key: readability-identifier-naming.InlineNamespacePrefix + value: '' + - key: readability-identifier-naming.EnumConstantPrefix + value: '' + - key: readability-identifier-naming.ConstexprVariablePrefix + value: '' + - key: readability-identifier-naming.ConstantMemberPrefix + value: '' + - key: readability-identifier-naming.PrivateMemberPrefix + value: '_' + - key: readability-identifier-naming.ProtectedMemberPrefix + value: '_' + - key: readability-identifier-naming.PublicMemberPrefix + value: '' + - key: readability-identifier-naming.MemberPrefix + value: '' + - key: readability-identifier-naming.ClassConstantPrefix + value: '' + - key: readability-identifier-naming.ClassMemberPrefix + value: '' + - key: readability-identifier-naming.GlobalConstantPrefix + value: '' + - key: readability-identifier-naming.GlobalConstantPointerPrefix + value: '' + - key: readability-identifier-naming.GlobalPointerPrefix + value: '' + - key: readability-identifier-naming.GlobalVariablePrefix + value: '' + - key: readability-identifier-naming.LocalConstantPrefix + value: '' + - key: readability-identifier-naming.LocalConstantPointerPrefix + value: '' + - key: readability-identifier-naming.LocalPointerPrefix + value: '' + - key: readability-identifier-naming.LocalVariablePrefix + value: '' + - key: readability-identifier-naming.StaticConstantPrefix + value: '' + - key: readability-identifier-naming.StaticVariablePrefix + value: '' + - key: readability-identifier-naming.ConstantPrefix + value: '' + - key: readability-identifier-naming.VariablePrefix + value: '' + - key: readability-identifier-naming.ConstantParameterPrefix + value: '' + - key: readability-identifier-naming.ParameterPackPrefix + value: '' + - key: readability-identifier-naming.ParameterPrefix + value: '' + - key: readability-identifier-naming.PointerParameterPrefix + value: '' + - key: readability-identifier-naming.ConstantPointerParameterPrefix + value: '' + - key: readability-identifier-naming.AbstractClassPrefix + value: '' + - key: readability-identifier-naming.StructPrefix + value: '' + - key: readability-identifier-naming.ClassPrefix + value: '' + - key: readability-identifier-naming.UnionPrefix + value: '' + - key: readability-identifier-naming.EnumPrefix + value: '' + - key: readability-identifier-naming.GlobalFunctionPrefix + value: '' + - key: readability-identifier-naming.ConstexprFunctionPrefix + value: '' + - key: readability-identifier-naming.FunctionPrefix + value: '' + - key: readability-identifier-naming.ConstexprMethodPrefix + value: '' + - key: readability-identifier-naming.VirtualMethodPrefix + value: '' + - key: readability-identifier-naming.ClassMethodPrefix + value: '' + - key: readability-identifier-naming.PrivateMethodPrefix + value: '' + - key: readability-identifier-naming.ProtectedMethodPrefix + value: '' + - key: readability-identifier-naming.PublicMethodPrefix + value: '' + - key: readability-identifier-naming.MethodPrefix + value: '' + - key: readability-identifier-naming.TypedefPrefix + value: '' + - key: readability-identifier-naming.TypeTemplateParameterPrefix + value: '' + - key: readability-identifier-naming.ValueTemplateParameterPrefix + value: '' + - key: readability-identifier-naming.TemplateTemplateParameterPrefix + value: '' + - key: readability-identifier-naming.TemplateParameterPrefix + value: '' + - key: readability-identifier-naming.TypeAliasPrefix + value: '' + - key: readability-identifier-naming.MacroDefinitionPrefix + value: '' + - key: readability-identifier-naming.ObjcIvarPrefix + value: '' + - key: readability-identifier-naming.NamespaceSuffix + value: '' + - key: readability-identifier-naming.InlineNamespaceSuffix + value: '' + - key: readability-identifier-naming.EnumConstantSuffix + value: '' + - key: readability-identifier-naming.ConstexprVariableSuffix + value: '' + - key: readability-identifier-naming.ConstantMemberSuffix + value: '' + - key: readability-identifier-naming.PrivateMemberSuffix + value: '' + - key: readability-identifier-naming.ProtectedMemberSuffix + value: '' + - key: readability-identifier-naming.PublicMemberSuffix + value: '' + - key: readability-identifier-naming.MemberSuffix + value: '' + - key: readability-identifier-naming.ClassConstantSuffix + value: '' + - key: readability-identifier-naming.ClassMemberSuffix + value: '' + - key: readability-identifier-naming.GlobalConstantSuffix + value: '' + - key: readability-identifier-naming.GlobalConstantPointerSuffix + value: '' + - key: readability-identifier-naming.GlobalPointerSuffix + value: '' + - key: readability-identifier-naming.GlobalVariableSuffix + value: '' + - key: readability-identifier-naming.LocalConstantSuffix + value: '' + - key: readability-identifier-naming.LocalConstantPointerSuffix + value: '' + - key: readability-identifier-naming.LocalPointerSuffix + value: '' + - key: readability-identifier-naming.LocalVariableSuffix + value: '' + - key: readability-identifier-naming.StaticConstantSuffix + value: '' + - key: readability-identifier-naming.StaticVariableSuffix + value: '' + - key: readability-identifier-naming.ConstantSuffix + value: '' + - key: readability-identifier-naming.VariableSuffix + value: '' + - key: readability-identifier-naming.ConstantParameterSuffix + value: '' + - key: readability-identifier-naming.ParameterPackSuffix + value: '' + - key: readability-identifier-naming.ParameterSuffix + value: '' + - key: readability-identifier-naming.PointerParameterSuffix + value: '' + - key: readability-identifier-naming.ConstantPointerParameterSuffix + value: '' + - key: readability-identifier-naming.AbstractClassSuffix + value: '' + - key: readability-identifier-naming.StructSuffix + value: '' + - key: readability-identifier-naming.ClassSuffix + value: '' + - key: readability-identifier-naming.UnionSuffix + value: '' + - key: readability-identifier-naming.EnumSuffix + value: '' + - key: readability-identifier-naming.GlobalFunctionSuffix + value: '' + - key: readability-identifier-naming.ConstexprFunctionSuffix + value: '' + - key: readability-identifier-naming.FunctionSuffix + value: '' + - key: readability-identifier-naming.ConstexprMethodSuffix + value: '' + - key: readability-identifier-naming.VirtualMethodSuffix + value: '' + - key: readability-identifier-naming.ClassMethodSuffix + value: '' + - key: readability-identifier-naming.PrivateMethodSuffix + value: '' + - key: readability-identifier-naming.ProtectedMethodSuffix + value: '' + - key: readability-identifier-naming.PublicMethodSuffix + value: '' + - key: readability-identifier-naming.MethodSuffix + value: '' + - key: readability-identifier-naming.TypedefSuffix + value: '' + - key: readability-identifier-naming.TypeTemplateParameterSuffix + value: '' + - key: readability-identifier-naming.ValueTemplateParameterSuffix + value: '' + - key: readability-identifier-naming.TemplateTemplateParameterSuffix + value: '' + - key: readability-identifier-naming.TemplateParameterSuffix + value: '' + - key: readability-identifier-naming.TypeAliasSuffix + value: '' + - key: readability-identifier-naming.MacroDefinitionSuffix + value: '' + - key: readability-identifier-naming.ObjcIvarSuffix + value: '' +... +``` \ No newline at end of file diff --git a/_posts/2023-05-5-cpp-code-snippet.md b/_posts/2023-05-5-cpp-code-snippet.md new file mode 100644 index 0000000..5a2e27c --- /dev/null +++ b/_posts/2023-05-5-cpp-code-snippet.md @@ -0,0 +1,109 @@ +--- +title: cpp code snippet +date: 2023-05-5 +0800 # 2022-01-01 13:14:15 +0800 只写日期也行;不写秒也行;这样也行 2022-03-09T00:55:42+08:00 +categories: [cpp] +tags: [cpp] # TAG names should always be lowercase + +# 以下默认false +math: true +mermaid: true +# pin: true +--- + +## 1. 获取数组长度 + +```cpp +#include + +struct StructDef { + int32_t arr[32]; +}; + +StructDef sd; +const size_t len = std::extent::value; +std::vector vec(sd.arr, sd.arr + len); +``` + +## 2. CHECK + +```cpp +#include +#include + +#if defined DEBUG || defined _DEBUG +#define CHECK2(condition, message) \ + (!(condition)) ? (std::cerr << "Assertion failed: (" << #condition << "), " \ + << "function " << __FUNCTION__ << ", file " << __FILE__ << ", line " << __LINE__ << "." << std::endl \ + << message << std::endl, \ + abort(), 0) \ + : 1 +#else +#define CHECK2(condition, message) (void)0 +#endif +``` + +## 3. 获取线程 ID + +通过 `pthread_self` 及 `std::this_thread::getid` 函数获取的线程 ID,跟使用 `top`, `htop` 命令呈现的线程 ID 不对应。 +通过如下代码获取跟 `top`, `htop` 命令一致的 TID: + +```cpp +#include + +pid_t gettid(void) { + return (pid_t)syscall(SYS_gettid); +} + +// 设置所在线程名称 +const char* thd_name = "demo_thread"; +prctl(PR_SET_NAME, reinterpret_cast(thd_name ), 0, 0, 0); +``` + +## 4. 获取本地IP地址列表 + +```cpp +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +std::vector get_local_ip_v2() { + std::vector addr_list; + struct ifaddrs *ifaddr, *ifa; + char host[NI_MAXHOST]; + + if (getifaddrs(&ifaddr) == -1) { + perror("getifaddrs"); + exit(EXIT_FAILURE); + } + + for (ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) { + if (ifa->ifa_addr == nullptr) { + continue; + } + + const auto s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, + NI_MAXHOST, nullptr, 0, NI_NUMERICHOST); + if (ifa->ifa_addr->sa_family == AF_INET) { + // strcmp(ifa->ifa_name,"wlan0") == 0 + if (s != 0) { + printf("getnameinfo failed: %s\n", gai_strerror(s)); + break; + } + + // printf("\tInterface : <%s>\n", ifa->ifa_name); + // printf("\t Address : <%s>\n", host); + addr_list.push_back(host); + } + } + + freeifaddrs(ifaddr); + return addr_list; +} +``` diff --git a/_posts/2023-05-5-design-modes-for-all.md b/_posts/2023-05-5-design-modes-for-all.md new file mode 100644 index 0000000..40b8f46 --- /dev/null +++ b/_posts/2023-05-5-design-modes-for-all.md @@ -0,0 +1,110 @@ +--- +title: 写给大家看的设计模式 +date: 2023-05-5 +0800 # 2022-01-01 13:14:15 +0800 只写日期也行;不写秒也行;这样也行 2022-03-09T00:55:42+08:00 +categories: [cpp] +tags: [cpp] # TAG names should always be lowercase + +# 以下默认false +math: true +mermaid: true +# pin: true +--- + +- [写给大家看的设计模式](https://juejin.cn/post/6844903491601694727) +- [图解TensorFlow源码](https://www.cnblogs.com/yao62995/p/5773578.html) + +## 抽象工厂模式 + +1. 被创建抽象类 Iuser; +2. 抽象工厂类 IFactory,定义创建接口 `IUser* createUser()`。 +当需要新增被创建类型时,需要新增被创建类型及对应工厂类型; + +```cpp +// 代表数据库中User表中的一条记录 +class RecUser { + int32_t uid; + std::string uname; +}; + +// 代表数据库中Department表中一条记录 +class RecDepartment { + int32_t did; + std::string dname; +}; + +// 1. 用户表操作抽象接口 +class IUser { +public: + virtual void insert(const RecUser *user) = 0; + virtual RecUser *getUserRecord(int32_t id) = 0; + virtual ~IUser() = default; +}; + +// 2.1 User表操作实现类:SQL Server +class SqlServerUser : public IUser { +public: + void insert(const RecUser *user) override { + std::cout << "Insert a user record into SQL Server table." << std::endl; + } + RecUser *getUserRecord(int32_t id) override { + std::cout << "Get a record from SQL Server table." << std::endl; + return nullptr; + } + ~SqlServerUser() override { + std::cout << "dtor of SqlServerUser." << std::endl; + } +}; + +// 2.2 User表操作实现类:access 表 +class AccessUser : public IUser { +public: + void insert(const RecUser *user) override { + std::cout << "Insert a user record into access table." << std::endl; + } + RecUser *getUserRecord(int32_t id) override { + std::cout << "Get a record from access table." << std::endl; + return nullptr; + } + ~AccessUser() override { + std::cout << "dtor of AccessUser. " << std::endl; + } +}; + +// 3. 抽象工厂类 +class IFactory { +public: + virtual IUser *createUser() = 0; +}; + +// 4.1 SQL Server 具体工厂类 +class SqlFactory : public IFactory { +public: + IUser *createUser() override { + return new SqlServerUser; + } +}; + +// 4.2 access 具体工厂类 +class AccessFactory : public IFactory { +public: + IUser *createUser() override { + return new AccessUser; + } +}; + +TEST_CASE("design mode: abstract factory") { + RecUser user_rec; + + // 创建类型1实例:SQL表操作 + std::shared_ptr factory(new SqlFactory); + std::shared_ptr user_table(factory->createUser()); + user_table->insert(&user_rec); + user_table->getUserRecord(1); + + // 创建类型2实例:access表操作 + factory.reset(new AccessFactory); + user_table.reset(factory->createUser()); + user_table->insert(&user_rec); + user_table->getUserRecord(1); +} +``` diff --git a/_posts/2023-05-5-good-cpp-repo-on-github.md b/_posts/2023-05-5-good-cpp-repo-on-github.md new file mode 100644 index 0000000..a3de4fc --- /dev/null +++ b/_posts/2023-05-5-good-cpp-repo-on-github.md @@ -0,0 +1,14 @@ +--- +title: good cpp repo on github +date: 2023-05-5 +0800 # 2022-01-01 13:14:15 +0800 只写日期也行;不写秒也行;这样也行 2022-03-09T00:55:42+08:00 +categories: [cpp] +tags: [cpp] # TAG names should always be lowercase + +# 以下默认false +math: true +mermaid: true +# pin: true +--- + +Intel并行库 [oneTBB](https://github.com/oneapi-src/oneTBB) +包含[malloc](https://github.com/oneapi-src/oneTBB/tree/master/src/tbbmalloc) diff --git a/_posts/2023-0610-install qt5 on ubuntu 22.04 for VTK.md b/_posts/2023-0610-install qt5 on ubuntu 22.04 for VTK.md new file mode 100644 index 0000000..51d21c4 --- /dev/null +++ b/_posts/2023-0610-install qt5 on ubuntu 22.04 for VTK.md @@ -0,0 +1,24 @@ +--- +title: Ubuntu 22.04 安装 Qt5,以编译 VTK +date: 2023-06-10 +0800 # 2022-01-01 13:14:15 +0800 只写日期也行;不写秒也行;这样也行 2022-03-09T00:55:42+08:00 +categories: [cpp] +tags: [cpp] # TAG names should always be lowercase + +# 以下默认false +math: true +mermaid: true +# pin: true +--- + +## 1. install commands + +```bash +sudo apt-get -y install build-essential cmake gcc git lib32ncurses-dev lib32z1 libfox-1.6-dev libsdl1.2-dev qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools qtmultimedia5-dev qttools5-dev qttools5-dev-tools qtcreator libqt5svg5-dev software-properties-common wget zip python3-pip-whl python3-pil libgtest-dev python3-pip python3-tk python3-setuptools clang-14 python3-clang-14 libusb-1.0-0-dev stlink-tools openocd npm pv libncurses5:i386 libpython2.7:i386 libclang-14-dev python-is-python3 + +sudo apt install qtdeclarative5-dev +``` + +## 2. refs + +* [gist](https://gist.githubusercontent.com/simos/8de45464687d87407041e4c2d2f69500/raw/4530829479584f290a91020a75c4f6e360492704/setup_buildenv_ubuntu22.04.sh) +* [Which dev packages are needed to build a QtQuick application on Ubuntu 20.04?](https://stackoverflow.com/questions/64882226/which-dev-packages-are-needed-to-build-a-qtquick-application-on-ubuntu-20-04) \ No newline at end of file