= value_.begin() + index * columnCount();
return AnalysisDataFrameRef(
AnalysisDataFrameHeader(index, xvalue(index), 0.0),
- AnalysisDataValuesRef(begin, begin + columnCount()),
- AnalysisDataPointSetInfosRef(&pointSetInfo_, 1));
+ constArrayRefFromVector<AnalysisDataValue>(begin, begin + columnCount()),
+ constArrayRefFromArray(&pointSetInfo_, 1));
}
modules.notifyPointsAdd(
AnalysisDataPointSetRef(
header, pointSetInfo_,
- AnalysisDataValuesRef(valueIter,
- valueIter + columnCount())));
+ constArrayRefFromVector<AnalysisDataValue>(valueIter,
+ valueIter + columnCount())));
modules.notifyFrameFinish(header);
}
modules.notifyDataFinish();
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2012,2013, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
: header_(header),
dataSetIndex_(pointSetInfo.dataSetIndex()),
firstColumn_(pointSetInfo.firstColumn()),
- values_(&*values.begin() + pointSetInfo.valueOffset(),
- pointSetInfo.valueCount())
+ values_(constArrayRefFromArray(&*values.begin() + pointSetInfo.valueOffset(),
+ pointSetInfo.valueCount()))
{
GMX_ASSERT(header_.isValid(),
"Invalid point set reference should not be constructed");
const AnalysisDataFrameHeader &header,
const std::vector<AnalysisDataValue> &values)
: header_(header), dataSetIndex_(0), firstColumn_(0),
- values_(values.begin(), values.end())
+ values_(constArrayRefFromVector<AnalysisDataValue>(values.begin(), values.end()))
{
GMX_ASSERT(header_.isValid(),
"Invalid point set reference should not be constructed");
const AnalysisDataFrameHeader &header,
const std::vector<AnalysisDataValue> &values,
const std::vector<AnalysisDataPointSetInfo> &pointSets)
- : header_(header), values_(values.begin(), values.end()),
- pointSets_(pointSets.begin(), pointSets.end())
+ : header_(header), values_(constArrayRefFromVector<AnalysisDataValue>(values.begin(), values.end())),
+ pointSets_(constArrayRefFromVector<AnalysisDataPointSetInfo>(pointSets.begin(), pointSets.end()))
{
GMX_ASSERT(!pointSets_.empty(), "There must always be a point set");
}
AnalysisDataFrameRef::AnalysisDataFrameRef(
const AnalysisDataFrameRef &frame, int firstColumn, int columnCount)
: header_(frame.header()),
- values_(&frame.values_[firstColumn], columnCount),
+ values_(constArrayRefFromArray(&frame.values_[firstColumn], columnCount)),
pointSets_(frame.pointSets_)
{
// FIXME: This doesn't produce a valid internal state, although it does
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2012,2013, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
AnalysisDataPointSetInfo pointSetInfo(0, valueCount,
dataSetIndex, firstColumn);
AnalysisDataPointSetRef pointSet(header(), pointSetInfo,
- AnalysisDataValuesRef(begin, end));
+ constArrayRefFromVector<AnalysisDataValue>(begin, end));
storageImpl().modules_->notifyParallelPointsAdd(pointSet);
if (storageImpl().shouldNotifyImmediately())
{
"Invalid point set index");
return AnalysisDataPointSetRef(
header_, pointSets_[index],
- AnalysisDataValuesRef(values_.begin(), values_.end()));
+ constArrayRefFromVector<AnalysisDataValue>(values_.begin(), values_.end()));
}
} // namespace internal
if (context != NULL && !(FF(PCA_QUIET)))
{
gmx::Options options(NULL, NULL);
- options.setDescription(gmx::ConstArrayRef<const char *>(desc, ndesc));
+ options.setDescription(gmx::constArrayRefFromArray(desc, ndesc));
for (i = 0; i < nfile; i++)
{
gmx::filenmToOptions(&options, &fnm[i]);
gmx::CommandLineHelpWriter(options)
.setShowDescriptions(true)
.setTimeUnitString(output_env_get_time_unit(*oenv))
- .setKnownIssues(gmx::ConstArrayRef<const char *>(bugs, nbugs))
+ .setKnownIssues(gmx::constArrayRefFromArray(bugs, nbugs))
.writeHelp(*context);
}
}
const FileTypeRegistry ®istry = FileTypeRegistry::instance();
const FileTypeHandler &typeHandler = registry.handlerForType(filetype_, legacyType_);
const ExtensionList &extensions = typeHandler.extensions();
- return ConstArrayRef<const char *>(extensions.begin(), extensions.end());
+ return constArrayRefFromVector<const char *>(extensions.begin(), extensions.end());
}
/********************************************************************
{
if (positions.index_ < 0)
{
- testPositions_ = ConstArrayRef<rvec>(positions.x_, positions.count_);
+ testPositions_ = constArrayRefFromArray<rvec>(positions.x_, positions.count_);
reset(0);
}
else
{
// Somewhat of a hack: setup the array such that only the last position
// will be used.
- testPositions_ = ConstArrayRef<rvec>(positions.x_, positions.index_ + 1);
+ testPositions_ = constArrayRefFromArray<rvec>(positions.x_, positions.index_ + 1);
reset(positions.index_);
}
}
//! Returns atom indices of all atoms in the selection.
ConstArrayRef<int> atomIndices() const
{
- return ConstArrayRef<int>(sel_->rawPositions_.m.mapb.a,
- sel_->rawPositions_.m.mapb.nra);
+ return constArrayRefFromArray(sel_->rawPositions_.m.mapb.a,
+ sel_->rawPositions_.m.mapb.nra);
}
//! Number of positions in the selection.
int posCount() const { return data().posCount(); }
//! Returns coordinates for this selection as a continuous array.
ConstArrayRef<rvec> coordinates() const
{
- return ConstArrayRef<rvec>(data().rawPositions_.x, posCount());
+ return constArrayRefFromArray(data().rawPositions_.x, posCount());
}
//! Returns whether velocities are available for this selection.
bool hasVelocities() const { return data().rawPositions_.v != NULL; }
ConstArrayRef<rvec> velocities() const
{
GMX_ASSERT(hasVelocities(), "Velocities accessed, but unavailable");
- return ConstArrayRef<rvec>(data().rawPositions_.v, posCount());
+ return constArrayRefFromArray(data().rawPositions_.v, posCount());
}
//! Returns whether forces are available for this selection.
bool hasForces() const { return sel_->rawPositions_.f != NULL; }
ConstArrayRef<rvec> forces() const
{
GMX_ASSERT(hasForces(), "Forces accessed, but unavailable");
- return ConstArrayRef<rvec>(data().rawPositions_.f, posCount());
+ return constArrayRefFromArray(data().rawPositions_.f, posCount());
}
//! Returns masses for this selection as a continuous array.
ConstArrayRef<real> masses() const
// (and thus the masses and charges are fixed).
GMX_ASSERT(data().posMass_.size() >= static_cast<size_t>(posCount()),
"Internal inconsistency");
- return ConstArrayRef<real>(data().posMass_.begin(),
- data().posMass_.begin() + posCount());
+ return constArrayRefFromVector<real>(data().posMass_.begin(),
+ data().posMass_.begin() + posCount());
}
//! Returns charges for this selection as a continuous array.
ConstArrayRef<real> charges() const
// (and thus the masses and charges are fixed).
GMX_ASSERT(data().posCharge_.size() >= static_cast<size_t>(posCount()),
"Internal inconsistency");
- return ConstArrayRef<real>(data().posCharge_.begin(),
- data().posCharge_.begin() + posCount());
+ return constArrayRefFromVector<real>(data().posCharge_.begin(),
+ data().posCharge_.begin() + posCount());
}
/*! \brief
* Returns reference IDs for this selection as a continuous array.
*/
ConstArrayRef<int> refIds() const
{
- return ConstArrayRef<int>(data().rawPositions_.m.refid, posCount());
+ return constArrayRefFromArray(data().rawPositions_.m.refid, posCount());
}
/*! \brief
* Returns mapped IDs for this selection as a continuous array.
*/
ConstArrayRef<int> mappedIds() const
{
- return ConstArrayRef<int>(data().rawPositions_.m.mapid, posCount());
+ return constArrayRefFromArray(data().rawPositions_.m.mapid, posCount());
}
//! Returns whether the covered fraction can change between frames.
return ConstArrayRef<int>();
}
const int first = sel_->rawPositions_.m.mapb.index[i_];
- return ConstArrayRef<int>(&atoms[first], atomCount());
+ return constArrayRefFromArray(&atoms[first], atomCount());
}
/*! \brief
* Returns whether this position is selected in the current frame.
* \param[in] end Pointer to the end of a range.
*
* Passed pointers must remain valid for the lifetime of this object.
+ *
+ * \note For clarity, use the non-member function arrayRefFromPointers
+ * instead.
*/
ArrayRef(pointer begin, pointer end)
: begin_(begin), end_(end)
{
GMX_ASSERT(end >= begin, "Invalid range");
}
- /*! \brief
- * Constructs a reference to a particular range in a std::vector.
- *
- * \param[in] begin Iterator to the beginning of a range.
- * \param[in] end Iterator to the end of a range.
- *
- * The referenced vector must remain valid and not be reallocated for
- * the lifetime of this object.
- */
- ArrayRef(typename std::vector<value_type>::iterator begin,
- typename std::vector<value_type>::iterator end)
- : begin_((begin != end) ? &*begin : NULL),
- end_(begin_+(end-begin))
- {
- GMX_ASSERT(end >= begin, "Invalid range");
- }
- /*! \brief
- * Constructs a reference to an array.
- *
- * \param[in] begin Pointer to the beginning of the array.
- * May be NULL if \p size is zero.
- * \param[in] size Number of elements in the array.
- *
- * Passed pointer must remain valid for the lifetime of this object.
- */
- ArrayRef(pointer begin, size_type size)
- : begin_(begin), end_(begin + size)
- {
- }
//! \cond
// Doxygen 1.8.5 doesn't parse the declaration correctly...
/*! \brief
pointer end_;
};
+
+/*! \brief
+ * Constructs a reference to a particular range from two pointers.
+ *
+ * \param[in] begin Pointer to the beginning of a range.
+ * \param[in] end Pointer to the end of a range.
+ *
+ * Passed pointers must remain valid for the lifetime of this object.
+ *
+ * \related ArrayRef
+ */
+template <typename T>
+ArrayRef<T> arrayRefFromPointers(T * begin, T * end)
+{
+ return ArrayRef<T>(begin, end);
+}
+
+/*! \brief
+ * Constructs a reference to an array
+ *
+ * \param[in] begin Pointer to the beginning of the array.
+ * May be NULL if \p size is zero.
+ * \param[in] size Number of elements in the array.
+ *
+ * Passed pointer must remain valid for the lifetime of this object.
+ *
+ * \related ArrayRef
+ */
+template <typename T>
+ArrayRef<T> arrayRefFromArray(T * begin, size_t size)
+{
+ return arrayRefFromPointers<T>(begin, begin+size);
+}
+
+/*! \brief
+ * Constructs a reference to a particular range in a std::vector.
+ *
+ * \param[in] begin Iterator to the beginning of a range.
+ * \param[in] end Iterator to the end of a range.
+ *
+ * The referenced vector must remain valid and not be reallocated for
+ * the lifetime of this object.
+ *
+ * \related ArrayRef
+ */
+template <typename T>
+ArrayRef<T> arrayRefFromVector(typename std::vector<T>::iterator begin,
+ typename std::vector<T>::iterator end)
+{
+ T * p_begin = (begin != end) ? &*begin : NULL;
+ T * p_end = p_begin + (end-begin);
+ return arrayRefFromPointers<T>(p_begin, p_end);
+}
+
+
+
/*! \brief
* STL-like container for non-mutable interface to a C array (or part of a
* std::vector).
* \param[in] end Pointer to the end of a range.
*
* Passed pointers must remain valid for the lifetime of this object.
+ *
+ * \note For clarity, use the non-member function constArrayRefFromPointers
+ * instead.
*/
ConstArrayRef(const_pointer begin, const_pointer end)
: begin_(begin), end_(end)
{
GMX_ASSERT(end >= begin, "Invalid range");
}
- /*! \brief
- * Constructs a reference to a particular range in a std::vector.
- *
- * \param[in] begin Iterator to the beginning of a range.
- * \param[in] end Iterator to the end of a range.
- *
- * The referenced vector must remain valid and not be reallocated for
- * the lifetime of this object.
- */
- ConstArrayRef(typename std::vector<value_type>::const_iterator begin,
- typename std::vector<value_type>::const_iterator end)
- : begin_((begin != end) ? &*begin : NULL),
- end_(begin_+(end-begin))
- {
- GMX_ASSERT(end >= begin, "Invalid range");
- }
- /*! \brief
- * Constructs a reference to an array.
- *
- * \param[in] begin Pointer to the beginning of the array.
- * May be NULL if \p size is zero.
- * \param[in] size Number of elements in the array.
- *
- * Passed pointer must remain valid for the lifetime of this object.
- */
- ConstArrayRef(const_pointer begin, size_type size)
- : begin_(begin), end_(begin + size)
- {
- }
//! \cond
// Doxygen 1.8.5 doesn't parse the declaration correctly...
/*! \brief
const_pointer end_;
};
+
+/*! \brief
+ * Constructs a reference to a particular range from two pointers.
+ *
+ * \param[in] begin Pointer to the beginning of a range.
+ * \param[in] end Pointer to the end of a range.
+ *
+ * Passed pointers must remain valid for the lifetime of this object.
+ *
+ * \related ConstArrayRef
+ */
+template <typename T>
+ConstArrayRef<T> constArrayRefFromPointers(const T * begin, const T * end)
+{
+ return ConstArrayRef<T>(begin, end);
+}
+
+/*! \brief
+ * Constructs a reference to an array.
+ *
+ * \param[in] begin Pointer to the beginning of the array.
+ * May be NULL if \p size is zero.
+ * \param[in] size Number of elements in the array.
+ *
+ * Passed pointer must remain valid for the lifetime of this object.
+ *
+ * \related ConstArrayRef
+ */
+template <typename T>
+ConstArrayRef<T> constArrayRefFromArray(const T * begin, size_t size)
+{
+ return constArrayRefFromPointers<T>(begin, begin+size);
+}
+
+/*! \brief
+ * Constructs a reference to a particular range in a std::vector.
+ *
+ * \param[in] begin Iterator to the beginning of a range.
+ * \param[in] end Iterator to the end of a range.
+ *
+ * The referenced vector must remain valid and not be reallocated for
+ * the lifetime of this object.
+ *
+ * \related ConstArrayRef
+ */
+template <typename T>
+ConstArrayRef<T> constArrayRefFromVector(typename std::vector<T>::const_iterator begin,
+ typename std::vector<T>::const_iterator end)
+{
+ const T * p_begin = (begin != end) ? &*begin : NULL;
+ const T * p_end = p_begin + (end-begin);
+ return constArrayRefFromPointers<T>(p_begin, p_end);
+}
+
/*! \brief
* Simple swap method for ArrayRef objects.
*