search_util.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Tencent is pleased to support the open source community by making wwsearch
  3. * available.
  4. *
  5. * Copyright (C) 2018-present Tencent. All Rights Reserved.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  8. * use this file except in compliance with the License. You may obtain a copy of
  9. * the License at
  10. *
  11. * https://opensource.org/licenses/Apache-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OF ANY KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations under the License.
  17. */
  18. #pragma once
  19. #include "header.h"
  20. namespace wwsearch {
  21. #define DELETE_RESET(ptr) \
  22. if ((ptr) != nullptr) { \
  23. delete (ptr); \
  24. (ptr) = nullptr; \
  25. }
  26. class ArgsHelper {
  27. private:
  28. std::map<char, std::string> _kv;
  29. public:
  30. // usage: man 3 getopt
  31. // example: a:b:cd
  32. ArgsHelper(int argc, char **argv, const char *opts_str);
  33. ~ArgsHelper();
  34. bool Have(const char c);
  35. std::string String(const char c);
  36. int Int(const char c);
  37. int64_t Int64(const char c);
  38. uint32_t UInt(const char c);
  39. uint64_t UInt64(const char c);
  40. };
  41. } // namespace wwsearch