collectionstack.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifndef COLLECTIONSTACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
  2. #define COLLECTIONSTACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
  3. #if defined(_MSC_VER) || \
  4. (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
  5. (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
  6. #pragma once
  7. #endif
  8. #include <cassert>
  9. #include <stack>
  10. namespace YAML {
  11. struct CollectionType {
  12. enum value { NoCollection, BlockMap, BlockSeq, FlowMap, FlowSeq, CompactMap };
  13. };
  14. class CollectionStack {
  15. public:
  16. CollectionStack() : collectionStack{} {}
  17. CollectionType::value GetCurCollectionType() const {
  18. if (collectionStack.empty())
  19. return CollectionType::NoCollection;
  20. return collectionStack.top();
  21. }
  22. void PushCollectionType(CollectionType::value type) {
  23. collectionStack.push(type);
  24. }
  25. void PopCollectionType(CollectionType::value type) {
  26. assert(type == GetCurCollectionType());
  27. (void)type;
  28. collectionStack.pop();
  29. }
  30. private:
  31. std::stack<CollectionType::value> collectionStack;
  32. };
  33. } // namespace YAML
  34. #endif // COLLECTIONSTACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66