qsmall.h
来自「算断裂的」· C头文件 代码 · 共 199 行
H
199 行
// ------------------------------------------------------------------// qsmall.h//// This file contains small classes used by the mesh generator.// ------------------------------------------------------------------// Author: Stephen A. Vavasis// Copyright (c) 1999 by Cornell University. All rights reserved.// // See the accompanying file 'Copyright' for authorship information,// the terms of the license governing this software, and disclaimers// concerning this software.// ------------------------------------------------------------------// This file is part of the QMG software. // Version 2.0 of QMG, release date September 3, 1999.// ------------------------------------------------------------------#ifndef QSMALL_H#define QSMALL_H#include "qmgnamesp.h"// ------------------------------------------------------------------// class Qmg_Mask.// Class for a binary mask. For example, a mask called "flatdim"// is used as part of a boxes address to indicate which dimensions the box// is flat over.// ------------------------------------------------------------------class QMG::MG::Mask {private: UInt32 maskword; // the only actual member data is this word. // No virtual functions! We want this compact! static int r_dims_[MAXDIM_EXP]; static UInt32 diexp_; static int di_;public: static Mask zero; static void initialize_static_data(int di); static Mask diexp() {return diexp_;} static int embedded_dim() {return di_;} inline bool operator[](int i) const {#ifdef RANGECHECK if (i < 0 || i >= di_) throw_error("Subscript out of range in MASK(1)");#endif return ((maskword & (1 << i)) != 0); } inline void set_bit(int i) {#ifdef RANGECHECK if (i < 0 || i >= di_) throw_error("Subscript out of range in MASK(2)");#endif maskword |= (1 << i); } inline void clear_bit(int i) {#ifdef RANGE_CHECK if (i < 0 || i >= di_) throw_error("Subscript out of range in MASK(3)");#endif UInt32 tmp = maskword & (1 << i); maskword -= tmp; } inline Mask& operator= (UInt32 w) { maskword = w; return *this; } inline Mask& operator= (const Mask& w) { maskword = w.maskword; return *this; } inline void operator++ () { maskword++; } inline void operator-- () { maskword--; } static inline Mask merge(Mask a, Mask b) {return Mask(a.maskword | b.maskword);} inline operator UInt32() const { return maskword; } Mask() { } Mask(int i) { maskword = i; } inline int dim() const { return r_dims_[maskword]; };};// ------------------------------------------------------------------// class Base3// Base-3 numbers are used to index subfaces of boxes. Note that // a d-dimensional box has 3^d subfaces. The subfaces are indexed// by strings of the digits 0,1,2. For the unit cube, the indexes// mean the following. If the ith digit is zero, x_i=0. If// the ith digit is 1, x_i=1. If the ith digit is 2, x_i is // a free variable (must lie in [0,1]).// ------------------------------------------------------------------class QMG::MG::Base3 {private: // This next item is the only member data. No virtual functions! // We want this class to be compact! UInt32 maskword; static int base_3_digits[MAXDIM_3EXP][MAXDIM]; static UInt32 powers_3_[MAXDIM + 1]; static Mask r_flatdims[MAXDIM_3EXP]; static int r_dims[MAXDIM_3EXP]; static int di_; static UInt32 di3exp_;public: Base3() { maskword = 0; } Base3(UInt32 i) { maskword = i; } inline int operator [] (int i) const {#ifdef RANGECHECK if (i < 0 || i >= di_) throw_error("Subscript out of range in BASE3 (1) ");#endif return (base_3_digits[maskword][i]); } inline Base3 modify_digit(int i, int digit) const {#ifdef RANGECHECK if (i < 0 || i >= di_ || digit < 0 || digit > 2) throw_error("Subscript out of range in BASE3 (3)");#endif Base3 v(maskword + (digit - base_3_digits[maskword][i]) * powers_3_[i]); return v; } inline void set_digit(int i, int digit) {#ifdef RANGECHECK if (i < 0 || i >= di_ || digit < 0 || digit > 2) throw_error("Subscript out of range in BASE3 (2) ");#endif maskword += powers_3_[i] * digit; } static Base3 merge(Base3 a, Base3 b); inline Base3& operator= (UInt32 w) { maskword = w; return *this; } inline Base3& operator= (const Base3& w) { maskword = w.maskword; return *this;} inline void operator++ () { maskword++; } inline int operator==(const Base3& w) const { return maskword == w.maskword; } inline operator UInt32() const { return maskword; } inline Mask flatdim() const { return r_flatdims[maskword]; } inline int dim() const {return r_dims[maskword]; } static UInt32 power3(int i) { #ifdef RANGECHECK if (i < 0 || i > di_) throw_error("Subscript out of range in power3");#endif return powers_3_[i]; } void output(ostream& os, int dim) const; static void initialize_static_data(int di); static Base3 di3exp() { return di3exp_; } static int embedded_dim() { return di_;}};// A class that mimics bool. Used so that vector<My_bool> won't specialize.class QMG::MG::My_bool {private: bool b_;public: My_bool() : b_(false) {} My_bool(const My_bool& mb) : b_(mb.b_) { } My_bool(bool b) : b_(b) { } My_bool& operator=(const My_bool& mb) {b_ = mb.b_; return *this;} My_bool& operator=(bool b) {b_ = b; return *this;} operator bool() const {return b_;}};class QMG::MG::IntCoord {private: UInt32 intcoord_[MAXDIM]; static int di_;public: inline UInt32 operator[](int d) const {#if 0#ifdef RANGECHECK if (d < 0 || d >= di_) { throw_error("Arg out of range in IntCoord[]"); }#endif#endif return intcoord_[d]; } inline UInt32& operator[](int d) {#ifdef RANGECHECK if (d < 0 || d >= di_) { throw_error("Arg out of range in IntCoord[]"); }#endif return intcoord_[d]; } void increment(int dim, int width); static int compare(const IntCoord& a, const IntCoord& b); inline bool operator==(const IntCoord& b) const {return compare(*this,b) == 0;} static void initialize_static_data(int di) {di_ = di;} static int embedded_dim() { return di_; }};#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?