Zserio C++17 runtime library  0.5.0
Built for Zserio 2.17.0
Walker.h
Go to the documentation of this file.
1 #ifndef ZSERIO_WALKER_H_INC
2 #define ZSERIO_WALKER_H_INC
3 
4 #include <algorithm>
5 #include <functional>
6 #include <regex>
7 
9 #include "zserio/ITypeInfo.h"
10 #include "zserio/IWalkFilter.h"
11 #include "zserio/IWalkObserver.h"
12 #include "zserio/String.h"
14 #include "zserio/TypeInfoUtil.h"
15 #include "zserio/Vector.h"
16 #include "zserio/WalkerConst.h"
17 
18 namespace zserio
19 {
20 
21 template <typename ALLOC>
22 class BasicDefaultWalkFilter;
23 
28 template <typename ALLOC = std::allocator<uint8_t>>
30 {
31 public:
37  explicit BasicWalker(IBasicWalkObserver<ALLOC>& walkObserver);
38 
46 
50  ~BasicWalker() = default;
51 
56  BasicWalker(const BasicWalker& other) = delete;
57  BasicWalker& operator=(const BasicWalker& other) = delete;
58 
59  BasicWalker(BasicWalker&& other) = delete;
60  BasicWalker& operator=(BasicWalker&& other) = delete;
70  void walk(const IBasicReflectableDataConstPtr<ALLOC>& compound);
71 
72 private:
73  void walkFields(
75  bool walkField(
77  bool walkFieldValue(const IBasicReflectableDataConstPtr<ALLOC>& reflectable,
78  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex = WALKER_NOT_ELEMENT);
79 
80  IBasicWalkObserver<ALLOC>& m_walkObserver;
81  BasicDefaultWalkFilter<ALLOC> m_defaultWalkFilter;
82  IBasicWalkFilter<ALLOC>& m_walkFilter;
83 };
84 
88 template <typename ALLOC = std::allocator<uint8_t>>
90 {
91 public:
97  ~BasicDefaultWalkObserver() override = default;
108 
116  {}
118  {}
119 
121  {}
123  {}
124 
126  const IBasicReflectableDataConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>&, size_t) override
127  {}
129  {}
130 
132  {}
133 };
134 
138 template <typename ALLOC = std::allocator<uint8_t>>
140 {
141 public:
147  ~BasicDefaultWalkFilter() override = default;
158 
166  {
167  return true;
168  }
169 
171  {
172  return true;
173  }
174 
176  const IBasicReflectableDataConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>&, size_t) override
177  {
178  return true;
179  }
180 
182  const IBasicReflectableDataConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>&, size_t) override
183  {
184  return true;
185  }
186 
188  {
189  return true;
190  }
191 
193  {
194  return true;
195  }
196 };
197 
201 template <typename ALLOC = std::allocator<uint8_t>>
203 {
204 public:
210  explicit BasicDepthWalkFilter(size_t maxDepth);
211 
215  ~BasicDepthWalkFilter() override = default;
216 
223 
230  bool beforeArray(
231  const IBasicReflectableDataConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo) override;
232  bool afterArray(
233  const IBasicReflectableDataConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo) override;
234 
236  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
238  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
239 
240  bool beforeValue(const IBasicReflectableDataConstPtr<ALLOC>& value, const BasicFieldInfo<ALLOC>& fieldInfo,
241  size_t elementIndex) override;
242  bool afterValue(const IBasicReflectableDataConstPtr<ALLOC>& value, const BasicFieldInfo<ALLOC>& fieldInfo,
243  size_t elementIndex) override;
244 
245 private:
246  bool enterDepthLevel();
247  bool leaveDepthLevel();
248 
249  size_t m_maxDepth;
250  size_t m_depth;
251 };
252 
262 template <typename ALLOC = std::allocator<uint8_t>>
264 {
265 public:
271  explicit BasicRegexWalkFilter(const char* pathRegex, const ALLOC& allocator = ALLOC());
272 
276  ~BasicRegexWalkFilter() override = default;
277 
284 
291  bool beforeArray(
292  const IBasicReflectableDataConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo) override;
293  bool afterArray(
294  const IBasicReflectableDataConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo) override;
295 
297  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
299  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
300 
301  bool beforeValue(const IBasicReflectableDataConstPtr<ALLOC>& value, const BasicFieldInfo<ALLOC>& fieldInfo,
302  size_t elementIndex) override;
303  bool afterValue(const IBasicReflectableDataConstPtr<ALLOC>& value, const BasicFieldInfo<ALLOC>& fieldInfo,
304  size_t elementIndex) override;
305 
306 private:
307  using StringType = BasicString<RebindAlloc<ALLOC, char>>;
308 
309  void appendPath(const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex);
310  void popPath(const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex);
311  StringType getCurrentPath() const;
312  bool matchSubtree(
313  const IBasicReflectableDataConstPtr<ALLOC>& value, const BasicFieldInfo<ALLOC>& fieldInfo) const;
314 
315  typename IBasicWalkFilter<ALLOC>::Path m_currentPath;
316  std::regex m_pathRegex;
317  ALLOC m_allocator; // TODO[Mi-L@]: Check how std::regex_match allocates when results are omitted!
318 };
319 
323 template <typename ALLOC = std::allocator<uint8_t>>
325 {
326 public:
332  explicit BasicArrayLengthWalkFilter(size_t maxArrayLength);
333 
337  ~BasicArrayLengthWalkFilter() override = default;
338 
345 
352  bool beforeArray(
353  const IBasicReflectableDataConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo) override;
354  bool afterArray(
355  const IBasicReflectableDataConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo) override;
356 
358  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
360  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
361 
362  bool beforeValue(const IBasicReflectableDataConstPtr<ALLOC>& value, const BasicFieldInfo<ALLOC>& fieldInfo,
363  size_t elementIndex) override;
364  bool afterValue(const IBasicReflectableDataConstPtr<ALLOC>& value, const BasicFieldInfo<ALLOC>& fieldInfo,
365  size_t elementIndex) override;
366 
367 private:
368  bool filterArrayElement(size_t elementIndex);
369 
370  size_t m_maxArrayLength;
371 };
372 
379 template <typename ALLOC = std::allocator<uint8_t>>
381 {
382 public:
383  using WalkFilterRef = std::reference_wrapper<IBasicWalkFilter<ALLOC>>;
385 
391  explicit BasicAndWalkFilter(const WalkFilters& walkFilters);
392 
396  ~BasicAndWalkFilter() override = default;
397 
402  BasicAndWalkFilter(const BasicAndWalkFilter& other) = delete;
404 
411  bool beforeArray(
412  const IBasicReflectableDataConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo) override;
413  bool afterArray(
414  const IBasicReflectableDataConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo) override;
415 
417  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
419  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
420 
421  bool beforeValue(const IBasicReflectableDataConstPtr<ALLOC>& value, const BasicFieldInfo<ALLOC>& fieldInfo,
422  size_t elementIndex) override;
423  bool afterValue(const IBasicReflectableDataConstPtr<ALLOC>& value, const BasicFieldInfo<ALLOC>& fieldInfo,
424  size_t elementIndex) override;
425 
426 private:
427  template <typename FILTER_FUNC, typename... ARGS>
428  bool applyFilters(FILTER_FUNC filterFunc, ARGS... args)
429  {
430  bool result = true;
431  for (IBasicWalkFilter<ALLOC>& walkFilter : m_walkFilters)
432  {
433  result &= (walkFilter.*filterFunc)(args...);
434  }
435  return result;
436  }
437 
438  WalkFilters m_walkFilters;
439 };
440 
452 template <typename ALLOC>
454  m_walkObserver(walkObserver),
455  m_walkFilter(m_defaultWalkFilter)
456 {}
457 
458 template <typename ALLOC>
460  m_walkObserver(walkObserver),
461  m_walkFilter(walkFilter)
462 {}
463 
464 template <typename ALLOC>
466 {
467  if (!compound)
468  {
469  throw CppRuntimeException("Walker: Root object cannot be NULL!");
470  }
471 
472  const IBasicTypeInfo<ALLOC>& typeInfo = compound->getTypeInfo();
474  {
475  throw CppRuntimeException("Walker: Root object '")
476  << typeInfo.getSchemaName() << "' is not a compound type!";
477  }
478 
479  m_walkObserver.beginRoot(compound);
480  walkFields(compound, typeInfo);
481  m_walkObserver.endRoot(compound);
482 }
483 
484 template <typename ALLOC>
487 {
489  {
490  std::string_view compoundChoice = compound->getChoice();
491  if (!compoundChoice.empty())
492  {
494  auto fieldsIt = std::find_if(
495  fields.begin(), fields.end(), [compoundChoice](const BasicFieldInfo<ALLOC>& fieldInfo) {
496  return fieldInfo.schemaName == compoundChoice;
497  });
498  if (fieldsIt != fields.end())
499  {
500  walkField(compound->getField(compoundChoice), *fieldsIt);
501  }
502  }
503  // else uninitialized or empty branch
504  }
505  else
506  {
507  for (const BasicFieldInfo<ALLOC>& fieldInfo : typeInfo.getFields())
508  {
509  if (!walkField(compound->getField(fieldInfo.schemaName), fieldInfo))
510  {
511  break;
512  }
513  }
514  }
515 }
516 
517 template <typename ALLOC>
518 bool BasicWalker<ALLOC>::walkField(
519  const IBasicReflectableDataConstPtr<ALLOC>& reflectable, const BasicFieldInfo<ALLOC>& fieldInfo)
520 {
521  if (reflectable && fieldInfo.isArray)
522  {
523  if (m_walkFilter.beforeArray(reflectable, fieldInfo))
524  {
525  m_walkObserver.beginArray(reflectable, fieldInfo);
526  for (size_t i = 0; i < reflectable->size(); ++i)
527  {
528  if (!walkFieldValue(reflectable->at(i), fieldInfo, i))
529  {
530  break;
531  }
532  }
533  m_walkObserver.endArray(reflectable, fieldInfo);
534  }
535  return m_walkFilter.afterArray(reflectable, fieldInfo);
536  }
537  else
538  {
539  return walkFieldValue(reflectable, fieldInfo);
540  }
541 }
542 
543 template <typename ALLOC>
544 bool BasicWalker<ALLOC>::walkFieldValue(const IBasicReflectableDataConstPtr<ALLOC>& reflectable,
545  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
546 {
547  const IBasicTypeInfo<ALLOC>& typeInfo = fieldInfo.typeInfo;
549  {
550  if (m_walkFilter.beforeCompound(reflectable, fieldInfo, elementIndex))
551  {
552  m_walkObserver.beginCompound(reflectable, fieldInfo, elementIndex);
553  walkFields(reflectable, typeInfo);
554  m_walkObserver.endCompound(reflectable, fieldInfo, elementIndex);
555  }
556  return m_walkFilter.afterCompound(reflectable, fieldInfo, elementIndex);
557  }
558  else
559  {
560  if (m_walkFilter.beforeValue(reflectable, fieldInfo, elementIndex))
561  {
562  m_walkObserver.visitValue(reflectable, fieldInfo, elementIndex);
563  }
564  return m_walkFilter.afterValue(reflectable, fieldInfo, elementIndex);
565  }
566 }
567 
568 template <typename ALLOC>
570  m_maxDepth(maxDepth),
571  m_depth(1)
572 {}
573 
574 template <typename ALLOC>
577 {
578  return enterDepthLevel();
579 }
580 
581 template <typename ALLOC>
584 {
585  return leaveDepthLevel();
586 }
587 
588 template <typename ALLOC>
591 {
592  return enterDepthLevel();
593 }
594 
595 template <typename ALLOC>
598 {
599  return leaveDepthLevel();
600 }
601 
602 template <typename ALLOC>
605 {
606  return m_depth <= m_maxDepth;
607 }
608 
609 template <typename ALLOC>
612 {
613  return true;
614 }
615 
616 template <typename ALLOC>
618 {
619  const bool enter = (m_depth <= m_maxDepth);
620  m_depth += 1;
621  return enter;
622 }
623 
624 template <typename ALLOC>
625 bool BasicDepthWalkFilter<ALLOC>::leaveDepthLevel()
626 {
627  m_depth -= 1;
628  return true;
629 }
630 
631 namespace detail
632 {
633 
634 template <typename PATH, typename ALLOC>
635 BasicString<RebindAlloc<ALLOC, char>> getCurrentPathImpl(const PATH& currentPath, const ALLOC& allocator)
636 {
637  BasicString<RebindAlloc<ALLOC, char>> currentPathStr(allocator);
638  for (auto it = currentPath.begin(); it != currentPath.end(); ++it)
639  {
640  if (!currentPathStr.empty())
641  {
642  currentPathStr += ".";
643  }
644  currentPathStr += *it;
645  }
646  return currentPathStr;
647 }
648 
649 template <typename PATH, typename ALLOC>
650 void appendPathImpl(
651  PATH& currentPath, const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex, const ALLOC& allocator)
652 {
653  if (elementIndex == WALKER_NOT_ELEMENT)
654  {
655  currentPath.emplace_back(fieldInfo.schemaName.data(), fieldInfo.schemaName.size());
656  }
657  else
658  {
659  currentPath.back() =
660  toString(fieldInfo.schemaName, allocator) + "[" + toString(elementIndex, allocator) + "]";
661  }
662 }
663 
664 template <typename PATH, typename ALLOC>
665 void popPathImpl(
666  PATH& currentPath, const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex, const ALLOC& allocator)
667 {
668  if (elementIndex == WALKER_NOT_ELEMENT)
669  {
670  currentPath.pop_back();
671  }
672  else
673  {
674  currentPath.back() = toString(fieldInfo.schemaName, allocator);
675  }
676 }
677 
678 template <typename ALLOC>
679 class SubtreeRegexWalkFilter : public IBasicWalkFilter<ALLOC>
680 {
681 public:
682  SubtreeRegexWalkFilter(const typename IBasicWalkFilter<ALLOC>::Path& currentPath,
683  const std::regex& pathRegex, const ALLOC& allocator) :
684  m_currentPath(currentPath),
685  m_pathRegex(pathRegex),
686  m_allocator(allocator)
687  {}
688 
689  bool matches()
690  {
691  return m_matches;
692  }
693 
694  bool beforeArray(
695  const IBasicReflectableDataConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>& fieldInfo) override
696  {
697  m_currentPath.emplace_back(fieldInfo.schemaName.data(), fieldInfo.schemaName.size());
698  m_matches = std::regex_match(getCurrentPath(), m_pathRegex);
699 
700  // terminate when the match is already found (note that array is never null here)
701  return !m_matches;
702  }
703 
704  bool afterArray(const IBasicReflectableDataConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>&) override
705  {
706  m_currentPath.pop_back();
707  return !m_matches; // terminate when the match is already found
708  }
709 
710  bool beforeCompound(const IBasicReflectableDataConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>& fieldInfo,
711  size_t elementIndex) override
712  {
713  appendPath(fieldInfo, elementIndex);
714  m_matches = std::regex_match(getCurrentPath(), m_pathRegex);
715 
716  // terminate when the match is already found (note that compound is never null here)
717  return !m_matches;
718  }
719 
720  bool afterCompound(const IBasicReflectableDataConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>& fieldInfo,
721  size_t elementIndex) override
722  {
723  popPath(fieldInfo, elementIndex);
724  return !m_matches; // terminate when the match is already found
725  }
726 
727  bool beforeValue(const IBasicReflectableDataConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>& fieldInfo,
728  size_t elementIndex) override
729  {
730  appendPath(fieldInfo, elementIndex);
731  m_matches = std::regex_match(getCurrentPath(), m_pathRegex);
732 
733  return !m_matches; // terminate when the match is already found
734  }
735 
736  bool afterValue(const IBasicReflectableDataConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>& fieldInfo,
737  size_t elementIndex) override
738  {
739  popPath(fieldInfo, elementIndex);
740  return !m_matches; // terminate when the match is already found
741  }
742 
743 private:
744  BasicString<RebindAlloc<ALLOC, char>> getCurrentPath() const
745  {
746  return detail::getCurrentPathImpl(m_currentPath, m_allocator);
747  }
748 
749  void appendPath(const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
750  {
751  detail::appendPathImpl(m_currentPath, fieldInfo, elementIndex, m_allocator);
752  }
753 
754  void popPath(const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
755  {
756  detail::popPathImpl(m_currentPath, fieldInfo, elementIndex, m_allocator);
757  }
758 
759  typename IBasicWalkFilter<ALLOC>::Path m_currentPath;
760  std::regex m_pathRegex;
761  ALLOC m_allocator;
762  bool m_matches = false;
763 };
764 
765 } // namespace detail
766 
767 template <typename ALLOC>
768 BasicRegexWalkFilter<ALLOC>::BasicRegexWalkFilter(const char* pathRegex, const ALLOC& allocator) :
769  m_pathRegex(pathRegex),
770  m_allocator(allocator)
771 {}
772 
773 template <typename ALLOC>
775  const IBasicReflectableDataConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo)
776 {
777  m_currentPath.emplace_back(fieldInfo.schemaName.data(), fieldInfo.schemaName.size());
778 
779  if (std::regex_match(getCurrentPath(), m_pathRegex))
780  {
781  return true; // the array itself matches
782  }
783 
784  for (size_t i = 0; i < array->size(); ++i)
785  {
786  m_currentPath.back() =
787  toString(fieldInfo.schemaName, m_allocator) + "[" + toString(i, m_allocator) + "]";
788 
789  if (matchSubtree(array->at(i), fieldInfo))
790  {
791  return true;
792  }
793  }
794 
795  m_currentPath.back() = toString(fieldInfo.schemaName, m_allocator);
796 
797  return false;
798 }
799 
800 template <typename ALLOC>
803 {
804  m_currentPath.pop_back();
805  return true;
806 }
807 
808 template <typename ALLOC>
810  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
811 {
812  appendPath(fieldInfo, elementIndex);
813  if (std::regex_match(getCurrentPath(), m_pathRegex))
814  {
815  return true; // the compound itself matches
816  }
817 
818  return matchSubtree(compound, fieldInfo);
819 }
820 
821 template <typename ALLOC>
823  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
824 {
825  popPath(fieldInfo, elementIndex);
826  return true;
827 }
828 
829 template <typename ALLOC>
831  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
832 {
833  appendPath(fieldInfo, elementIndex);
834  return matchSubtree(value, fieldInfo);
835 }
836 
837 template <typename ALLOC>
839  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
840 {
841  popPath(fieldInfo, elementIndex);
842  return true;
843 }
844 
845 template <typename ALLOC>
846 void BasicRegexWalkFilter<ALLOC>::appendPath(const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
847 {
848  detail::appendPathImpl(m_currentPath, fieldInfo, elementIndex, m_allocator);
849 }
850 
851 template <typename ALLOC>
852 void BasicRegexWalkFilter<ALLOC>::popPath(const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
853 {
854  detail::popPathImpl(m_currentPath, fieldInfo, elementIndex, m_allocator);
855 }
856 
857 template <typename ALLOC>
858 BasicString<RebindAlloc<ALLOC, char>> BasicRegexWalkFilter<ALLOC>::getCurrentPath() const
859 {
860  return detail::getCurrentPathImpl(m_currentPath, m_allocator);
861 }
862 
863 template <typename ALLOC>
864 bool BasicRegexWalkFilter<ALLOC>::matchSubtree(
865  const IBasicReflectableDataConstPtr<ALLOC>& value, const BasicFieldInfo<ALLOC>& fieldInfo) const
866 {
867  if (value != nullptr && TypeInfoUtil::isCompound(fieldInfo.typeInfo.getSchemaType()))
868  {
869  // is a not null compound, try to find match within its subtree
870  BasicDefaultWalkObserver<ALLOC> defaultObserver;
871  detail::SubtreeRegexWalkFilter<ALLOC> subtreeFilter(m_currentPath, m_pathRegex, m_allocator);
872  BasicWalker<ALLOC> walker(defaultObserver, subtreeFilter);
873  walker.walk(value);
874  return subtreeFilter.matches();
875  }
876  else
877  {
878  // try to match a simple value or null compound
879  return std::regex_match(getCurrentPath(), m_pathRegex);
880  }
881 }
882 
883 template <typename ALLOC>
885  m_maxArrayLength(maxArrayLength)
886 {}
887 
888 template <typename ALLOC>
891 {
892  return true;
893 }
894 
895 template <typename ALLOC>
898 {
899  return true;
900 }
901 
902 template <typename ALLOC>
904  const IBasicReflectableDataConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>&, size_t elementIndex)
905 {
906  return filterArrayElement(elementIndex);
907 }
908 
909 template <typename ALLOC>
911  const IBasicReflectableDataConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>&, size_t elementIndex)
912 {
913  return filterArrayElement(elementIndex);
914 }
915 
916 template <typename ALLOC>
918  const IBasicReflectableDataConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>&, size_t elementIndex)
919 {
920  return filterArrayElement(elementIndex);
921 }
922 
923 template <typename ALLOC>
925  const IBasicReflectableDataConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>&, size_t elementIndex)
926 {
927  return filterArrayElement(elementIndex);
928 }
929 
930 template <typename ALLOC>
932 {
933  return elementIndex == WALKER_NOT_ELEMENT ? true : elementIndex < m_maxArrayLength;
934 }
935 
936 template <typename ALLOC>
938  m_walkFilters(walkFilters)
939 {}
940 
941 template <typename ALLOC>
943  const IBasicReflectableDataConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo)
944 {
945  return applyFilters(&IBasicWalkFilter<ALLOC>::beforeArray, array, fieldInfo);
946 }
947 
948 template <typename ALLOC>
950  const IBasicReflectableDataConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo)
951 {
952  return applyFilters(&IBasicWalkFilter<ALLOC>::afterArray, array, fieldInfo);
953 }
954 
955 template <typename ALLOC>
957  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
958 {
959  return applyFilters(&IBasicWalkFilter<ALLOC>::beforeCompound, compound, fieldInfo, elementIndex);
960 }
961 
962 template <typename ALLOC>
964  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
965 {
966  return applyFilters(&IBasicWalkFilter<ALLOC>::afterCompound, compound, fieldInfo, elementIndex);
967 }
968 
969 template <typename ALLOC>
971  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
972 {
973  return applyFilters(&IBasicWalkFilter<ALLOC>::beforeValue, value, fieldInfo, elementIndex);
974 }
975 
976 template <typename ALLOC>
978  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
979 {
980  return applyFilters(&IBasicWalkFilter<ALLOC>::afterValue, value, fieldInfo, elementIndex);
981 }
982 
983 } // namespace zserio
984 
985 #endif // ZSERIO_WALKER_H_INC
BasicAndWalkFilter(const WalkFilters &walkFilters)
Definition: Walker.h:937
std::reference_wrapper< IBasicWalkFilter< ALLOC > > WalkFilterRef
Definition: Walker.h:383
bool beforeArray(const IBasicReflectableDataConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:942
Vector< WalkFilterRef, RebindAlloc< ALLOC, WalkFilterRef > > WalkFilters
Definition: Walker.h:384
bool afterCompound(const IBasicReflectableDataConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:963
bool afterValue(const IBasicReflectableDataConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:977
BasicAndWalkFilter(const BasicAndWalkFilter &other)=delete
~BasicAndWalkFilter() override=default
bool beforeValue(const IBasicReflectableDataConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:970
bool beforeCompound(const IBasicReflectableDataConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:956
BasicAndWalkFilter & operator=(const BasicAndWalkFilter &other)=delete
BasicAndWalkFilter & operator=(BasicAndWalkFilter &&other)=delete
BasicAndWalkFilter(BasicAndWalkFilter &&other)=delete
bool afterArray(const IBasicReflectableDataConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:949
BasicArrayLengthWalkFilter(BasicArrayLengthWalkFilter &&other)=delete
bool beforeCompound(const IBasicReflectableDataConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:903
bool beforeValue(const IBasicReflectableDataConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:917
bool afterArray(const IBasicReflectableDataConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:896
BasicArrayLengthWalkFilter(const BasicArrayLengthWalkFilter &other)=delete
~BasicArrayLengthWalkFilter() override=default
bool afterValue(const IBasicReflectableDataConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:924
bool afterCompound(const IBasicReflectableDataConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:910
BasicArrayLengthWalkFilter & operator=(BasicArrayLengthWalkFilter &&other)=delete
BasicArrayLengthWalkFilter(size_t maxArrayLength)
Definition: Walker.h:884
bool beforeArray(const IBasicReflectableDataConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:889
BasicArrayLengthWalkFilter & operator=(const BasicArrayLengthWalkFilter &other)=delete
BasicDefaultWalkFilter(BasicDefaultWalkFilter &&other)=delete
BasicDefaultWalkFilter & operator=(const BasicDefaultWalkFilter &other)=delete
bool beforeValue(const IBasicReflectableDataConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &, size_t) override
Definition: Walker.h:187
bool afterArray(const IBasicReflectableDataConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &) override
Definition: Walker.h:170
bool beforeCompound(const IBasicReflectableDataConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &, size_t) override
Definition: Walker.h:175
BasicDefaultWalkFilter & operator=(BasicDefaultWalkFilter &&other)=delete
BasicDefaultWalkFilter(const BasicDefaultWalkFilter &other)=delete
~BasicDefaultWalkFilter() override=default
bool afterValue(const IBasicReflectableDataConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &, size_t) override
Definition: Walker.h:192
bool beforeArray(const IBasicReflectableDataConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &) override
Definition: Walker.h:165
bool afterCompound(const IBasicReflectableDataConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &, size_t) override
Definition: Walker.h:181
~BasicDefaultWalkObserver() override=default
BasicDefaultWalkObserver & operator=(BasicDefaultWalkObserver &&other)=delete
BasicDefaultWalkObserver(BasicDefaultWalkObserver &&other)=delete
void endCompound(const IBasicReflectableDataConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &, size_t) override
Definition: Walker.h:128
void endRoot(const IBasicReflectableDataConstPtr< ALLOC > &) override
Definition: Walker.h:117
void beginRoot(const IBasicReflectableDataConstPtr< ALLOC > &) override
Definition: Walker.h:115
void beginCompound(const IBasicReflectableDataConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &, size_t) override
Definition: Walker.h:125
void endArray(const IBasicReflectableDataConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &) override
Definition: Walker.h:122
BasicDefaultWalkObserver(const BasicDefaultWalkObserver &other)=delete
void beginArray(const IBasicReflectableDataConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &) override
Definition: Walker.h:120
BasicDefaultWalkObserver & operator=(const BasicDefaultWalkObserver &other)=delete
void visitValue(const IBasicReflectableDataConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &, size_t) override
Definition: Walker.h:131
bool beforeCompound(const IBasicReflectableDataConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:589
BasicDepthWalkFilter(size_t maxDepth)
Definition: Walker.h:569
BasicDepthWalkFilter & operator=(const BasicDepthWalkFilter &other)=delete
~BasicDepthWalkFilter() override=default
bool beforeArray(const IBasicReflectableDataConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:575
bool afterCompound(const IBasicReflectableDataConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:596
bool afterValue(const IBasicReflectableDataConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:610
bool afterArray(const IBasicReflectableDataConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:582
bool beforeValue(const IBasicReflectableDataConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:603
BasicDepthWalkFilter & operator=(BasicDepthWalkFilter &&other)=delete
BasicDepthWalkFilter(BasicDepthWalkFilter &&other)=delete
BasicDepthWalkFilter(const BasicDepthWalkFilter &other)=delete
BasicRegexWalkFilter & operator=(BasicRegexWalkFilter &&other)=delete
BasicRegexWalkFilter & operator=(const BasicRegexWalkFilter &other)=delete
~BasicRegexWalkFilter() override=default
BasicRegexWalkFilter(const char *pathRegex, const ALLOC &allocator=ALLOC())
Definition: Walker.h:768
bool afterArray(const IBasicReflectableDataConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:801
BasicRegexWalkFilter(const BasicRegexWalkFilter &other)=delete
bool beforeCompound(const IBasicReflectableDataConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:809
BasicRegexWalkFilter(BasicRegexWalkFilter &&other)=delete
bool afterValue(const IBasicReflectableDataConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:838
bool beforeArray(const IBasicReflectableDataConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:774
bool beforeValue(const IBasicReflectableDataConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:830
bool afterCompound(const IBasicReflectableDataConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:822
BasicWalker(IBasicWalkObserver< ALLOC > &walkObserver)
Definition: Walker.h:453
BasicWalker & operator=(BasicWalker &&other)=delete
BasicWalker & operator=(const BasicWalker &other)=delete
~BasicWalker()=default
BasicWalker(const BasicWalker &other)=delete
BasicWalker(BasicWalker &&other)=delete
void walk(const IBasicReflectableDataConstPtr< ALLOC > &compound)
Definition: Walker.h:465
virtual Span< const BasicFieldInfo< ALLOC > > getFields() const =0
virtual SchemaType getSchemaType() const =0
virtual std::string_view getSchemaName() const =0
virtual bool beforeArray(const IBasicReflectableDataConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo)=0
virtual bool beforeValue(const IBasicReflectableDataConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex)=0
Vector< BasicString< RebindAlloc< ALLOC, char > >, RebindAlloc< ALLOC, BasicString< RebindAlloc< ALLOC, char > >> > Path
Definition: IWalkFilter.h:99
virtual bool afterValue(const IBasicReflectableDataConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex)=0
virtual bool afterArray(const IBasicReflectableDataConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo)=0
virtual bool afterCompound(const IBasicReflectableDataConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex)=0
virtual bool beforeCompound(const IBasicReflectableDataConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex)=0
constexpr iterator end() const noexcept
Definition: Span.h:210
constexpr iterator begin() const noexcept
Definition: Span.h:200
typename IBasicReflectableData< ALLOC >::ConstPtr IBasicReflectableDataConstPtr
std::basic_string< char, std::char_traits< char >, ALLOC > BasicString
Definition: String.h:17
std::vector< T, ALLOC > Vector
Definition: Vector.h:13
IBasicReflectableDataConstPtr< ALLOC > reflectable(const T &value, const ALLOC &allocator=ALLOC())
const IBasicTypeInfo< ALLOC > & typeInfo()
Definition: ITypeInfo.h:668
BasicString< RebindAlloc< ALLOC, char > > toString(T value, const ALLOC &allocator=ALLOC())
std::string_view schemaName
Definition: ITypeInfo.h:493
static bool hasChoice(SchemaType schemaType)
static bool isCompound(SchemaType schemaType)
Definition: TypeInfoUtil.cpp:6