⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 field.h

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 H
📖 第 1 页 / 共 2 页
字号:

    friend ifield operator*(const ifield&, INT);
    friend ifield operator*(INT, const ifield&);
    ifield& operator*=(INT);
    friend ifield operator/(const ifield&, INT);
    friend ifield operator/(INT, const ifield&);
    ifield& operator/=(INT);
    friend ifield operator%(const ifield&, INT);
    friend ifield operator%(INT, const ifield&);
    ifield& operator%=(INT);
    friend ifield operator+(const ifield&, INT);
    friend ifield operator+(INT, const ifield&);
    ifield& operator+=(INT);
    friend ifield operator-(const ifield&, INT);
    friend ifield operator-(INT, const ifield&);
    ifield& operator-=(INT);
    friend ifield operator^(const ifield&, INT);
    friend ifield operator^(INT, const ifield&);
    ifield& operator^=(INT);
    friend ifield operator&(const ifield&, INT);
    friend ifield operator&(INT, const ifield&);
    ifield& operator&=(INT);
    friend ifield operator|(const ifield&, INT);
    friend ifield operator|(INT, const ifield&);
    ifield& operator|=(INT);
    friend ifield operator<(const ifield&, INT);
    friend ifield operator<(INT, const ifield&);
    friend ifield operator>(const ifield&, INT);
    friend ifield operator>(INT, const ifield&);
    friend ifield operator<=(const ifield&, INT);
    friend ifield operator<=(INT, const ifield&);
    friend ifield operator>=(const ifield&, INT);
    friend ifield operator>=(INT, const ifield&);
    friend ifield operator<<(const ifield&, INT);
    friend ifield operator<<(INT, const ifield&);
    ifield& operator<<=(INT);
    friend ifield operator>>(const ifield&, INT);
    friend ifield operator>>(INT, const ifield&);
    ifield& operator>>=(INT);
    friend ifield operator&&(const ifield&, INT);
    friend ifield operator&&(INT, const ifield&);
    friend ifield operator||(const ifield&, INT);
    friend ifield operator||(INT, const ifield&);
    friend ifield operator==(const ifield&, INT);
    friend ifield operator==(INT, const ifield&);
    friend ifield operator!=(const ifield&, INT);
    friend ifield operator!=(INT, const ifield&);

// Operators with other integer fields

    friend ifield  operator*(const ifield&, const ifield&);
    ifield& operator*=(const ifield& ab);
    friend ifield  operator/(const ifield&, const ifield&);
    ifield& operator/=(const ifield& ab);
    friend ifield  operator%(const ifield&, const ifield&);
    ifield& operator%=(const ifield& ab);
    friend ifield  operator+(const ifield&, const ifield&);
    ifield& operator+=(const ifield& ab);
    friend ifield  operator-(const ifield&, const ifield&);
    ifield& operator-=(const ifield& ab);
    friend ifield operator^(const ifield&, const ifield&);
    ifield& operator^=(const ifield&);
    friend ifield operator|(const ifield&, const ifield&);
    ifield& operator|=(const ifield&);
    friend ifield operator&(const ifield&, const ifield&);
    ifield& operator&=(const ifield&);
    friend ifield operator<<(const ifield&, const ifield&);
    ifield& operator<<=(const ifield&);
    friend ifield operator>>(const ifield&, const ifield&);
    ifield& operator>>=(const ifield&);

    friend ifield operator==(const ifield&, const ifield&);
    friend ifield operator!=(const ifield&, const ifield&);
    friend ifield operator<( const ifield&, const ifield&);
    friend ifield operator>( const ifield&, const ifield&);
    friend ifield operator<=(const ifield&, const ifield&);
    friend ifield operator>=(const ifield&, const ifield&);
    friend ifield operator||(const ifield&, const ifield&);
    friend ifield operator&&(const ifield&, const ifield&);

// operators returning ifield

    friend ifield operator==(const field&, double);
    friend ifield operator==(double, const field&);
    friend ifield operator==(const field&, const field&);
    friend ifield operator!=(const field&, double);
    friend ifield operator!=(double, const field&);
    friend ifield operator!=(const field&, const field&);
    friend ifield operator<(const field&, double);
    friend ifield operator<(double, const field&);
    friend ifield operator<(const field&, const field&);
    friend ifield operator>(const field&, double);
    friend ifield operator>(double, const field&);
    friend ifield operator>(const field&, const field&);
    friend ifield operator<=(const field&, double);
    friend ifield operator<=(double, const field&);
    friend ifield operator<=(const field&, const field&);
    friend ifield operator>=(const field&, double);
    friend ifield operator>=(double, const field&);
    friend ifield operator>=(const field&, const field&);

 				// Methods

// find the sum of all the components

    INT Sum(void) const;

// Perform the indicated function element-by-element

    friend ifield abs(const ifield&);
    friend void div(const ifield&, const ifield&, ifield&, ifield&);
    void rand(void);

// FORTRAN-like functions

    friend ifield min(INT, const ifield&);
    friend ifield max(INT, const ifield&);
    friend ifield min(const ifield&, INT);
    friend ifield max(const ifield&, INT);
    friend ifield min(const ifield&, const ifield&);
    friend ifield max(const ifield&, const ifield&);
    friend INT min(const ifield&);
    friend INT max(const ifield&);
    friend ifield sign(INT, const ifield&);
    friend ifield sign(const ifield&, INT);
    friend ifield sign(const ifield&, const ifield&);
    friend ifield dim(INT, const ifield&);
    friend ifield dim(const ifield&, INT);
    friend ifield dim(const ifield&, const ifield&);

// perform a gather operation

    ifield Shift(int) const;

    ifield& Assemble(const ifield& a, const ifield& ia, const ifield& ib);
		// Add selected elements from a to this.  ib lists the 
		// elements selected from a and ia lists their destination
		// in this. ia and ib must be the same length; this and a
		// need not be the same length.  To function reliably, it
		// is necessary that each value in ia be unique. 

    ifield& Assemble(const ifield& a, const ifield& ia);
		// Add all elements from a to selected elements of this.
		// ia lists the destination of each element of a.  ia and
		// a must be the same size; a and this need not be the same
		// size. To function reliably, each value in ia should be
		// unique.

    ifield& Assemble(INT, const ifield& ia);
		// Like the previous function, but a constant value is
		// being assembled into selected elements of this.

    ifield& Scatter(const ifield& a, const ifield& ia, const ifield& ib);
		// Scatter selected elements from a to this (replacing the
		// old values.)  ib lists the elements selected from a and ia 
		// lists their destination in this. ia and ib must be the same
		// length; this and a need not be the same length.  To function
		// reliably, it is necessary that each value in ia be unique. 

    ifield& Scatter(const ifield& a, const ifield& ia);
		// Scatter the elements of a into this (replacing the old
		// values).  ia lists the destination of each element
		// in this.  a and ia must be the same length. To function 
		// reliably, each value in ia should be unique.

    ifield& Scatter(INT fill, const ifield& ia);
		// Like the previous function, but a constant value is
		// being scattered into selected elements of this.
 
    ifield Gather(const ifield& ia) const;
		// Gather selected elements from this into a new ifield.
		// ia lists the elements to select.  the result will have
		// the same length as ia.  The mapping need NOT be one-to-one
		// to function reliably.

    ifield& Scatter(const ifield& a, size_t start, size_t end, size_t stride=1);
		// Scatter the elements of a into those elements of the ifield
		// whose indices are n*stride+start.  The length of the ifield
		// must be stride times the length of a and start must be less
		// than stride.

    ifield Gather(size_t start, size_t end, size_t stride=1) const;
		// Gather the elements whose indices are given by n*stride+start
		// into a new ifield. The value of start must be less than 
		// the value of stride.

// I/O

    friend size_t fwrite(const ifield&, FILE*);
    friend size_t fread(ifield&, FILE*);

// Miscellaneous

    void Free(void);

  private:

    friend class field;

    // Data

    int ref_flag;
    struct __field_inode *root;

    // Methods

    void Private(void);
};

/******************************* Inlines *************************************/

/**** __field_node ****/

inline __field_node::__field_node(size_t size) :
  length(size),
  ref_count(1)
{}

inline __field_node* __field_node::NewCopy(void) const {
  return new(length) __field_node(*this);
}

/**** __field_inode ****/

inline __field_inode::__field_inode(size_t size) :
  length(size),
  ref_count(1)
{}

inline __field_inode* __field_inode::NewCopy(void) const {
  return new(length) __field_inode(*this);
}

/**** field ****/

inline field::field(void) :
  ref_flag(0),
  root(NULL)
{}

inline field::field(size_t size) :
  ref_flag(0),
  root(new(size) __field_node(size))
{}

inline field::field(size_t size, double fill) :
  ref_flag(0),
  root(new(size) __field_node(size, fill))
{}

inline field::~field(void){ Free(); }

inline size_t field::Length(void) const {
  return root? root->length : 0;
}

inline double field::operator[](size_t n) const{
  assert(n<root->length);
  return root->data[n];
}
inline double& field::operator[](size_t n) {
  assert(n<root->length);
  if (root->ref_count>1) Private();
  ref_flag = 1;
  return root->data[n];
}

inline field::operator const double*(void) const{ 
  assert(root!=NULL);
  return root->data; 
}
inline field::operator double *(void){ 
  assert(root!=NULL);
  ref_flag = 1;
  if (root->ref_count>1) Private();
  return root->data; 
}

inline field field::operator+(void) const{
  return *this;
}

/**** ifield ****/

inline ifield::ifield(void) :
  ref_flag(0),
  root(NULL)
{}

inline ifield::ifield(size_t size) :
  ref_flag(0),
  root(new(size) __field_inode(size))
{}

inline ifield::ifield(size_t size, INT fill) :
  ref_flag(0),
  root(new(size) __field_inode(size, fill))
{}

inline ifield::~ifield(void){ Free(); }

inline size_t ifield::Length(void) const {
  return root? root->length : 0;
}

inline INT ifield::operator[](size_t n) const{
  assert(n<root->length);
  return root->data[n];
}

inline INT& ifield::operator[](size_t n) {
  assert(n<root->length);
  if (root->ref_count>1) Private();
  ref_flag = 1;
  return root->data[n];
}

inline ifield::operator const INT *(void) const{
  assert(root!=NULL);
  return root->data; 
}
inline ifield::operator INT *(void){
  assert(root!=NULL);
  if (root->ref_count>1) Private();
  ref_flag = 1;
  return root->data; 
}

inline ifield ifield::operator+(void) const{
  return *this;
}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -