One Framework 0.1.0
RoboMaster嵌入式框架“一键”解决方案,为你的“创意”服务。
载入中...
搜索中...
未找到
FixedString.hpp
浏览该文件的文档.
1#ifndef OF_FIXEDSTRING_HPP
2#define OF_FIXEDSTRING_HPP
3
4#include <assert.h>
5#include <cstring>
6#include <string>
7
8namespace OF
9{
10 template <size_t Size>
12 {
13 public:
14 FixedString() { data[0] = '\0'; }
15
16 FixedString(const char* str)
17 {
18 assert(str != nullptr);
19 const auto len = strlen(str);
20 assert(len <= Size);
21 memcpy(data, str, len);
22 data[len] = '\0';
23 }
24
25 FixedString(const std::string& str) : FixedString(str.c_str())
26 {
27 }
28
29 bool operator==(const FixedString& other) const
30 {
31 return strcmp(data, other.data) == 0;
32 }
33
34 std::string_view view() const
35 {
36 return std::string_view(data);
37 }
38
39 private:
40 char data[Size];
41 };
42}
43
44template <size_t Size>
45struct std::hash<OF::FixedString<Size>>
46{
47 size_t operator()(const OF::FixedString<Size>& k) const
48 {
49 return hash<string_view>{}(k.view());
50 }
51};
52
53#endif //OF_FIXEDSTRING_HPP
定义 FixedString.hpp:12
FixedString(const char *str)
定义 FixedString.hpp:16
std::string_view view() const
定义 FixedString.hpp:34
FixedString()
定义 FixedString.hpp:14
bool operator==(const FixedString &other) const
定义 FixedString.hpp:29
FixedString(const std::string &str)
定义 FixedString.hpp:25
定义 Mecanum.hpp:6
size_t operator()(const OF::FixedString< Size > &k) const
定义 FixedString.hpp:47