64-bit quick comparison

I am working on a GUI infrastructure where I want all elements to be identified by ascii strings up to 8 characters long (or 7 would be ok).

Each time an event is fired (some of them are just clicks, but some of them are continuous), the framework would access the client code with the identifier and its value.

I could use the actual strings and strcmp (), but I want it to be very fast (for mobile devices), so I thought to use char constants (like int id = 'BTN1';), d do a one-way comparison with the test to identifier. However, 4 characters are not readable enough.

I tried an experiment that long int id = L'abcdefg ';

... but it looks like char constants can only contain 4 characters, and the only thing that makes the long int char constant gives you the opportunity for your 4 characters to be twice as wide, not have twice as many characters. Did I miss something?

I want to make it easier for the person who wrote the client code. Gui is stored in xml, so the identifier is loaded from the lines, but in comparison with it the constants written in the client code will be indicated.

So long and short, I'm looking for a cross-platform way to make a quick comparison of 7-8 characters, any ideas?

+3
source share
6 answers

, ? , - ? , ? , . , strcmp , , , .

, , :

static const int MY_BUTTON_ID = 1;

, . , const char [9] 64- . " " 8 ( , ). 64- , .

: , :

__int64 makeid(const char* str)
{
    __int64 ret = 0;
    strncpy((char*)&ret, str, sizeof(__int64));
    return ret;
}
+4

, 64- 8- :

union ID {
  Int64 id;      // Assuming Int64 is an appropriate typedef somewhere
  char name[8];
};

, :

ID id;
strncpy(id.name, "Button1", 8);
if (anotherId.id == id.id) ...
+4

- red-black STL , .

STL , ( ), .

-

, 64- , boost. , , stl:: map, , , .

2

, , : , . , :

// WidgetHandle is a polymorphic base class (i.e., it has a virtual method),
// and foo::Luv implement WidgetHandle interface (public inheritance)
foo::WidgetHandle * LuvComponent = 
          Factory.CreateComponent<foo::Luv>( "meLuvYouLongTime");
....

.... // in different function
foo::WidgetHandle * LuvComponent = 
          Factory.RetrieveComponent<foo::Luv>("meLuvYouLongTime");

2 - IPC, IPC, , ​​ .

+1
+1

.

( ) ? , , - ( ) .

0

++ 0x , - 7chars..id "7chars.."id:

template <char...> constexpr unsigned long long operator ""id();
constexpr unsigned long long operator ""id(const char *, size_t);

, constexpr .

0

Source: https://habr.com/ru/post/1735068/


All Articles