📄 layoutdata.h
字号:
// This software is copyright (C) by the Lawrence Berkeley
// National Laboratory. Permission is granted to reproduce
// this software for non-commercial purposes provided that
// this notice is left intact.
//
// It is acknowledged that the U.S. Government has rights to
// this software under Contract DE-AC03-765F00098 between
// the U.S. Department of Energy and the University of
// California.
//
// This software is provided as a professional and academic
// contribution for joint exchange. Thus it is experimental,
// is provided ``as is'', with no warranties of any kind
// whatsoever, no support, no promise of updates, or printed
// documentation. By using this software, you acknowledge
// that the Lawrence Berkeley National Laboratory and
// Regents of the University of California shall have no
// liability with respect to the infringement of other
// copyrights by any part of this software.
//
#ifndef LAYOUTDATA_H
#define LAYOUTDATA_H
#include "BoxLayout.H"
#include "DataIterator.H"
//class ArrayViewData;
template<class T> class LayoutData
{
public:
friend class ArrayViewData;
LayoutData();
LayoutData(const BoxLayout& dp);
virtual ~LayoutData();
virtual void define(const BoxLayout& dp);
// this approach, of using the iterator itself for indexing is
// my own brilliance. This way you don't need all the
// crappy [Const][Dependent] Iterators. It also forces all
// data access to be done through the DataIterator, which will
// know how to talk to KeLP (or other parallel architectures,
// like multithreading, etc).
DataIterator dataIterator() const;
const T& operator[](const DataIndex& a_index) const;
const T& operator[](const DataIterator& a_iterator) const;
T& operator[](const DataIndex& a_index);
T& operator[](const DataIterator& a_iterator);
Box box(const DataIndex& a_index) const;
Box box(const DataIterator& a_iterator) const;
// not really a protection mechanism, since a user can always
// perform a shallow copy of the BoxLayout, and be free to manipulate
// the data in the object. If you wish to have an actual copy
// of the BoxLayout, then you need to invoke the clone() method.
const BoxLayout& boxLayout() const
{
return m_boxLayout;
}
protected:
BoxLayout m_boxLayout;
// this used to be std::vector<T>, and I could let vector handle
// destruction for me, but vector.resize() absolutely demands that
// I provide a copy constructor for T. People get uncomfortable when
// I make them provide me with copy constructors.
Vector<T*> m_vector;
// thinking about making this class self-documenting to a greater degree
// and having the component names also be kept in the class and carried
// around through various transformations.....
// vector<string> m_componentNames;
private:
// disallow copy constructors and assignment operators
// to avoid very hard-to-find performance problems
LayoutData<T>& operator= (const LayoutData<T>& rhs);
LayoutData(const LayoutData& rhs);
// handy usage function, tied to the implementation of this class
// as a vector<T*>. Assumes that m_comps and m_boxLayout have already
// been initialized correctly. Sets the correct size for the data
// vector, deletes the extra T objects if m_vector is to shorten, and
// performs either construction or define on the remaining T objects.
void allocate();
};
//======================================================================
//======================================================================
//========= inline functions ===========================
// not literally a .H file, but just an experiment in
// having useable, readable headers, while having
// the dependeny system work properly. Since LayoutData.H
// now depends on LayoutDataI.H, then changing either
// should cause all code that includes LayoutData.H to be
// recompiled. This way people can just read the interface
// in this file. Implementation is put in the *I.H file.
#include "LayoutDataI.H"
#endif // LAYOUTDATA_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -