Zserio C++ runtime library  1.0.1
Built for Zserio 2.14.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 
8 #include "zserio/IReflectable.h"
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 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:
95  ~BasicDefaultWalkObserver() override = default;
106 
114  {}
116  {}
117 
119  {}
121  {}
122 
124  {}
126  {}
127 
129  {}
130 };
131 
135 template <typename ALLOC = std::allocator<uint8_t>>
137 {
138 public:
144  ~BasicDefaultWalkFilter() override = default;
155 
163  {
164  return true;
165  }
166 
168  {
169  return true;
170  }
171 
173  {
174  return true;
175  }
176 
178  {
179  return true;
180  }
181 
183  {
184  return true;
185  }
186 
188  {
189  return true;
190  }
191 };
192 
196 template <typename ALLOC = std::allocator<uint8_t>>
198 {
199 public:
205  explicit BasicDepthWalkFilter(size_t maxDepth);
206 
210  ~BasicDepthWalkFilter() override = default;
211 
218 
225  bool beforeArray(
226  const IBasicReflectableConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo) override;
227  bool afterArray(
228  const IBasicReflectableConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo) override;
229 
231  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
232  bool afterCompound(const IBasicReflectableConstPtr<ALLOC>& compound, const BasicFieldInfo<ALLOC>& fieldInfo,
233  size_t elementIndex) override;
234 
235  bool beforeValue(const IBasicReflectableConstPtr<ALLOC>& value, const BasicFieldInfo<ALLOC>& fieldInfo,
236  size_t elementIndex) override;
237  bool afterValue(const IBasicReflectableConstPtr<ALLOC>& value, const BasicFieldInfo<ALLOC>& fieldInfo,
238  size_t elementIndex) override;
239 
240 private:
241  bool enterDepthLevel();
242  bool leaveDepthLevel();
243 
244  size_t m_maxDepth;
245  size_t m_depth;
246 };
247 
257 template <typename ALLOC = std::allocator<uint8_t>>
259 {
260 public:
266  explicit BasicRegexWalkFilter(const char* pathRegex, const ALLOC& allocator = ALLOC());
267 
271  ~BasicRegexWalkFilter() override = default;
272 
279 
286  bool beforeArray(
287  const IBasicReflectableConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo) override;
288  bool afterArray(
289  const IBasicReflectableConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo) override;
290 
292  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
293  bool afterCompound(const IBasicReflectableConstPtr<ALLOC>& compound, const BasicFieldInfo<ALLOC>& fieldInfo,
294  size_t elementIndex) override;
295 
296  bool beforeValue(const IBasicReflectableConstPtr<ALLOC>& value, const BasicFieldInfo<ALLOC>& fieldInfo,
297  size_t elementIndex) override;
298  bool afterValue(const IBasicReflectableConstPtr<ALLOC>& value, const BasicFieldInfo<ALLOC>& fieldInfo,
299  size_t elementIndex) override;
300 
301 private:
302  void appendPath(const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex);
303  void popPath(const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex);
304  string<ALLOC> getCurrentPath() const;
305  bool matchSubtree(
306  const IBasicReflectableConstPtr<ALLOC>& value, const BasicFieldInfo<ALLOC>& fieldInfo) const;
307 
308  vector<string<ALLOC>, ALLOC> m_currentPath;
309  std::regex m_pathRegex;
310  ALLOC m_allocator; // TODO[Mi-L@]: Check how std::regex_match allocates when results are omitted!
311 };
312 
316 template <typename ALLOC = std::allocator<uint8_t>>
318 {
319 public:
325  explicit BasicArrayLengthWalkFilter(size_t maxArrayLength);
326 
330  ~BasicArrayLengthWalkFilter() override = default;
331 
338 
345  bool beforeArray(
346  const IBasicReflectableConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo) override;
347  bool afterArray(
348  const IBasicReflectableConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo) override;
349 
351  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
352  bool afterCompound(const IBasicReflectableConstPtr<ALLOC>& compound, const BasicFieldInfo<ALLOC>& fieldInfo,
353  size_t elementIndex) override;
354 
355  bool beforeValue(const IBasicReflectableConstPtr<ALLOC>& value, const BasicFieldInfo<ALLOC>& fieldInfo,
356  size_t elementIndex) override;
357  bool afterValue(const IBasicReflectableConstPtr<ALLOC>& value, const BasicFieldInfo<ALLOC>& fieldInfo,
358  size_t elementIndex) override;
359 
360 private:
361  bool filterArrayElement(size_t elementIndex);
362 
363  size_t m_maxArrayLength;
364 };
365 
372 template <typename ALLOC = std::allocator<uint8_t>>
374 {
375 public:
376  using WalkFilterRef = std::reference_wrapper<IBasicWalkFilter<ALLOC>>;
378 
384  explicit BasicAndWalkFilter(const WalkFilters& walkFilters);
385 
389  ~BasicAndWalkFilter() override = default;
390 
395  BasicAndWalkFilter(const BasicAndWalkFilter& other) = delete;
397 
404  bool beforeArray(
405  const IBasicReflectableConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo) override;
406  bool afterArray(
407  const IBasicReflectableConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo) override;
408 
410  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex) override;
411  bool afterCompound(const IBasicReflectableConstPtr<ALLOC>& compound, const BasicFieldInfo<ALLOC>& fieldInfo,
412  size_t elementIndex) override;
413 
414  bool beforeValue(const IBasicReflectableConstPtr<ALLOC>& value, const BasicFieldInfo<ALLOC>& fieldInfo,
415  size_t elementIndex) override;
416  bool afterValue(const IBasicReflectableConstPtr<ALLOC>& value, const BasicFieldInfo<ALLOC>& fieldInfo,
417  size_t elementIndex) override;
418 
419 private:
420  template <typename FILTER_FUNC, typename... ARGS>
421  bool applyFilters(FILTER_FUNC filterFunc, ARGS... args)
422  {
423  bool result = true;
424  for (IBasicWalkFilter<ALLOC>& walkFilter : m_walkFilters)
425  result &= (walkFilter.*filterFunc)(args...);
426  return result;
427  }
428 
429  WalkFilters m_walkFilters;
430 };
431 
443 template <typename ALLOC>
445  m_walkObserver(walkObserver),
446  m_walkFilter(m_defaultWalkFilter)
447 {}
448 
449 template <typename ALLOC>
451  m_walkObserver(walkObserver),
452  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 '")
465  << typeInfo.getSchemaName() << "' 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 IBasicReflectableConstPtr<ALLOC>& compound, 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(
484  fields.begin(), fields.end(), [compoundChoice](const BasicFieldInfo<ALLOC>& fieldInfo) {
485  return fieldInfo.schemaName == compoundChoice;
486  });
487  if (fieldsIt != fields.end())
488  {
489  walkField(compound->getField(compoundChoice), *fieldsIt);
490  }
491  }
492  // else uninitialized or empty branch
493  }
494  else
495  {
496  for (const BasicFieldInfo<ALLOC>& fieldInfo : typeInfo.getFields())
497  {
498  if (!walkField(compound->getField(fieldInfo.schemaName), fieldInfo))
499  break;
500  }
501  }
502 }
503 
504 template <typename ALLOC>
505 bool BasicWalker<ALLOC>::walkField(
506  const IBasicReflectableConstPtr<ALLOC>& reflectable, const BasicFieldInfo<ALLOC>& fieldInfo)
507 {
508  if (reflectable && fieldInfo.isArray)
509  {
510  if (m_walkFilter.beforeArray(reflectable, fieldInfo))
511  {
512  m_walkObserver.beginArray(reflectable, fieldInfo);
513  for (size_t i = 0; i < reflectable->size(); ++i)
514  {
515  if (!walkFieldValue(reflectable->at(i), fieldInfo, i))
516  break;
517  }
518  m_walkObserver.endArray(reflectable, fieldInfo);
519  }
520  return m_walkFilter.afterArray(reflectable, fieldInfo);
521  }
522  else
523  {
524  return walkFieldValue(reflectable, fieldInfo);
525  }
526 }
527 
528 template <typename ALLOC>
529 bool BasicWalker<ALLOC>::walkFieldValue(const IBasicReflectableConstPtr<ALLOC>& reflectable,
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),
554  m_depth(1)
555 {}
556 
557 template <typename ALLOC>
560 {
561  return enterDepthLevel();
562 }
563 
564 template <typename ALLOC>
567 {
568  return leaveDepthLevel();
569 }
570 
571 template <typename ALLOC>
574 {
575  return enterDepthLevel();
576 }
577 
578 template <typename ALLOC>
581 {
582  return leaveDepthLevel();
583 }
584 
585 template <typename ALLOC>
588 {
589  return m_depth <= m_maxDepth;
590 }
591 
592 template <typename ALLOC>
595 {
596  return true;
597 }
598 
599 template <typename ALLOC>
601 {
602  const bool enter = (m_depth <= m_maxDepth);
603  m_depth += 1;
604  return enter;
605 }
606 
607 template <typename ALLOC>
608 bool BasicDepthWalkFilter<ALLOC>::leaveDepthLevel()
609 {
610  m_depth -= 1;
611  return true;
612 }
613 
614 namespace detail
615 {
616 
617 template <typename ALLOC>
618 string<ALLOC> getCurrentPathImpl(const vector<string<ALLOC>, ALLOC>& currentPath, const ALLOC& allocator)
619 {
620  string<ALLOC> currentPathStr(allocator);
621  for (auto it = currentPath.begin(); it != currentPath.end(); ++it)
622  {
623  if (!currentPathStr.empty())
624  currentPathStr += ".";
625  currentPathStr += *it;
626  }
627  return currentPathStr;
628 }
629 
630 template <typename ALLOC>
631 void appendPathImpl(vector<string<ALLOC>, ALLOC>& currentPath, const BasicFieldInfo<ALLOC>& fieldInfo,
632  size_t elementIndex, const ALLOC& allocator)
633 {
634  if (elementIndex == WALKER_NOT_ELEMENT)
635  {
636  currentPath.emplace_back(fieldInfo.schemaName.data(), fieldInfo.schemaName.size(), allocator);
637  }
638  else
639  {
640  currentPath.back() =
641  toString(fieldInfo.schemaName, allocator) + "[" + toString(elementIndex, allocator) + "]";
642  }
643 }
644 
645 template <typename ALLOC>
646 void popPathImpl(vector<string<ALLOC>, ALLOC>& currentPath, const BasicFieldInfo<ALLOC>& fieldInfo,
647  size_t elementIndex, const ALLOC& allocator)
648 {
649  if (elementIndex == WALKER_NOT_ELEMENT)
650  currentPath.pop_back();
651  else
652  currentPath.back() = toString(fieldInfo.schemaName, allocator);
653 }
654 
655 template <typename ALLOC>
656 class SubtreeRegexWalkFilter : public IBasicWalkFilter<ALLOC>
657 {
658 public:
659  SubtreeRegexWalkFilter(const vector<string<ALLOC>, ALLOC>& currentPath, const std::regex& pathRegex,
660  const ALLOC& allocator) :
661  m_currentPath(currentPath),
662  m_pathRegex(pathRegex),
663  m_allocator(allocator)
664  {}
665 
666  bool matches()
667  {
668  return m_matches;
669  }
670 
671  bool beforeArray(const IBasicReflectableConstPtr<ALLOC>&, 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 
680  bool afterArray(const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>&) override
681  {
682  m_currentPath.pop_back();
683  return !m_matches; // terminate when the match is already found
684  }
685 
686  bool beforeCompound(const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>& fieldInfo,
687  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 
696  bool afterCompound(const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>& fieldInfo,
697  size_t elementIndex) override
698  {
699  popPath(fieldInfo, elementIndex);
700  return !m_matches; // terminate when the match is already found
701  }
702 
703  bool beforeValue(const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>& fieldInfo,
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 
712  bool afterValue(const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>& fieldInfo,
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),
746  m_allocator(allocator)
747 {}
748 
749 template <typename ALLOC>
751  const IBasicReflectableConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo)
752 {
753  m_currentPath.emplace_back(fieldInfo.schemaName.data(), fieldInfo.schemaName.size(), m_allocator);
754 
755  if (std::regex_match(getCurrentPath(), m_pathRegex))
756  return true; // the array itself matches
757 
758  for (size_t i = 0; i < array->size(); ++i)
759  {
760  m_currentPath.back() =
761  toString(fieldInfo.schemaName, m_allocator) + "[" + toString(i, m_allocator) + "]";
762 
763  if (matchSubtree(array->at(i), fieldInfo))
764  return true;
765  }
766 
767  m_currentPath.back() = toString(fieldInfo.schemaName, m_allocator);
768 
769  return false;
770 }
771 
772 template <typename ALLOC>
775 {
776  m_currentPath.pop_back();
777  return true;
778 }
779 
780 template <typename ALLOC>
782  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
783 {
784  appendPath(fieldInfo, elementIndex);
785  if (std::regex_match(getCurrentPath(), m_pathRegex))
786  return true; // the compound itself matches
787 
788  return matchSubtree(compound, fieldInfo);
789 }
790 
791 template <typename ALLOC>
793  const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
794 {
795  popPath(fieldInfo, elementIndex);
796  return true;
797 }
798 
799 template <typename ALLOC>
801  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
802 {
803  appendPath(fieldInfo, elementIndex);
804  return matchSubtree(value, fieldInfo);
805 }
806 
807 template <typename ALLOC>
809  const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
810 {
811  popPath(fieldInfo, elementIndex);
812  return true;
813 }
814 
815 template <typename ALLOC>
816 void BasicRegexWalkFilter<ALLOC>::appendPath(const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
817 {
818  detail::appendPathImpl(m_currentPath, fieldInfo, elementIndex, m_allocator);
819 }
820 
821 template <typename ALLOC>
822 void BasicRegexWalkFilter<ALLOC>::popPath(const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
823 {
824  detail::popPathImpl(m_currentPath, fieldInfo, elementIndex, m_allocator);
825 }
826 
827 template <typename ALLOC>
828 string<ALLOC> BasicRegexWalkFilter<ALLOC>::getCurrentPath() const
829 {
830  return detail::getCurrentPathImpl(m_currentPath, m_allocator);
831 }
832 
833 template <typename ALLOC>
834 bool BasicRegexWalkFilter<ALLOC>::matchSubtree(
835  const IBasicReflectableConstPtr<ALLOC>& value, const BasicFieldInfo<ALLOC>& fieldInfo) const
836 {
837  if (value != nullptr && TypeInfoUtil::isCompound(fieldInfo.typeInfo.getSchemaType()))
838  {
839  // is a not null compound, try to find match within its subtree
840  BasicDefaultWalkObserver<ALLOC> defaultObserver;
841  detail::SubtreeRegexWalkFilter<ALLOC> subtreeFilter(m_currentPath, m_pathRegex, m_allocator);
842  BasicWalker<ALLOC> walker(defaultObserver, subtreeFilter);
843  walker.walk(value);
844  return subtreeFilter.matches();
845  }
846  else
847  {
848  // try to match a simple value or null compound
849  return std::regex_match(getCurrentPath(), m_pathRegex);
850  }
851 }
852 
853 template <typename ALLOC>
855  m_maxArrayLength(maxArrayLength)
856 {}
857 
858 template <typename ALLOC>
861 {
862  return true;
863 }
864 
865 template <typename ALLOC>
868 {
869  return true;
870 }
871 
872 template <typename ALLOC>
874  const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>&, size_t elementIndex)
875 {
876  return filterArrayElement(elementIndex);
877 }
878 
879 template <typename ALLOC>
881  const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>&, size_t elementIndex)
882 {
883  return filterArrayElement(elementIndex);
884 }
885 
886 template <typename ALLOC>
888  const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>&, size_t elementIndex)
889 {
890  return filterArrayElement(elementIndex);
891 }
892 
893 template <typename ALLOC>
895  const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>&, size_t elementIndex)
896 {
897  return filterArrayElement(elementIndex);
898 }
899 
900 template <typename ALLOC>
902 {
903  return elementIndex == WALKER_NOT_ELEMENT ? true : elementIndex < m_maxArrayLength;
904 }
905 
906 template <typename ALLOC>
908  m_walkFilters(walkFilters)
909 {}
910 
911 template <typename ALLOC>
913  const IBasicReflectableConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo)
914 {
915  return applyFilters(&IBasicWalkFilter<ALLOC>::beforeArray, array, fieldInfo);
916 }
917 
918 template <typename ALLOC>
920  const IBasicReflectableConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo)
921 {
922  return applyFilters(&IBasicWalkFilter<ALLOC>::afterArray, array, fieldInfo);
923 }
924 
925 template <typename ALLOC>
927  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
928 {
929  return applyFilters(&IBasicWalkFilter<ALLOC>::beforeCompound, compound, fieldInfo, elementIndex);
930 }
931 
932 template <typename ALLOC>
934  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
935 {
936  return applyFilters(&IBasicWalkFilter<ALLOC>::afterCompound, compound, fieldInfo, elementIndex);
937 }
938 
939 template <typename ALLOC>
941  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
942 {
943  return applyFilters(&IBasicWalkFilter<ALLOC>::beforeValue, value, fieldInfo, elementIndex);
944 }
945 
946 template <typename ALLOC>
948  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
949 {
950  return applyFilters(&IBasicWalkFilter<ALLOC>::afterValue, value, fieldInfo, elementIndex);
951 }
952 
953 } // namespace zserio
954 
955 #endif // ZSERIO_WALKER_H_INC
BasicAndWalkFilter(const WalkFilters &walkFilters)
Definition: Walker.h:907
std::reference_wrapper< IBasicWalkFilter< ALLOC > > WalkFilterRef
Definition: Walker.h:376
bool beforeValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:940
bool beforeArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:912
bool afterArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:919
bool afterCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:933
bool afterValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:947
BasicAndWalkFilter(const BasicAndWalkFilter &other)=delete
~BasicAndWalkFilter() override=default
bool beforeCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:926
BasicAndWalkFilter & operator=(const BasicAndWalkFilter &other)=delete
vector< WalkFilterRef, ALLOC > WalkFilters
Definition: Walker.h:377
BasicAndWalkFilter & operator=(BasicAndWalkFilter &&other)=delete
BasicAndWalkFilter(BasicAndWalkFilter &&other)=delete
bool afterArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:866
BasicArrayLengthWalkFilter(BasicArrayLengthWalkFilter &&other)=delete
bool beforeArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:859
bool afterCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:880
BasicArrayLengthWalkFilter(const BasicArrayLengthWalkFilter &other)=delete
bool beforeCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:873
bool beforeValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:887
~BasicArrayLengthWalkFilter() override=default
BasicArrayLengthWalkFilter & operator=(BasicArrayLengthWalkFilter &&other)=delete
BasicArrayLengthWalkFilter(size_t maxArrayLength)
Definition: Walker.h:854
bool afterValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:894
BasicArrayLengthWalkFilter & operator=(const BasicArrayLengthWalkFilter &other)=delete
BasicDefaultWalkFilter(BasicDefaultWalkFilter &&other)=delete
BasicDefaultWalkFilter & operator=(const BasicDefaultWalkFilter &other)=delete
bool beforeValue(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &, size_t) override
Definition: Walker.h:182
bool beforeCompound(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &, size_t) override
Definition: Walker.h:172
bool afterValue(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &, size_t) override
Definition: Walker.h:187
bool afterCompound(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &, size_t) override
Definition: Walker.h:177
BasicDefaultWalkFilter & operator=(BasicDefaultWalkFilter &&other)=delete
BasicDefaultWalkFilter(const BasicDefaultWalkFilter &other)=delete
~BasicDefaultWalkFilter() override=default
bool afterArray(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &) override
Definition: Walker.h:167
bool beforeArray(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &) override
Definition: Walker.h:162
void beginArray(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &) override
Definition: Walker.h:118
~BasicDefaultWalkObserver() override=default
BasicDefaultWalkObserver & operator=(BasicDefaultWalkObserver &&other)=delete
BasicDefaultWalkObserver(BasicDefaultWalkObserver &&other)=delete
void beginCompound(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &, size_t) override
Definition: Walker.h:123
void endCompound(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &, size_t) override
Definition: Walker.h:125
void endArray(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &) override
Definition: Walker.h:120
void endRoot(const IBasicReflectableConstPtr< ALLOC > &) override
Definition: Walker.h:115
void visitValue(const IBasicReflectableConstPtr< ALLOC > &, const BasicFieldInfo< ALLOC > &, size_t) override
Definition: Walker.h:128
BasicDefaultWalkObserver(const BasicDefaultWalkObserver &other)=delete
BasicDefaultWalkObserver & operator=(const BasicDefaultWalkObserver &other)=delete
void beginRoot(const IBasicReflectableConstPtr< ALLOC > &) override
Definition: Walker.h:113
BasicDepthWalkFilter(size_t maxDepth)
Definition: Walker.h:552
BasicDepthWalkFilter & operator=(const BasicDepthWalkFilter &other)=delete
bool afterArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:565
~BasicDepthWalkFilter() override=default
bool afterValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:593
BasicDepthWalkFilter & operator=(BasicDepthWalkFilter &&other)=delete
bool beforeValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:586
bool afterCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:579
BasicDepthWalkFilter(BasicDepthWalkFilter &&other)=delete
bool beforeArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:558
BasicDepthWalkFilter(const BasicDepthWalkFilter &other)=delete
bool beforeCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:572
bool afterValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:808
BasicRegexWalkFilter & operator=(BasicRegexWalkFilter &&other)=delete
BasicRegexWalkFilter & operator=(const BasicRegexWalkFilter &other)=delete
bool beforeCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:781
~BasicRegexWalkFilter() override=default
BasicRegexWalkFilter(const char *pathRegex, const ALLOC &allocator=ALLOC())
Definition: Walker.h:744
BasicRegexWalkFilter(const BasicRegexWalkFilter &other)=delete
bool beforeArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:750
BasicRegexWalkFilter(BasicRegexWalkFilter &&other)=delete
bool afterCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:792
bool beforeValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:800
bool afterArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:773
constexpr size_type size() const noexcept
Definition: StringView.h:240
constexpr bool empty() const noexcept
Definition: StringView.h:270
constexpr const_pointer data() const noexcept
Definition: StringView.h:230
BasicWalker(IBasicWalkObserver< ALLOC > &walkObserver)
Definition: Walker.h:444
BasicWalker & operator=(BasicWalker &&other)=delete
BasicWalker & operator=(const BasicWalker &other)=delete
void walk(const IBasicReflectableConstPtr< ALLOC > &compound)
Definition: Walker.h:456
~BasicWalker()=default
BasicWalker(const BasicWalker &other)=delete
BasicWalker(BasicWalker &&other)=delete
virtual StringView getSchemaName() const =0
virtual Span< const BasicFieldInfo< ALLOC > > getFields() const =0
virtual SchemaType getSchemaType() const =0
virtual bool beforeCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex)=0
virtual bool beforeArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo)=0
virtual bool beforeValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex)=0
virtual bool afterValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex)=0
virtual bool afterCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex)=0
virtual bool afterArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo)=0
constexpr iterator end() const noexcept
Definition: Span.h:210
constexpr iterator begin() const noexcept
Definition: Span.h:200
std::basic_string< char, std::char_traits< char >, RebindAlloc< ALLOC, char > > string
Definition: String.h:17
std::vector< T, RebindAlloc< ALLOC, T > > vector
Definition: Vector.h:17
string< ALLOC > toString(T value, const ALLOC &allocator=ALLOC())
typename IBasicReflectable< ALLOC >::ConstPtr IBasicReflectableConstPtr
Definition: IReflectable.h:519
StringView schemaName
Definition: ITypeInfo.h:379
static bool hasChoice(SchemaType schemaType)
static bool isCompound(SchemaType schemaType)
Definition: TypeInfoUtil.cpp:6