开发者

What to name an array of flags?

开发者 https://www.devze.com 2023-01-01 04:41 出处:网络
I have a project where lots of the objects hold state by maintaining simple boolean flags.There are lots of these, so I maintain them within a uint32_t and use bit masking.There are now so many flags

I have a project where lots of the objects hold state by maintaining simple boolean flags. There are lots of these, so I maintain them within a uint32_t and use bit masking. There are now so many flags to keep track of, I've created an abstraction for them (just a class wrapping the uint32_t) with set(), clear(), etc.

My question: What's a nice accurate, concise name for this class? What name could I give this class s开发者_Go百科o that you'd have a reasonable idea what it was [for] knowing the name only?

Some ideas I had:

  • FlagBank
  • FlagArray
  • etc

Any ideas?

Thanks in advance!

Cheers,

-Chris


The Standard has such a class template and it is called std::bitset<N> (N for the number of bits/flags). The actual object of this class could be named according its purpose then, like state or something.


FlagBank would be fairly descriptive.

But I have one suggestion. Instead of using uint32_t and bit masking, it might be less C-like to use an STL vector instead. It uses a template specialization for the boolean case where only one bit per element is used for the storage. Very efficient and MUCH more object oriented.

0

精彩评论

暂无评论...
验证码 换一张
取 消