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