Layout.hh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * https://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef avro_Layout_hh__
  19. #define avro_Layout_hh__
  20. #include "Config.hh"
  21. #include <boost/noncopyable.hpp>
  22. /// \file Layout.hh
  23. ///
  24. namespace avro {
  25. class AVRO_DECL Layout : private boost::noncopyable {
  26. protected:
  27. explicit Layout(size_t offset = 0) : offset_(offset) {}
  28. public:
  29. size_t offset() const {
  30. return offset_;
  31. }
  32. virtual ~Layout() = default;
  33. private:
  34. const size_t offset_;
  35. };
  36. class AVRO_DECL PrimitiveLayout : public Layout {
  37. public:
  38. explicit PrimitiveLayout(size_t offset = 0) : Layout(offset) {}
  39. };
  40. class AVRO_DECL CompoundLayout : public Layout {
  41. public:
  42. explicit CompoundLayout(size_t offset = 0) : Layout(offset) {}
  43. void add(std::unique_ptr<Layout> &layout) {
  44. layouts_.push_back(std::move(layout));
  45. }
  46. const Layout &at(size_t idx) const {
  47. return *layouts_.at(idx);
  48. }
  49. private:
  50. std::vector<std::unique_ptr<Layout>> layouts_;
  51. };
  52. } // namespace avro
  53. #endif