Zserio C++ runtime library  1.1.0
Built for Zserio 2.15.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  {
426  result &= (walkFilter.*filterFunc)(args...);
427  }
428  return result;
429  }
430 
431  WalkFilters m_walkFilters;
432 };
433 
445 template <typename ALLOC>
447  m_walkObserver(walkObserver),
448  m_walkFilter(m_defaultWalkFilter)
449 {}
450 
451 template <typename ALLOC>
453  m_walkObserver(walkObserver),
454  m_walkFilter(walkFilter)
455 {}
456 
457 template <typename ALLOC>
459 {
460  if (!compound)
461  {
462  throw CppRuntimeException("Walker: Root object cannot be NULL!");
463  }
464 
465  const IBasicTypeInfo<ALLOC>& typeInfo = compound->getTypeInfo();
466  if (!TypeInfoUtil::isCompound(typeInfo.getSchemaType()))
467  {
468  throw CppRuntimeException("Walker: Root object '")
469  << typeInfo.getSchemaName() << "' is not a compound type!";
470  }
471 
472  m_walkObserver.beginRoot(compound);
473  walkFields(compound, typeInfo);
474  m_walkObserver.endRoot(compound);
475 }
476 
477 template <typename ALLOC>
479  const IBasicReflectableConstPtr<ALLOC>& compound, const IBasicTypeInfo<ALLOC>& typeInfo)
480 {
481  if (TypeInfoUtil::hasChoice(typeInfo.getSchemaType()))
482  {
483  StringView compoundChoice = compound->getChoice();
484  if (!compoundChoice.empty())
485  {
486  Span<const BasicFieldInfo<ALLOC>> fields = typeInfo.getFields();
487  auto fieldsIt = std::find_if(
488  fields.begin(), fields.end(), [compoundChoice](const BasicFieldInfo<ALLOC>& fieldInfo) {
489  return fieldInfo.schemaName == compoundChoice;
490  });
491  if (fieldsIt != fields.end())
492  {
493  walkField(compound->getField(compoundChoice), *fieldsIt);
494  }
495  }
496  // else uninitialized or empty branch
497  }
498  else
499  {
500  for (const BasicFieldInfo<ALLOC>& fieldInfo : typeInfo.getFields())
501  {
502  if (!walkField(compound->getField(fieldInfo.schemaName), fieldInfo))
503  {
504  break;
505  }
506  }
507  }
508 }
509 
510 template <typename ALLOC>
511 bool BasicWalker<ALLOC>::walkField(
512  const IBasicReflectableConstPtr<ALLOC>& reflectable, const BasicFieldInfo<ALLOC>& fieldInfo)
513 {
514  if (reflectable && fieldInfo.isArray)
515  {
516  if (m_walkFilter.beforeArray(reflectable, fieldInfo))
517  {
518  m_walkObserver.beginArray(reflectable, fieldInfo);
519  for (size_t i = 0; i < reflectable->size(); ++i)
520  {
521  if (!walkFieldValue(reflectable->at(i), fieldInfo, i))
522  {
523  break;
524  }
525  }
526  m_walkObserver.endArray(reflectable, fieldInfo);
527  }
528  return m_walkFilter.afterArray(reflectable, fieldInfo);
529  }
530  else
531  {
532  return walkFieldValue(reflectable, fieldInfo);
533  }
534 }
535 
536 template <typename ALLOC>
537 bool BasicWalker<ALLOC>::walkFieldValue(const IBasicReflectableConstPtr<ALLOC>& reflectable,
538  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
539 {
540  const IBasicTypeInfo<ALLOC>& typeInfo = fieldInfo.typeInfo;
541  if (reflectable && TypeInfoUtil::isCompound(typeInfo.getSchemaType()))
542  {
543  if (m_walkFilter.beforeCompound(reflectable, fieldInfo, elementIndex))
544  {
545  m_walkObserver.beginCompound(reflectable, fieldInfo, elementIndex);
546  walkFields(reflectable, typeInfo);
547  m_walkObserver.endCompound(reflectable, fieldInfo, elementIndex);
548  }
549  return m_walkFilter.afterCompound(reflectable, fieldInfo, elementIndex);
550  }
551  else
552  {
553  if (m_walkFilter.beforeValue(reflectable, fieldInfo, elementIndex))
554  {
555  m_walkObserver.visitValue(reflectable, fieldInfo, elementIndex);
556  }
557  return m_walkFilter.afterValue(reflectable, fieldInfo, elementIndex);
558  }
559 }
560 
561 template <typename ALLOC>
563  m_maxDepth(maxDepth),
564  m_depth(1)
565 {}
566 
567 template <typename ALLOC>
570 {
571  return enterDepthLevel();
572 }
573 
574 template <typename ALLOC>
577 {
578  return leaveDepthLevel();
579 }
580 
581 template <typename ALLOC>
584 {
585  return enterDepthLevel();
586 }
587 
588 template <typename ALLOC>
591 {
592  return leaveDepthLevel();
593 }
594 
595 template <typename ALLOC>
598 {
599  return m_depth <= m_maxDepth;
600 }
601 
602 template <typename ALLOC>
605 {
606  return true;
607 }
608 
609 template <typename ALLOC>
611 {
612  const bool enter = (m_depth <= m_maxDepth);
613  m_depth += 1;
614  return enter;
615 }
616 
617 template <typename ALLOC>
618 bool BasicDepthWalkFilter<ALLOC>::leaveDepthLevel()
619 {
620  m_depth -= 1;
621  return true;
622 }
623 
624 namespace detail
625 {
626 
627 template <typename ALLOC>
628 string<ALLOC> getCurrentPathImpl(const vector<string<ALLOC>, ALLOC>& currentPath, const ALLOC& allocator)
629 {
630  string<ALLOC> currentPathStr(allocator);
631  for (auto it = currentPath.begin(); it != currentPath.end(); ++it)
632  {
633  if (!currentPathStr.empty())
634  {
635  currentPathStr += ".";
636  }
637  currentPathStr += *it;
638  }
639  return currentPathStr;
640 }
641 
642 template <typename ALLOC>
643 void appendPathImpl(vector<string<ALLOC>, ALLOC>& currentPath, const BasicFieldInfo<ALLOC>& fieldInfo,
644  size_t elementIndex, const ALLOC& allocator)
645 {
646  if (elementIndex == WALKER_NOT_ELEMENT)
647  {
648  currentPath.emplace_back(fieldInfo.schemaName.data(), fieldInfo.schemaName.size(), allocator);
649  }
650  else
651  {
652  currentPath.back() =
653  toString(fieldInfo.schemaName, allocator) + "[" + toString(elementIndex, allocator) + "]";
654  }
655 }
656 
657 template <typename ALLOC>
658 void popPathImpl(vector<string<ALLOC>, ALLOC>& currentPath, const BasicFieldInfo<ALLOC>& fieldInfo,
659  size_t elementIndex, const ALLOC& allocator)
660 {
661  if (elementIndex == WALKER_NOT_ELEMENT)
662  {
663  currentPath.pop_back();
664  }
665  else
666  {
667  currentPath.back() = toString(fieldInfo.schemaName, allocator);
668  }
669 }
670 
671 template <typename ALLOC>
672 class SubtreeRegexWalkFilter : public IBasicWalkFilter<ALLOC>
673 {
674 public:
675  SubtreeRegexWalkFilter(const vector<string<ALLOC>, ALLOC>& currentPath, const std::regex& pathRegex,
676  const ALLOC& allocator) :
677  m_currentPath(currentPath),
678  m_pathRegex(pathRegex),
679  m_allocator(allocator)
680  {}
681 
682  bool matches()
683  {
684  return m_matches;
685  }
686 
687  bool beforeArray(const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>& fieldInfo) override
688  {
689  m_currentPath.emplace_back(fieldInfo.schemaName.data(), fieldInfo.schemaName.size());
690  m_matches = std::regex_match(getCurrentPath(), m_pathRegex);
691 
692  // terminate when the match is already found (note that array is never null here)
693  return !m_matches;
694  }
695 
696  bool afterArray(const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>&) override
697  {
698  m_currentPath.pop_back();
699  return !m_matches; // terminate when the match is already found
700  }
701 
702  bool beforeCompound(const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>& fieldInfo,
703  size_t elementIndex) override
704  {
705  appendPath(fieldInfo, elementIndex);
706  m_matches = std::regex_match(getCurrentPath(), m_pathRegex);
707 
708  // terminate when the match is already found (note that compound is never null here)
709  return !m_matches;
710  }
711 
712  bool afterCompound(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  bool beforeValue(const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>& fieldInfo,
720  size_t elementIndex) override
721  {
722  appendPath(fieldInfo, elementIndex);
723  m_matches = std::regex_match(getCurrentPath(), m_pathRegex);
724 
725  return !m_matches; // terminate when the match is already found
726  }
727 
728  bool afterValue(const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>& fieldInfo,
729  size_t elementIndex) override
730  {
731  popPath(fieldInfo, elementIndex);
732  return !m_matches; // terminate when the match is already found
733  }
734 
735 private:
736  string<ALLOC> getCurrentPath() const
737  {
738  return detail::getCurrentPathImpl(m_currentPath, m_allocator);
739  }
740 
741  void appendPath(const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
742  {
743  detail::appendPathImpl(m_currentPath, fieldInfo, elementIndex, m_allocator);
744  }
745 
746  void popPath(const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
747  {
748  detail::popPathImpl(m_currentPath, fieldInfo, elementIndex, m_allocator);
749  }
750 
751  vector<string<ALLOC>, ALLOC> m_currentPath;
752  std::regex m_pathRegex;
753  ALLOC m_allocator;
754  bool m_matches = false;
755 };
756 
757 } // namespace detail
758 
759 template <typename ALLOC>
760 BasicRegexWalkFilter<ALLOC>::BasicRegexWalkFilter(const char* pathRegex, const ALLOC& allocator) :
761  m_pathRegex(pathRegex),
762  m_allocator(allocator)
763 {}
764 
765 template <typename ALLOC>
767  const IBasicReflectableConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo)
768 {
769  m_currentPath.emplace_back(fieldInfo.schemaName.data(), fieldInfo.schemaName.size(), m_allocator);
770 
771  if (std::regex_match(getCurrentPath(), m_pathRegex))
772  {
773  return true; // the array itself matches
774  }
775 
776  for (size_t i = 0; i < array->size(); ++i)
777  {
778  m_currentPath.back() =
779  toString(fieldInfo.schemaName, m_allocator) + "[" + toString(i, m_allocator) + "]";
780 
781  if (matchSubtree(array->at(i), fieldInfo))
782  {
783  return true;
784  }
785  }
786 
787  m_currentPath.back() = toString(fieldInfo.schemaName, m_allocator);
788 
789  return false;
790 }
791 
792 template <typename ALLOC>
795 {
796  m_currentPath.pop_back();
797  return true;
798 }
799 
800 template <typename ALLOC>
802  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
803 {
804  appendPath(fieldInfo, elementIndex);
805  if (std::regex_match(getCurrentPath(), m_pathRegex))
806  {
807  return true; // the compound itself matches
808  }
809 
810  return matchSubtree(compound, fieldInfo);
811 }
812 
813 template <typename ALLOC>
815  const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
816 {
817  popPath(fieldInfo, elementIndex);
818  return true;
819 }
820 
821 template <typename ALLOC>
823  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
824 {
825  appendPath(fieldInfo, elementIndex);
826  return matchSubtree(value, fieldInfo);
827 }
828 
829 template <typename ALLOC>
831  const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
832 {
833  popPath(fieldInfo, elementIndex);
834  return true;
835 }
836 
837 template <typename ALLOC>
838 void BasicRegexWalkFilter<ALLOC>::appendPath(const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
839 {
840  detail::appendPathImpl(m_currentPath, fieldInfo, elementIndex, m_allocator);
841 }
842 
843 template <typename ALLOC>
844 void BasicRegexWalkFilter<ALLOC>::popPath(const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
845 {
846  detail::popPathImpl(m_currentPath, fieldInfo, elementIndex, m_allocator);
847 }
848 
849 template <typename ALLOC>
850 string<ALLOC> BasicRegexWalkFilter<ALLOC>::getCurrentPath() const
851 {
852  return detail::getCurrentPathImpl(m_currentPath, m_allocator);
853 }
854 
855 template <typename ALLOC>
856 bool BasicRegexWalkFilter<ALLOC>::matchSubtree(
857  const IBasicReflectableConstPtr<ALLOC>& value, const BasicFieldInfo<ALLOC>& fieldInfo) const
858 {
859  if (value != nullptr && TypeInfoUtil::isCompound(fieldInfo.typeInfo.getSchemaType()))
860  {
861  // is a not null compound, try to find match within its subtree
862  BasicDefaultWalkObserver<ALLOC> defaultObserver;
863  detail::SubtreeRegexWalkFilter<ALLOC> subtreeFilter(m_currentPath, m_pathRegex, m_allocator);
864  BasicWalker<ALLOC> walker(defaultObserver, subtreeFilter);
865  walker.walk(value);
866  return subtreeFilter.matches();
867  }
868  else
869  {
870  // try to match a simple value or null compound
871  return std::regex_match(getCurrentPath(), m_pathRegex);
872  }
873 }
874 
875 template <typename ALLOC>
877  m_maxArrayLength(maxArrayLength)
878 {}
879 
880 template <typename ALLOC>
883 {
884  return true;
885 }
886 
887 template <typename ALLOC>
890 {
891  return true;
892 }
893 
894 template <typename ALLOC>
896  const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>&, size_t elementIndex)
897 {
898  return filterArrayElement(elementIndex);
899 }
900 
901 template <typename ALLOC>
903  const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>&, size_t elementIndex)
904 {
905  return filterArrayElement(elementIndex);
906 }
907 
908 template <typename ALLOC>
910  const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>&, size_t elementIndex)
911 {
912  return filterArrayElement(elementIndex);
913 }
914 
915 template <typename ALLOC>
917  const IBasicReflectableConstPtr<ALLOC>&, const BasicFieldInfo<ALLOC>&, size_t elementIndex)
918 {
919  return filterArrayElement(elementIndex);
920 }
921 
922 template <typename ALLOC>
924 {
925  return elementIndex == WALKER_NOT_ELEMENT ? true : elementIndex < m_maxArrayLength;
926 }
927 
928 template <typename ALLOC>
930  m_walkFilters(walkFilters)
931 {}
932 
933 template <typename ALLOC>
935  const IBasicReflectableConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo)
936 {
937  return applyFilters(&IBasicWalkFilter<ALLOC>::beforeArray, array, fieldInfo);
938 }
939 
940 template <typename ALLOC>
942  const IBasicReflectableConstPtr<ALLOC>& array, const BasicFieldInfo<ALLOC>& fieldInfo)
943 {
944  return applyFilters(&IBasicWalkFilter<ALLOC>::afterArray, array, fieldInfo);
945 }
946 
947 template <typename ALLOC>
949  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
950 {
951  return applyFilters(&IBasicWalkFilter<ALLOC>::beforeCompound, compound, fieldInfo, elementIndex);
952 }
953 
954 template <typename ALLOC>
956  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
957 {
958  return applyFilters(&IBasicWalkFilter<ALLOC>::afterCompound, compound, fieldInfo, elementIndex);
959 }
960 
961 template <typename ALLOC>
963  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
964 {
965  return applyFilters(&IBasicWalkFilter<ALLOC>::beforeValue, value, fieldInfo, elementIndex);
966 }
967 
968 template <typename ALLOC>
970  const BasicFieldInfo<ALLOC>& fieldInfo, size_t elementIndex)
971 {
972  return applyFilters(&IBasicWalkFilter<ALLOC>::afterValue, value, fieldInfo, elementIndex);
973 }
974 
975 } // namespace zserio
976 
977 #endif // ZSERIO_WALKER_H_INC
BasicAndWalkFilter(const WalkFilters &walkFilters)
Definition: Walker.h:929
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:962
bool beforeArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:934
bool afterArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:941
bool afterCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:955
bool afterValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:969
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:948
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:888
BasicArrayLengthWalkFilter(BasicArrayLengthWalkFilter &&other)=delete
bool beforeArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:881
bool afterCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:902
BasicArrayLengthWalkFilter(const BasicArrayLengthWalkFilter &other)=delete
bool beforeCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:895
bool beforeValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:909
~BasicArrayLengthWalkFilter() override=default
BasicArrayLengthWalkFilter & operator=(BasicArrayLengthWalkFilter &&other)=delete
BasicArrayLengthWalkFilter(size_t maxArrayLength)
Definition: Walker.h:876
bool afterValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:916
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:562
BasicDepthWalkFilter & operator=(const BasicDepthWalkFilter &other)=delete
bool afterArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:575
~BasicDepthWalkFilter() override=default
bool afterValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:603
BasicDepthWalkFilter & operator=(BasicDepthWalkFilter &&other)=delete
bool beforeValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:596
bool afterCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:589
BasicDepthWalkFilter(BasicDepthWalkFilter &&other)=delete
bool beforeArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:568
BasicDepthWalkFilter(const BasicDepthWalkFilter &other)=delete
bool beforeCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:582
bool afterValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:830
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:801
~BasicRegexWalkFilter() override=default
BasicRegexWalkFilter(const char *pathRegex, const ALLOC &allocator=ALLOC())
Definition: Walker.h:760
BasicRegexWalkFilter(const BasicRegexWalkFilter &other)=delete
bool beforeArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:766
BasicRegexWalkFilter(BasicRegexWalkFilter &&other)=delete
bool afterCompound(const IBasicReflectableConstPtr< ALLOC > &compound, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:814
bool beforeValue(const IBasicReflectableConstPtr< ALLOC > &value, const BasicFieldInfo< ALLOC > &fieldInfo, size_t elementIndex) override
Definition: Walker.h:822
bool afterArray(const IBasicReflectableConstPtr< ALLOC > &array, const BasicFieldInfo< ALLOC > &fieldInfo) override
Definition: Walker.h:793
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:446
BasicWalker & operator=(BasicWalker &&other)=delete
BasicWalker & operator=(const BasicWalker &other)=delete
void walk(const IBasicReflectableConstPtr< ALLOC > &compound)
Definition: Walker.h:458
~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:534
StringView schemaName
Definition: ITypeInfo.h:379
static bool hasChoice(SchemaType schemaType)
static bool isCompound(SchemaType schemaType)
Definition: TypeInfoUtil.cpp:6