Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/vis15/src/lib/include/diderot/dynseq-inst.hxx
ViewVC logotype

View of /branches/vis15/src/lib/include/diderot/dynseq-inst.hxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3988 - (download) (as text) (annotate)
Fri Jun 17 17:26:51 2016 UTC (3 years, 9 months ago) by jhr
File size: 2200 byte(s)
working on merge
/*! \file dynseq-inst.hxx
 *
 * \author John Reppy
 */

/*
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2016 The University of Chicago
 * All rights reserved.
 */

#ifndef _DIDEROT_DYNSEQ_INST_HXX_
#define _DIDEROT_DYNSEQ_INST_HXX_


#ifndef _DIDEROT_DYNSEQ_HXX_
# error dynseq-inst.hxx should not be directly included
#endif

#include "nrrd-inst.hxx"

namespace diderot {

    namespace __details {

      // traits for instances of the dynamic sequence template class
	template <typename T> struct seq_traits;
	// typedef elemtype;
	// static const uint32_t nDims;
        // static const uint32_t dims[nDims];

    } // namespace __details

  //! construct a sequence for a range lo..hi (integer types only)
    template <typename T>
    dynseq<T>::dynseq (T const &lo, T const &hi)
	: _seq(std::make_shared<std::vector<T>>(std::vector<T>()))
    {
	if (lo <= hi) {
	    this->_seq->reserve (hi - lo + 1);
	    for (T i = lo;  i <= hi;  ++i) {
		this->_seq->push_back(i);
	    }
	}
    }

  //! copy constructor with additional space reserved
    template <typename T>
    dynseq<T>::dynseq (const dynseq &seq, uint32_t n)
    {
    }

    template <typename T>
    dynseq<T> &dynseq<T>::prepend (T const &x)
    {
	this->_seq->insert (this->_seq->begin(), x);
	return *this;
    }

    template <typename T>
    dynseq<T> &dynseq<T>::append (T const &x)
    {
	this->_seq->push_back(x);
	return *this;
    }

    template <typename T>
    dynseq<T> &dynseq<T>::concat (dynseq<T> const &seq)
    {
	this->_seq->reserve (this->length() + seq.length());
	for (auto it = seq.cbegin(); it != seq.cend(); ++it) {
	    this->_seq->push_back (*it);
	}
	return *this;
    }

    template <typename T>
    dynseq<T> load_dynseq_from_file (world_base *wrld, std::string const &file, bool &sts)
    {
	Nrrd *nin = wrld->load_nrrd_file (file);
	if (nin == nullptr) {  // there was an error, so we return the empty sequence
	    sts = true;
	    return dynseq<T>();
	}
	else {
	    dynseq<T> result = load_dynseq_from_nrrd<T> (nin, sts);
	    nrrdNuke(nin);
	    return result;
	}
    }

} // namespace diderot

#endif // !_DIDEROT_DYNSEQ_INST_HXX_

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0