QuantityFlag_methods.cpp 554 B

12345678910111213141516171819202122
  1. vector<const QuantityFlag *>
  2. QuantityFlag::flags_from_mask(unsigned int mask)
  3. {
  4. auto result = vector<const QuantityFlag *>();
  5. while (mask)
  6. {
  7. unsigned int new_mask = mask & (mask - 1);
  8. result.push_back(QuantityFlag::get(
  9. static_cast<enum sr_mqflag>(mask ^ new_mask)));
  10. mask = new_mask;
  11. }
  12. return result;
  13. }
  14. unsigned int QuantityFlag::mask_from_flags(vector<const QuantityFlag *> flags)
  15. {
  16. unsigned int result = 0;
  17. for (auto flag : flags)
  18. result |= flag->id();
  19. return result;
  20. }