Zserio C++ runtime library  1.0.0
Built for Zserio 2.13.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 <functional>
5 #include <regex>
6 #include <algorithm>
7 
8 #include "zserio/IReflectable.h"
9 #include "zserio/ITypeInfo.h"
10 #include "zserio/WalkerConst.h"
11 #include "zserio/IWalkObserver.h"
12 #include "zserio/IWalkFilter.h"
13 #include "zserio/TypeInfoUtil.h"
15 #include "zserio/String.h"
16 #include "zserio/Vector.h"
17 
18 namespace zserio
19 {
20 
21 template <typename ALLOC>
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 IBasicReflectableConstPtr<ALLOC>& compound);
71 
72 private:
73  void walkFields(const IBasicReflectableConstPtr<ALLOC>& compound, const IBasicTypeInfo<ALLOC>& typeInfo);
74  bool walkField(const IBasicReflectableConstPtr<ALLOC>& reflectable, const BasicFieldInfo<ALLOC>& fieldInfo);
75  bool walkFieldValue(const IBasicReflectableConstPtr<ALLOC>& reflectable,
76  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex = WALKER_NOT_ELEMENT);
77 
78  IBasicWalkObserver<ALLOC>& m_walkObserver;
79  BasicDefaultWalkFilter<ALLOC> m_defaultWalkFilter;
80  IBasicWalkFilter<ALLOC>& m_walkFilter;
81 };
82 
86 template <typename ALLOC = std::allocator<uint8_t>>
88 {
89 public:
94  BasicDefaultWalkObserver() = default;
95  ~BasicDefaultWalkObserver() override = default;
104  BasicDefaultWalkObserver(const BasicDefaultWalkObserver& other) = delete;
106 
114  void endRoot(const IBasicReflectableConstPtr<ALLOC>&) override {}
115 
117  const BasicFieldInfo<ALLOC>&) override {}
119  const BasicFieldInfo<ALLOC>&) override {}
120 
122  const BasicFieldInfo<ALLOC>&, size_t) override {}
124  const BasicFieldInfo<ALLOC>&, size_t) override {}
125 
127  const BasicFieldInfo<ALLOC>&, size_t) override {}
128 };
129 
133 template <typename ALLOC = std::allocator<uint8_t>>
134 class BasicDefaultWalkFilter : public IBasicWalkFilter<ALLOC>
135 {
136 public:
141  BasicDefaultWalkFilter() = default;
142  ~BasicDefaultWalkFilter() override = default;
151  BasicDefaultWalkFilter(const BasicDefaultWalkFilter& other) = delete;
153 
161  {
162  return true;
163  }
164 
166  {
167  return true;
168  }
169 
171  const BasicFieldInfo<ALLOC>&, size_t) override
172  {
173  return true;
174  }
175 
177  const BasicFieldInfo<ALLOC>&, size_t) override
178  {
179  return true;
180  }
181 
183  const BasicFieldInfo<ALLOC>&, size_t) override
184  {
185  return true;
186  }
187 
189  const BasicFieldInfo<ALLOC>&, size_t) override
190  {
191  return true;
192  }
193 };
194 
198 template <typename ALLOC = std::allocator<uint8_t>>
200 {
201 public:
207  explicit BasicDepthWalkFilter(size_t maxDepth);
208 
212  ~BasicDepthWalkFilter() override = default;
213 
218  BasicDepthWalkFilter(const BasicDepthWalkFilter& other) = delete;
219  BasicDepthWalkFilter& operator=(const BasicDepthWalkFilter& other) = delete;
220 
221  BasicDepthWalkFilter(BasicDepthWalkFilter&& other) = delete;
227  bool beforeArray(const IBasicReflectableConstPtr<ALLOC>& array,
228  const BasicFieldInfo<ALLOC>& fieldInfo) override;
229  bool afterArray(const IBasicReflectableConstPtr<ALLOC>& array,
230  const BasicFieldInfo<ALLOC>& fieldInfo) override;
231 
232  bool beforeCompound(const IBasicReflectableConstPtr<ALLOC>& compound,
233  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
234  bool afterCompound(const IBasicReflectableConstPtr<ALLOC>& compound,
235  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
236 
237  bool beforeValue(const IBasicReflectableConstPtr<ALLOC>& value,
238  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
239  bool afterValue(const IBasicReflectableConstPtr<ALLOC>& value,
240  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
241 
242 private:
243  bool enterDepthLevel();
244  bool leaveDepthLevel();
245 
246  size_t m_maxDepth;
247  size_t m_depth;
248 };
249 
259 template <typename ALLOC = std::allocator<uint8_t>>
261 {
262 public:
268  explicit BasicRegexWalkFilter(const char* pathRegex, const ALLOC& allocator = ALLOC());
269 
273  ~BasicRegexWalkFilter() override = default;
274 
279  BasicRegexWalkFilter(const BasicRegexWalkFilter& other) = delete;
280  BasicRegexWalkFilter& operator=(const BasicRegexWalkFilter& other) = delete;
281 
282  BasicRegexWalkFilter(BasicRegexWalkFilter&& other) = delete;
288  bool beforeArray(const IBasicReflectableConstPtr<ALLOC>& array,
289  const BasicFieldInfo<ALLOC>& fieldInfo) override;
290  bool afterArray(const IBasicReflectableConstPtr<ALLOC>& array,
291  const BasicFieldInfo<ALLOC>& fieldInfo) override;
292 
293  bool beforeCompound(const IBasicReflectableConstPtr<ALLOC>& compound,
294  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
295  bool afterCompound(const IBasicReflectableConstPtr<ALLOC>& compound,
296  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
297 
298  bool beforeValue(const IBasicReflectableConstPtr<ALLOC>& value,
299  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
300  bool afterValue(const IBasicReflectableConstPtr<ALLOC>& value,
301  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
302 
303 private:
304  void appendPath(const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex);
305  void popPath(const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex);
306  string<ALLOC> getCurrentPath() const;
307  bool matchSubtree(const IBasicReflectableConstPtr<ALLOC>& value,
308  const BasicFieldInfo<ALLOC>& fieldInfo) const;
309 
310  vector<string<ALLOC>, ALLOC> m_currentPath;
311  std::regex m_pathRegex;
312  ALLOC m_allocator; // TODO[Mi-L@]: Check how std::regex_match allocates when results are omitted!
313 };
314 
318 template <typename ALLOC = std::allocator<uint8_t>>
320 {
321 public:
327  explicit BasicArrayLengthWalkFilter(size_t maxArrayLength);
328 
332  ~BasicArrayLengthWalkFilter() override = default;
333 
340 
347  bool beforeArray(const IBasicReflectableConstPtr<ALLOC>& array,
348  const BasicFieldInfo<ALLOC>& fieldInfo) override;
349  bool afterArray(const IBasicReflectableConstPtr<ALLOC>& array,
350  const BasicFieldInfo<ALLOC>& fieldInfo) override;
351 
352  bool beforeCompound(const IBasicReflectableConstPtr<ALLOC>& compound,
353  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
354  bool afterCompound(const IBasicReflectableConstPtr<ALLOC>& compound,
355  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
356 
357  bool beforeValue(const IBasicReflectableConstPtr<ALLOC>& value,
358  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
359  bool afterValue(const IBasicReflectableConstPtr<ALLOC>& value,
360  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
361 
362 private:
363  bool filterArrayElement(size_t elementIndex);
364 
365  size_t m_maxArrayLength;
366 };
367 
374 template <typename ALLOC = std::allocator<uint8_t>>
376 {
377 public:
378  using WalkFilterRef = std::reference_wrapper<IBasicWalkFilter<ALLOC>>;
380 
386  explicit BasicAndWalkFilter(const WalkFilters& walkFilters);
387 
391  ~BasicAndWalkFilter() override = default;
392 
397  BasicAndWalkFilter(const BasicAndWalkFilter& other) = delete;
398  BasicAndWalkFilter& operator=(const BasicAndWalkFilter& other) = delete;
399 
400  BasicAndWalkFilter(BasicAndWalkFilter&& other) = delete;
406  bool beforeArray(const IBasicReflectableConstPtr<ALLOC>& array,
407  const BasicFieldInfo<ALLOC>& fieldInfo) override;
408  bool afterArray(const IBasicReflectableConstPtr<ALLOC>& array,
409  const BasicFieldInfo<ALLOC>& fieldInfo) override;
410 
411  bool beforeCompound(const IBasicReflectableConstPtr<ALLOC>& compound,
412  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
413  bool afterCompound(const IBasicReflectableConstPtr<ALLOC>& compound,
414  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
415 
416  bool beforeValue(const IBasicReflectableConstPtr<ALLOC>& value,
417  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
418  bool afterValue(const IBasicReflectableConstPtr<ALLOC>& value,
419  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
420 
421 private:
422  template <typename FILTER_FUNC, typename ...ARGS>
423  bool applyFilters(FILTER_FUNC filterFunc, ARGS... args)
424  {
425  bool result = true;
426  for (IBasicWalkFilter<ALLOC>& walkFilter : m_walkFilters)
427  result &= (walkFilter.*filterFunc)(args...);
428  return result;
429  }
430 
431  WalkFilters m_walkFilters;
432 };
433 
445 template <typename ALLOC>
447  m_walkObserver(walkObserver), m_walkFilter(m_defaultWalkFilter)
448 {}
449 
450 template <typename ALLOC>
452  m_walkObserver(walkObserver), m_walkFilter(walkFilter)
453 {}
454 
455 template <typename ALLOC>
457 {
458  if (!compound)
459  throw CppRuntimeException("Walker: Root object cannot be NULL!");
460 
461  const IBasicTypeInfo<ALLOC>& typeInfo = compound->getTypeInfo();
462  if (!TypeInfoUtil::isCompound(typeInfo.getSchemaType()))
463  {
464  throw CppRuntimeException("Walker: Root object '") << typeInfo.getSchemaName() <<
465  "' is not a compound type!";
466  }
467 
468  m_walkObserver.beginRoot(compound);
469  walkFields(compound, typeInfo);
470  m_walkObserver.endRoot(compound);
471 }
472 
473 template <typename ALLOC>
475  const IBasicTypeInfo<ALLOC>& typeInfo)
476 {
477  if (TypeInfoUtil::hasChoice(typeInfo.getSchemaType()))
478  {
479  StringView compoundChoice = compound->getChoice();
480  if (!compoundChoice.empty())
481  {
482  Span<const BasicFieldInfo<ALLOC>> fields = typeInfo.getFields();
483  auto fieldsIt = std::find_if(fields.begin(), fields.end(),
484  [compoundChoice](const BasicFieldInfo<ALLOC>& fieldInfo) {
485  return fieldInfo.schemaName == compoundChoice; });
486  if (fieldsIt != fields.end())
487  {
488  walkField(compound->getField(compoundChoice), *fieldsIt);
489  }
490  }
491  // else uninitialized or empty branch
492  }
493  else
494  {
495  for (const BasicFieldInfo<ALLOC>& fieldInfo : typeInfo.getFields())
496  {
497  if (!walkField(compound->getField(fieldInfo.schemaName), fieldInfo))
498  break;
499  }
500  }
501 }
502 
503 template <typename ALLOC>
505  const IBasicReflectableConstPtr<ALLOC>& reflectable, const BasicFieldInfo<ALLOC>& fieldInfo)
506 {
507  if (reflectable && fieldInfo.isArray)
508  {
509  if (m_walkFilter.beforeArray(reflectable, fieldInfo))
510  {
511  m_walkObserver.beginArray(reflectable, fieldInfo);
512  for (size_t i = 0; i < reflectable->size(); ++i)
513  {
514  if (!walkFieldValue(reflectable->at(i), fieldInfo, i))
515  break;
516  }
517  m_walkObserver.endArray(reflectable, fieldInfo);
518 
519  }
520  return m_walkFilter.afterArray(reflectable, fieldInfo);
521  }
522  else
523  {
524  return walkFieldValue(reflectable, fieldInfo);
525  }
526 }
527 
528 template <typename ALLOC>
530  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
531 {
532  const IBasicTypeInfo<ALLOC>& typeInfo = fieldInfo.typeInfo;
533  if (reflectable && TypeInfoUtil::isCompound(typeInfo.getSchemaType()))
534  {
535  if (m_walkFilter.beforeCompound(reflectable, fieldInfo, elementIndex))
536  {
537  m_walkObserver.beginCompound(reflectable, fieldInfo, elementIndex);
538  walkFields(reflectable, typeInfo);
539  m_walkObserver.endCompound(reflectable, fieldInfo, elementIndex);
540  }
541  return m_walkFilter.afterCompound(reflectable, fieldInfo, elementIndex);
542  }
543  else
544  {
545  if (m_walkFilter.beforeValue(reflectable, fieldInfo, elementIndex))
546  m_walkObserver.visitValue(reflectable, fieldInfo, elementIndex);
547  return m_walkFilter.afterValue(reflectable, fieldInfo, elementIndex);
548  }
549 }
550 
551 template <typename ALLOC>
553  m_maxDepth(maxDepth), m_depth(1)
554 {}
555 
556 template <typename ALLOC>
558  const BasicFieldInfo<ALLOC>&)
559 {
560  return enterDepthLevel();
561 }
562 
563 template <typename ALLOC>
565  const BasicFieldInfo<ALLOC>&)
566 {
567  return leaveDepthLevel();
568 }
569 
570 template <typename ALLOC>
572  const BasicFieldInfo<ALLOC>&, size_t)
573 {
574  return enterDepthLevel();
575 }
576 
577 template <typename ALLOC>
579  const BasicFieldInfo<ALLOC>&, size_t)
580 {
581  return leaveDepthLevel();
582 }
583 
584 template <typename ALLOC>
586  const BasicFieldInfo<ALLOC>&, size_t)
587 {
588  return m_depth <= m_maxDepth;
589 }
590 
591 template <typename ALLOC>
593  const BasicFieldInfo<ALLOC>&, size_t)
594 {
595  return true;
596 }
597 
598 template <typename ALLOC>
600 {
601  const bool enter = (m_depth <= m_maxDepth);
602  m_depth += 1;
603  return enter;
604 }
605 
606 template <typename ALLOC>
608 {
609  m_depth -= 1;
610  return true;
611 }
612 
613 namespace detail
614 {
615 
616 template <typename ALLOC>
617 string<ALLOC> getCurrentPathImpl(
618  const vector<string<ALLOC>, ALLOC>& currentPath,
619  const ALLOC& allocator)
620 {
621  string<ALLOC> currentPathStr(allocator);
622  for (auto it = currentPath.begin(); it != currentPath.end(); ++it)
623  {
624  if (!currentPathStr.empty())
625  currentPathStr += ".";
626  currentPathStr += *it;
627  }
628  return currentPathStr;
629 }
630 
631 template <typename ALLOC>
632 void appendPathImpl(vector<string<ALLOC>, ALLOC>& currentPath,
633  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex, const ALLOC& allocator)
634 {
635  if (elementIndex == WALKER_NOT_ELEMENT)
636  {
637  currentPath.emplace_back(fieldInfo.schemaName.data(), fieldInfo.schemaName.size(), allocator);
638  }
639  else
640  {
641  currentPath.back() = toString(fieldInfo.schemaName, allocator) +
642  "[" + toString(elementIndex, allocator) + "]";
643  }
644 }
645 
646 template <typename ALLOC>
647 void popPathImpl(vector<string<ALLOC>, ALLOC>& currentPath,
648  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex, const ALLOC& allocator)
649 {
650  if (elementIndex == WALKER_NOT_ELEMENT)
651  currentPath.pop_back();
652  else
653  currentPath.back() = toString(fieldInfo.schemaName, allocator);
654 }
655 
656 template <typename ALLOC>
657 class SubtreeRegexWalkFilter : public IBasicWalkFilter<ALLOC>
658 {
659 public:
660  SubtreeRegexWalkFilter(const vector<string<ALLOC>, ALLOC>& currentPath,
661  const std::regex& pathRegex, const ALLOC& allocator) :
662  m_currentPath(currentPath), m_pathRegex(pathRegex), m_allocator(allocator)
663  {}
664 
665  bool matches()
666  {
667  return m_matches;
668  }
669 
671  const BasicFieldInfo<ALLOC>& fieldInfo) override
672  {
673  m_currentPath.emplace_back(fieldInfo.schemaName.data(), fieldInfo.schemaName.size());
674  m_matches = std::regex_match(getCurrentPath(), m_pathRegex);
675 
676  // terminate when the match is already found (note that array is never null here)
677  return !m_matches;
678  }
679 
681  {
682  m_currentPath.pop_back();
683  return !m_matches; // terminate when the match is already found
684  }
685 
687  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override
688  {
689  appendPath(fieldInfo, elementIndex);
690  m_matches = std::regex_match(getCurrentPath(), m_pathRegex);
691 
692  // terminate when the match is already found (note that compound is never null here)
693  return !m_matches;
694  }
695 
697  size_t elementIndex) override
698  {
699  popPath(fieldInfo, elementIndex);
700  return !m_matches; // terminate when the match is already found
701  }
702 
704  size_t elementIndex) override
705  {
706  appendPath(fieldInfo, elementIndex);
707  m_matches = std::regex_match(getCurrentPath(), m_pathRegex);
708 
709  return !m_matches; // terminate when the match is already found
710  }
711 
713  size_t elementIndex) override
714  {
715  popPath(fieldInfo, elementIndex);
716  return !m_matches; // terminate when the match is already found
717  }
718 
719 private:
720  string<ALLOC> getCurrentPath() const
721  {
722  return detail::getCurrentPathImpl(m_currentPath, m_allocator);
723  }
724 
725  void appendPath(const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
726  {
727  detail::appendPathImpl(m_currentPath, fieldInfo, elementIndex, m_allocator);
728  }
729 
730  void popPath(const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
731  {
732  detail::popPathImpl(m_currentPath, fieldInfo, elementIndex, m_allocator);
733  }
734 
735  vector<string<ALLOC>, ALLOC> m_currentPath;
736  std::regex m_pathRegex;
737  ALLOC m_allocator;
738  bool m_matches = false;
739 };
740 
741 } // namespace detail
742 
743 template <typename ALLOC>
744 BasicRegexWalkFilter<ALLOC>::BasicRegexWalkFilter(const char* pathRegex, const ALLOC& allocator) :
745  m_pathRegex(pathRegex), m_allocator(allocator)
746 {}
747 
748 template <typename ALLOC>
750  const BasicFieldInfo<ALLOC>& fieldInfo)
751 {
752  m_currentPath.emplace_back(fieldInfo.schemaName.data(), fieldInfo.schemaName.size(), m_allocator);
753 
754  if (std::regex_match(getCurrentPath(), m_pathRegex))
755  return true; // the array itself matches
756 
757  for (size_t i = 0; i < array->size(); ++i)
758  {
759  m_currentPath.back() = toString(fieldInfo.schemaName, m_allocator) +
760  "[" + toString(i, m_allocator) + "]";
761 
762  if (matchSubtree(array->at(i), fieldInfo))
763  return true;
764  }
765 
766  m_currentPath.back() = toString(fieldInfo.schemaName, m_allocator);
767 
768  return false;
769 }
770 
771 template <typename ALLOC>
773  const BasicFieldInfo<ALLOC>&)
774 {
775  m_currentPath.pop_back();
776  return true;
777 }
778 
779 template <typename ALLOC>
781  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
782 {
783  appendPath(fieldInfo, elementIndex);
784  if (std::regex_match(getCurrentPath(), m_pathRegex))
785  return true; // the compound itself matches
786 
787  return matchSubtree(compound, fieldInfo);
788 }
789 
790 template <typename ALLOC>
792  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
793 {
794  popPath(fieldInfo, elementIndex);
795  return true;
796 }
797 
798 template <typename ALLOC>
800  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
801 {
802  appendPath(fieldInfo, elementIndex);
803  return matchSubtree(value, fieldInfo);
804 }
805 
806 template <typename ALLOC>
808  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
809 {
810  popPath(fieldInfo, elementIndex);
811  return true;
812 }
813 
814 template <typename ALLOC>
815 void BasicRegexWalkFilter<ALLOC>::appendPath(const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
816 {
817  detail::appendPathImpl(m_currentPath, fieldInfo, elementIndex, m_allocator);
818 }
819 
820 template <typename ALLOC>
821 void BasicRegexWalkFilter<ALLOC>::popPath(const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
822 {
823  detail::popPathImpl(m_currentPath, fieldInfo, elementIndex, m_allocator);
824 }
825 
826 template <typename ALLOC>
828 {
829  return detail::getCurrentPathImpl(m_currentPath, m_allocator);
830 }
831 
832 template <typename ALLOC>
834  const BasicFieldInfo<ALLOC>& fieldInfo) const
835 {
836  if (value != nullptr && TypeInfoUtil::isCompound(fieldInfo.typeInfo.getSchemaType()))
837  {
838  // is a not null compound, try to find match within its subtree
839  BasicDefaultWalkObserver<ALLOC> defaultObserver;
840  detail::SubtreeRegexWalkFilter<ALLOC> subtreeFilter(m_currentPath, m_pathRegex, m_allocator);
841  BasicWalker<ALLOC> walker(defaultObserver, subtreeFilter);
842  walker.walk(value);
843  return subtreeFilter.matches();
844  }
845  else
846  {
847  // try to match a simple value or null compound
848  return std::regex_match(getCurrentPath(), m_pathRegex);
849  }
850 }
851 
852 template <typename ALLOC>
854  m_maxArrayLength(maxArrayLength)
855 {}
856 
857 template <typename ALLOC>
859  const BasicFieldInfo<ALLOC>&)
860 {
861  return true;
862 }
863 
864 template <typename ALLOC>
866  const BasicFieldInfo<ALLOC>&)
867 {
868  return true;
869 }
870 
871 template <typename ALLOC>
873  const BasicFieldInfo<ALLOC>&, size_t elementIndex)
874 {
875  return filterArrayElement(elementIndex);
876 }
877 
878 template <typename ALLOC>
880  const BasicFieldInfo<ALLOC>&, size_t elementIndex)
881 {
882  return filterArrayElement(elementIndex);
883 }
884 
885 template <typename ALLOC>
887  const BasicFieldInfo<ALLOC>&, size_t elementIndex)
888 {
889  return filterArrayElement(elementIndex);
890 }
891 
892 template <typename ALLOC>
894  const BasicFieldInfo<ALLOC>&, size_t elementIndex)
895 {
896  return filterArrayElement(elementIndex);
897 }
898 
899 template <typename ALLOC>
901 {
902  return elementIndex == WALKER_NOT_ELEMENT ? true : elementIndex < m_maxArrayLength;
903 }
904 
905 template <typename ALLOC>
907  m_walkFilters(walkFilters)
908 {}
909 
910 template <typename ALLOC>
912  const BasicFieldInfo<ALLOC>& fieldInfo)
913 {
914  return applyFilters(&IBasicWalkFilter<ALLOC>::beforeArray, array, fieldInfo);
915 }
916 
917 template <typename ALLOC>
919  const BasicFieldInfo<ALLOC>& fieldInfo)
920 {
921  return applyFilters(&IBasicWalkFilter<ALLOC>::afterArray, array, fieldInfo);
922 }
923 
924 template <typename ALLOC>
926  const BasicFieldInfo<ALLOC>& fieldInfo,
927  size_t elementIndex)
928 {
929  return applyFilters(&IBasicWalkFilter<ALLOC>::beforeCompound, compound, fieldInfo, elementIndex);
930 }
931 
932 template <typename ALLOC>
934  const BasicFieldInfo<ALLOC>& fieldInfo,
935  size_t elementIndex)
936 {
937  return applyFilters(&IBasicWalkFilter<ALLOC>::afterCompound, compound, fieldInfo, elementIndex);
938 }
939 
940 template <typename ALLOC>
942  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
943 {
944  return applyFilters(&IBasicWalkFilter<ALLOC>::beforeValue, value, fieldInfo, elementIndex);
945 }
946 
947 template <typename ALLOC>
949  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
950 {
951  return applyFilters(&IBasicWalkFilter<ALLOC>::afterValue, value, fieldInfo, elementIndex);
952 }
953 
954 } // namespace zserio
955 
956 #endif // ZSERIO_WALKER_H_INC
typename IBasicReflectable< ALLOC >::ConstPtr IBasicReflectableConstPtr
Definition: IReflectable.h:519
void walk(const IBasicReflectableConstPtr< ALLOC > &compound)
Definition: Walker.h:456
std::reference_wrapper< IBasicWalkFilter< ALLOC >> WalkFilterRef
Definition: Walker.h:378
BasicWalker & operator=(const BasicWalker &other)=delete
bool beforeCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:925
bool afterCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:933
bool afterArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:564
BasicDepthWalkFilter(size_t maxDepth)
Definition: Walker.h:552
bool beforeArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:911
bool afterCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:578
bool beforeArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:557
string< ALLOC > toString(T value, const ALLOC &allocator=ALLOC())
bool beforeCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:571
void endArray(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &) override
Definition: Walker.h:118
virtual Span< const BasicFieldInfo< ALLOC > > getFields() const =0
BasicArrayLengthWalkFilter(size_t maxArrayLength)
Definition: Walker.h:853
bool afterArray(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &) override
Definition: Walker.h:165
BasicRegexWalkFilter(const char *pathRegex, const ALLOC &allocator=ALLOC())
Definition: Walker.h:744
bool beforeCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:872
bool beforeArray(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &) override
Definition: Walker.h:160
void beginCompound(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &, size_t) override
Definition: Walker.h:121
vector< WalkFilterRef, ALLOC > WalkFilters
Definition: Walker.h:379
bool afterValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:893
StringView schemaName
Definition: ITypeInfo.h:369
void endCompound(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &, size_t) override
Definition: Walker.h:123
void beginArray(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &) override
Definition: Walker.h:116
virtual StringView getSchemaName() const =0
bool afterArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:772
static bool isCompound(SchemaType schemaType)
Definition: TypeInfoUtil.cpp:6
bool afterCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:791
void beginRoot(const IBasicReflectableConstPtr< ALLOC > &) override
Definition: Walker.h:113
virtual SchemaType getSchemaType() const =0
BasicWalker(IBasicWalkObserver< ALLOC > &walkObserver)
Definition: Walker.h:446
bool afterValue(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &, size_t) override
Definition: Walker.h:188
bool afterValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:948
std::vector< T, RebindAlloc< ALLOC, T >> vector
Definition: Vector.h:16
void endRoot(const IBasicReflectableConstPtr< ALLOC > &) override
Definition: Walker.h:114
static bool hasChoice(SchemaType schemaType)
bool beforeValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:886
bool afterArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:918
bool beforeCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:780
bool afterCompound(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &, size_t) override
Definition: Walker.h:176
bool beforeCompound(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &, size_t) override
Definition: Walker.h:170
void visitValue(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &, size_t) override
Definition: Walker.h:126
constexpr iterator begin() const noexcept
Definition: Span.h:195
~BasicWalker()=default
BasicAndWalkFilter(const WalkFilters &walkFilters)
Definition: Walker.h:906
bool beforeValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:799
std::basic_string< char, std::char_traits< char >, RebindAlloc< ALLOC, char >> string
Definition: String.h:16
bool beforeValue(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &, size_t) override
Definition: Walker.h:182
bool beforeValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:941
constexpr bool empty() const noexcept
Definition: StringView.h:267
constexpr iterator end() const noexcept
Definition: Span.h:205
bool beforeArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:749
bool beforeArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:858
bool afterValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:807
const IBasicTypeInfo< ALLOC > & typeInfo
Definition: ITypeInfo.h:370
bool afterCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:879
bool afterValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:592
bool beforeValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:585
bool afterArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:865