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.hxx
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log

Revision 3981 - (download) (as text) (annotate)
Thu Jun 16 13:45:03 2016 UTC (2 years, 11 months ago) by jhr
File size: 1931 byte(s)
working on merge: runtime library
/*! \file dynseq.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.


#include <memory>
#include <vector>
#include <initializer_list>
#include <teem/nrrd.h>

namespace diderot {

    template <typename T>
    class dynseq {

      //! construct an empty sequence
	dynseq ();
      //! construct a sequence from a fixed-size array
	dynseq (uint32_t n, const T *data);
      //! construct a sequence from an array initializer (e.g., `dynseq{1, 2, 3}`)
	dynseq (std::initializer_list<T> il);
      //! construct a sequence from a nrrd
	dynseq (const Nrrd *nin);
      //! copy constructor
	dynseq (const dynseq &seq);

	~dynseq ();

	const &T operator[] (uint32_t i) const { return *(this->_seq)[i]; }

	std::vector<T>::const_iterator cbegin() const noexcept
	    return this->_seq->cbegin();
	std::vector<T>::const_iterator cend() const noexcept
	    return this->_seq->cend();

	std::shared_ptr<std::vector<T>> _seq;

      // friends
	friend dynseq<T> dynseq_prepend (T const &x, dynseq<T> const &seq);
	friend dynseq<T> dynseq_append (dynseq<T> const &seq, T const &x);
	friend dynseq<T> dynseq_concat (dynseq<T> const &seq1, dynseq<T> const &seq2);


  /***** inline functions *****/

    template <typename T>
    dynseq<T>::dynseq ()
	: _seq(std::make_shared<std::vector<T>()>)
    { }

    template <typename T>
    dynseq<T>::dynseq (uint32_t n, const T *data)
	: _seq(std::make_shared<std::vector<T>(n)>())
	std::memcpy (this->_seq->data(), data, n * sizeof(T));

    template <typename T>
    dynseq<T>::dynseq (std::initializer_list<T> il)
	: _seq(std::make_shared<std::vector<T>(il)>())
    { }

} // namespace diderot


ViewVC Help
Powered by ViewVC 1.0.0