Layout.hh

Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one
00003  * or more contributor license agreements.  See the NOTICE file
00004  * distributed with this work for additional information
00005  * regarding copyright ownership.  The ASF licenses this file
00006  * to you under the Apache License, Version 2.0 (the
00007  * "License"); you may not use this file except in compliance
00008  * with the License.  You may obtain a copy of the License at
00009  *
00010  *     http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS,
00014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
00017  */
00018 
00019 #ifndef avro_Layout_hh__
00020 #define avro_Layout_hh__
00021 
00022 #include <boost/noncopyable.hpp>
00023 #include "Boost.hh"
00024 
00027 
00028 namespace avro {
00029     
00030 class Layout : private boost::noncopyable {
00031 
00032   protected:
00033 
00034     Layout(size_t offset = 0) :
00035         offset_(offset)
00036     {}
00037 
00038   public:
00039 
00040     size_t offset() const {
00041         return offset_;
00042     }
00043 
00044     virtual ~Layout() {}
00045 
00046   private:
00047 
00048     const size_t offset_;
00049 };
00050 
00051 class PrimitiveLayout : public Layout {
00052 
00053   public:
00054 
00055     PrimitiveLayout(size_t offset = 0) :
00056         Layout(offset)
00057     {}
00058 };
00059 
00060 class CompoundLayout : public Layout {
00061 
00062   public:
00063 
00064     CompoundLayout(size_t offset = 0) :
00065         Layout(offset)
00066     {}
00067 
00068     void add(Layout *layout) {
00069         layouts_.push_back(layout);
00070     }
00071 
00072     const Layout &at (size_t idx) const {
00073         return layouts_.at(idx);
00074     }
00075 
00076   private:
00077 
00078     boost::ptr_vector<Layout> layouts_;
00079 };
00080 
00081 } // namespace avro
00082 
00083 #endif