{"id":21098467,"url":"https://github.com/scarsty/mlcc","last_synced_at":"2025-05-16T16:32:17.000Z","repository":{"id":31228361,"uuid":"34789548","full_name":"scarsty/mlcc","owner":"scarsty","description":"一些有用的功能","archived":false,"fork":false,"pushed_at":"2025-04-12T15:41:50.000Z","size":390,"stargazers_count":45,"open_issues_count":0,"forks_count":16,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-12T16:41:46.138Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scarsty.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-04-29T11:16:05.000Z","updated_at":"2025-04-12T15:41:54.000Z","dependencies_parsed_at":"2023-02-10T20:50:18.086Z","dependency_job_id":"76ae8ac5-026b-4d2a-b5aa-767ba7f82720","html_url":"https://github.com/scarsty/mlcc","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scarsty%2Fmlcc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scarsty%2Fmlcc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scarsty%2Fmlcc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scarsty%2Fmlcc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scarsty","download_url":"https://codeload.github.com/scarsty/mlcc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254567510,"owners_count":22092780,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T22:55:12.500Z","updated_at":"2025-05-16T16:32:16.994Z","avatar_url":"https://github.com/scarsty.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MLCC Library\n\nMLCC is a set of C++ libraries.\n\nMLCC means Multi-layer Ceramic Capacitors.\n\nAll libraries are of standard C++ 11 and of cross platforms.\n\n## Cifa\n\nA simple c-style script, please see [cifa](cifa) for more details. The old develop branch is \u003chttps://github.com/scarsty/cifa\u003e, now it has been moved here.\n\n## INIReader\n\nINIReader.h\n\nRead and write ini file. Modified from \u003chttps://github.com/benhoyt/inih\u003e. The writting of it is very quick.\n\n### Read an ini file\n\nexample.ini:\n\n```ini\n; last modified 1 April 2001 by John Doe\n[owner]\nname=John Doe\norganization=Acme Widgets Inc.\n\n[database]\n; use IP address in case network name resolution is not working\nserver=192.0.2.62     \nport=143\nfile=\"payroll.dat\"\n```\nC++ code:\n\n```c++\nint main()\n{\n    INIReaderNoUnderline ini;\n    ini.loadFile(\"example.ini\");\n    int port = ini.getInt(\"database\", \"port\", 0);    //port = 143\n    int port_ = ini.getInt(\"database\", \"port_\", 0);    //port_ = 143\n    std::string name = ini.getString(\"owner\", \"name\", \"\");    //name = Joha Doe\n    auto file = ini[\"database\"][\"file\"].toString();    //file = payroll.dat (the quotation mark will be removed)\n    return 0;\n}\n```\n\nPlease note that here we use a subclass to ignore the underline in the keys.\n\n### Modify an ini file\n\nUse setKey and eraseKey after loading the file, then use saveFile to write results to a file.\n\nAn example:\n\n```c++\nint main()\n{\n    INIReaderNormal ini;\n    ini.loadFile(\"example.ini\");\n    ini.setKey(\"\", \"head\", \"nothing\");\n    ini.setKey(\"owner\", \"age\", \"30\");\n    ini.eraseKey(\"database\", \"port\");\n    ini[\"owner\"].erase(\"name\");\n    ini[\"account\"][\"password\"] = \"***\";\n    ini.saveFile(\"example1.ini\");\n    return 0;\n}\n```\nThe content of example1.ini after running is:\n\n```ini\n[]\nhead = nothing\n; last modified 1 April 2001 by John Doe\n[owner]\norganization = Acme Widgets Inc.\nage = 30\n\n[database]\n; use IP address in case network name resolution is not working\nserver = 192.0.2.62     \nfile = payroll.dat\n\n[account]\npassword = ***\n\n```\nA space will be added at both sides of \"=\", and the comments will be maintained.\n\nIf the string includes some special charactors, such as \";\" and \"#\" (which are the comment prefix), or line break, please use quote to surround it. Examples:\n\n```ini\n[sec]\nkey1 = \"cc;dd#l\"\nkey2 = \"line1\nline2\"\n```\n\nThis library does not support the escape characters or operating the comments.\n\nIf a key has been multi-defined, the last value is reserved. **Please note all the multi-defined keys EXCLUDE the first one with the last value will be ERASED when saving!** But the last comment to it will be kept.\n\nYou can define how to compare the section and key. Such as:\n\n```c++\nstruct CaseInsensitivity\n{\n    std::string operator()(const std::string\u0026 l) const\n    {\n        auto l1 = l;\n        std::transform(l1.begin(), l1.end(), l1.begin(), ::tolower);\n        return l1;\n    }\n};\n\nusing INIReaderNormal = INIReader\u003cCaseInsensitivity\u003e;\n\n```\n\nMulti level hierarchy is supported, the sub section should be put inisde two or more square brackets to. Example:\n\n```c++\nINIReaderNormal ini;\nini[\"sec0\"][\"a\"] = 1;\nini[\"sec0\"][\"sec0_1\"][\"a\"] = 1;\nini[\"sec1\"][\"a\"] = 1;\n```\nNote that if you use toString(), toInt() or toDouble() of this type, a new key with empty value will be created if it does not exist.\n\nThese C++ code will give an ini file like this:\n\n```ini\n[sec0]\na=1\n[[sec0_1]]\na=1\n[sec1]\na=1\n```\n\n### About comment\n\nIf you load one file for many times, the comments will be repeated at the end of their section. So please do not do this.\n\n## strfunc\n\nstrfunc.h, strfunc.cpp\n\nexample.txt:\n\n```\nabc_def_;dddd.\n```\n\nSome examples:\n\n```c++\nstd::string str = readStringFromFile(\"example.txt\");    //str = \"abc_def_;dddd.\"\nreplaceAllSubStringRef(str, \"_\", \".\");    //str = \"abc.def.;dddd.\"\n\nstr = \"123,467,222;44\";\nstd::vector\u003cint\u003e numbers = findNumbers\u003cint\u003e(str);    //numbers = {123, 467, 222, 44}, scientific notation is supported \nstd::vector\u003cstd::string\u003e strs = splitString(str, \",;\");    //strs = {\"123\", \"467\", \"222\", \"44\"}\n```\n\n\"splitString\" also supports treating continuous spaces as one pattern.\n\nvectorToString can convert a std::vector\u003cT\u003e to a std::string, it is too bother to deal with the last splitting char manually.\n\nIt also supplies some encoding converters.\n\n## Timer\n\nTimer.h\n\nA timer.\n\n```c++\nTimer t;\n// do something...\ndouble elapsed_second = t.getElapsedTime();    //you can check how long the program spent\n```\n\n## Random\n\nRandom.h\n\nAn Mersenne twister random number generator.\n\n```c++\nRandom\u003cdouble\u003e rand;\nrand.set_type(RANDOM_NORMAL);\ndouble d = rand.rand();    //Gaussian(0, 1)\nrand.set_type(RANDOM_UNIFORM);\nint i = rand.rand_int(100);    //[0, 100)\n```\n\n## DynamicLibrary\n\nDynamicLibrary.h\n\nThis library is a static class and is of single instance.\n\nGet the C-style function pointer like this:\n\n```c++\nvoid* func = DynamicLibrary::getFunction(\"xxx.dll\", \"xxx\");\n```\n\nYou have to give the full name of the library include the path.\n\nThe loaded libraries will be unload automatically when the program exits.\n\n## ConsoleControl\n\nConsoleControl.h\n\nThis library can change the color of the output characters on the console, or change the position of the cursor to format the output.\n\n```c++\nConsoleControl::setColor(CONSOLE_COLOR_LIGHT_RED);    //change the color of printf, fprintf...\nConsoleControl::moveUp(2);    //move up the cursor for 2 lines\n```\n## filefunc\n\nfilefunc.h, filefunc.cpp\n\nThis class can read and write file as a vector of any class.\n\nSome functions are very similar to those of \"strfunc\".\n\nThis class can also extract  path, main name or extension from a filename string, examples:\n\n```c++\nstd::string filename = R\"(C:\\Windows\\system32\\xxx.exe.1)\";\nstd::string result; \nresult = filefunc::getParentPath(filename);    // C:\\Windows\\system32\nresult = filefunc::getFileMainname(filename);    // C:\\Windows\\system32\\xxx.exe\nresult = filefunc::getFilenameWithoutPath(filename);    // xxx.exe.1\nresult = filefunc::changeFileExt(filename, \"dll\");    // C:\\Windows\\system32\\xxx.exe.dll\n```\n\nOn Windows, \"\\\\\" and \"/\" are both supported. A mixed style string (such as \"C:\\Windows\\system32/xxx.exe.1\") can also be treated correctly. It can treat ANSI string correctly, but for UTF8 string the result may be not right. In fact Windows cannot open a file with a UTF8 string file name directly, so this problem is not serious.\n\nOn Linux and other Unix-like systems, \"\\\\\" is not a path pattern, only \"/\" is effective and it is a single byte character in UTF8 coding, so the result should always be correct.\n\n# cmdline\n\ncmdline.h.\n\nModified from \u003chttps://github.com/tanakh/cmdline\u003e. Please read the instruction on the original project.\n\nA bug when parsing a full command line string has been corrected.\n\nYou'd better to use it like this:\n\n```c++\n\n#ifdef _WIN32    // or _MSC_VER, as you wish\n#include \u003cwindows.h\u003e\n#endif\n\nint main(int argc, char* argv[])\n{\n...\n#ifdef _WIN32\n    cmd.parse_check(GetCommandLineA());\n#else\n    cmd.parse_check(argc, argv);\n#endif\n...\n}\n```\nor a command line mixing backslash and quote cannot be correctly parsed on Windows. For an example:\n```shell\nsomething.exe --path \"C:\\Windows\\system32\\\" --other-option values\n```\nIn this case, \"argc\" and \"argv\" in the program are NOT right with CMD, but are right with Power Shell, is it a bug of Windows?\n\n# fmt1\n\nA simple substitute of std::format. \n\nIf you cannot stand the neglect of Clang and GCC, maybe you can try it.\n\nIt also provide the formatter of vector and map to use is C++20.\n\nIt has been removed due to the supporting of the mainstream compilers.\n\n# runtime_format\n\nA simple runtime format implement, temporary use before C++26 is released.\n\n# PotConv\n\nA C++ warp for iconv.\n\n# StrCvt\n\nSome practical functions involving string coding, wide characters, and multi-byte characters.\nRequires \u003e= C++11 and \u003c C++26.\n\n```c++\nstd::string strfunc::CvtStringToUTF8(const std::string\u0026 localstr); //windows only\nstd::string strfunc::CvtUTF8ToLocal(const std::string\u0026 utf8str); //windows only\n\nstd::string strfunc::CvtStringToUTF8(const char16_t\u0026 src);\nstd::string strfunc::CvtStringToUTF8(const std::u16string\u0026 src);\nstd::string strfunc::CvtStringToUTF8(const wchar_t* start, std::uint64_t len);\nstd::string strfunc::CvtStringToUTF8(const std::wstring\u0026 str);\nstd::u16string strfunc::CvtStringToUTF16(const std::string\u0026 src);\nstd::u16string strfunc::CvtStringToUTF16(const char* start, int len);\nstd::wstring strfunc::CvtStringToWString(const std::string\u0026 src);\nstd::wstring strfunc::CvtStringToWString(const char* start, uint64_t len);\n\n```\n\n# DrawStringFT\n\nA C++ warp for freetype and opencv Mat. It can write charactors (such as Chinese) on an image. \n\n# CheckDependency\n\nOnly for Windows.\n\nTo check the dependencies of a exe or dll file. \n\nThe CheckDependency is similar to the data viewed using the command `dumpbin /DEPENDENTS`.\nIt can help you get the platform (x64 or x86) of each dll that this exe or dll depends on, as well as the functions exported by each dll, the functions of each dll used by this file, and each problem Dlls (missing functions).\n\nAn example:\n\n```c++\nCheckDependency dep;\nauto problem_dlls = dep.Check(\"myself.dll\");\nstd::cout \u003c\u003c \"Problem Dlls : \" \u003c\u003c std::endl;\nfor(auto\u0026 item : problem_dlls)\n{\n    std::cout \u003c\u003c \"(\" \u003c\u003c item.second.machine.c_str() \u003c\u003c \")\"\n    \u003c\u003c item.first \u003c\u003c \", lost functions: \" \u003c\u003c item.second.lost_functions.size()\n    \u003c\u003c std::endl;\n}\nstd::cout \u003c\u003c \"Import Table: \" \u003c\u003c std::endl;\nfor(auto\u0026 item : dep.ImportTable())\n{\n    std::cout \u003c\u003c \"(\" \u003c\u003c item.second.machine.c_str() \u003c\u003c \")\"\n    \u003c\u003c item.first \u003c\u003c \", used functions: \" \u003c\u003c item.second.used_functions.size()\n    \u003c\u003c std::endl;\n}\nstd::cout \u003c\u003c \"Export Table: \" \u003c\u003c std::endl;\nfor(auto\u0026 item : dep.ExportTable())\n{\n    std::cout \u003c\u003c item.first \u003c\u003c \", export functions: \" \u003c\u003c item.second.size() \u003c\u003c std::endl;\n}\n```\n\n# FunctionTrait\n\nCheck the number of patameters anf the return type of a class member function.\n\n# FakeJson\n\nA simllified JSON library. It does not support escape characters.\n\n# vramusage\n\nOnly for Windows.\n\nCUDA and HIP supply the apis to get the usage of video memory, but on Windows the result is not right.\n\nThis can help you to get that correctly. \n\nFirst, get the LUID or PCI bus with cudaGetDeviceProperties / hipGetDeviceProperties, and get the memory usage of it.\n\n## 备注\n\n此功能用到了未公开用法的Windows API`D3DKMTQueryStatistics`和结构体`D3DKMT_QUERYSTATISTICS`。\n\n`D3DKMT_QUERYSTATISTICS`是一个以Union为主的结构，首先需要赋值查询内容和LUID，查询成功之后，Union的其余部分是没有用的。\n\n例如以下查询：\n\n```c++\nD3DKMT_QUERYSTATISTICS queryStatistics{};\nqueryStatistics.Type = D3DKMT_QUERYSTATISTICS_ADAPTER;\nqueryStatistics.AdapterLuid = luid;\nif (D3DKMTQueryStatistics(\u0026queryStatistics))\n{\n    //printf(\"D3DKMTQueryStatistics failed with %d\\n\", ret);\n    return 1;\n}\n```\n\n查询之后， 只有`queryStatistics.QueryResult.AdapterInformation`是有用的。\n\n在显存查询的部分，需要把每段的占用加起来得到总的占用。\n\n# targetlnk\n\nGet the target of a .lnk file.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscarsty%2Fmlcc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscarsty%2Fmlcc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscarsty%2Fmlcc/lists"}