"Fossies" - the Fresh Open Source Software Archive

Member "fimex-1.4.1/src/IndexedData.cc" (30 Oct 2019, 2421 Bytes) of package /linux/privat/fimex-1.4.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "IndexedData.cc" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Fimex, IndexedData.cc
    3  *
    4  * (C) Copyright 2012, met.no
    5  *
    6  * Project Info:  https://wiki.met.no/fimex/start
    7  *
    8  * This library is free software; you can redistribute it and/or modify it
    9  * under the terms of the GNU Lesser General Public License as published by
   10  * the Free Software Foundation; either version 2.1 of the License, or
   11  * (at your option) any later version.
   12  *
   13  * This library is distributed in the hope that it will be useful, but
   14  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   15  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
   16  * License for more details.
   17  *
   18  * You should have received a copy of the GNU Lesser General Public
   19  * License along with this library; if not, write to the Free Software
   20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
   21  * USA.
   22  *
   23  *  Created on: Jul 18, 2012
   24  *      Author: Heiko Klein
   25  */
   26 
   27 #include "fimex/IndexedData.h"
   28 
   29 #include "fimex/CDMDataType.h"
   30 #include "fimex/Data.h"
   31 #include "fimex/DataIndex.h"
   32 #include "fimex/Type2String.h"
   33 
   34 #include <numeric>
   35 #include <functional>
   36 
   37 namespace MetNoFimex
   38 {
   39 
   40 class IndexedData::Impl
   41 {
   42 public:
   43     DataPtr data;
   44     DataIndex idx;
   45 };
   46 
   47 IndexedData::IndexedData()
   48 {
   49     init(createData(CDM_NAT,0,0.), std::vector<size_t>(0));
   50 }
   51 
   52 IndexedData::IndexedData(DataPtr data, const std::vector<std::size_t>& dims)
   53 {
   54     init(data, dims);
   55 }
   56 
   57 IndexedData::~IndexedData()
   58 {}
   59 
   60 void IndexedData::init(DataPtr data, const std::vector<std::size_t>& dims)
   61 {
   62     p_.reset(new Impl());
   63     p_->data = data;
   64     setDims(dims);
   65 }
   66 
   67 void IndexedData::setDims(std::vector<std::size_t> dims)
   68 {
   69     std::size_t size = std::accumulate(&dims[0], &dims[dims.size()], 1, std::multiplies<size_t>());
   70     if (size == p_->data->size()) {
   71         p_->idx = DataIndex(dims);
   72     } else if (p_->data->size() == 0) {
   73         p_->idx = DataIndex(std::vector<size_t>(0));
   74     } else {
   75         throw std::runtime_error("setDims error: dims.size != data.size: " + type2string(size) + " != " + type2string(p_->data->size()));
   76     }
   77 }
   78 
   79 DataPtr IndexedData::getDataPtr() const
   80 {
   81     return p_->data;
   82 }
   83 
   84 const DataIndex& IndexedData::idx() const
   85 {
   86     return p_->idx;
   87 }
   88 
   89 double IndexedData::getDouble(size_t pos) const
   90 {
   91     return p_->data->getDouble(pos);
   92 }
   93 
   94 long long IndexedData::getLongLong(size_t pos) const
   95 {
   96     return p_->data->getLongLong(pos);
   97 }
   98 
   99 } /* namespace MetNoFimex */