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

📄 mvector.h

📁 这是一个从音频信号里提取特征参量的程序
💻 H
📖 第 1 页 / 共 5 页
字号:
// file: $isip/class/math/vector/MVector/MVector.h// version: $Id: MVector.h,v 1.84 2002/12/28 23:44:22 parihar Exp $//// make sure definitions are only made once//#ifndef ISIP_MVECTOR#define ISIP_MVECTOR// isip include files//#ifndef ISIP_BYTE#include <Byte.h>#endif#ifndef ISIP_ULONG#include <Ulong.h>#endif#ifndef ISIP_USHORT#include <Ushort.h>#endif#ifndef ISIP_ULLONG#include <Ullong.h>#endif#ifndef ISIP_SHORT#include <Short.h>#endif#ifndef ISIP_LONG#include <Long.h>#endif#ifndef ISIP_LLONG#include <Llong.h>#endif#ifndef ISIP_FLOAT#include <Float.h>#endif#ifndef ISIP_DOUBLE#include <Double.h>#endif#ifndef ISIP_COMPLEX_LONG#include <ComplexLong.h>#endif#ifndef ISIP_COMPLEX_FLOAT#include <ComplexFloat.h>#endif#ifndef ISIP_COMPLEX_DOUBLE#include <ComplexDouble.h>#endif#ifndef ISIP_STRING#include <String.h>#endif#ifndef ISIP_MVECTOR_METHODS#include "MVectorMethods.h"#endif// MVector: the vector template class which is inherited by other// vector classes. TScalar is a Scalar class, TIntegral is an Integral// type. most of the methods in this class are inline wrappers to the// MVectorMethods class functions. this is done to allow us to remove// implementations from the header file, and thus avoid the// compilation overhead inherent in compiling template classes with// multiple explicit instantiations.//template<class TScalar, class TIntegral>class MVector {    //---------------------------------------------------------------------------  //  // public constants  //  //---------------------------------------------------------------------------public:    // define the class name  //  static const String CLASS_NAME;    //----------------------------------------  //  // i/o related constants  //  //----------------------------------------      static const String DEF_PARAM;    // i/o data buffering lengths  //  static const long TEXT_READ_SIZE = 128;  static const long TEXT_PARTIAL_READ_SIZE = 33;  static const long TEXT_WRITE_SIZE = 512;    //----------------------------------------  //  // default values and arguments  //  //----------------------------------------      // define the default value(s) of the class data  //  static const TIntegral DEF_VALUE;  static const long DEF_LENGTH = 0;    // default arguments to methods  //  static const TIntegral DEF_OFFSET;  static const TIntegral DEF_INCR;  static const unichar DEF_DELIM = L',';  static const String DEF_DELIM_STR;  static const long DEF_SHIFT = 1;    //----------------------------------------  //  // error codes  //  //----------------------------------------      static const long ERR = 22000;  static const long ERR_LEN = 22001;    //---------------------------------------------------------------------------  //  // protected data  //  //---------------------------------------------------------------------------protected:    // vector elements  //  TScalar* v_d;    // the number of elements of this vector  //  Long length_d;    // the maximum number of elements  //  Long capacity_d;		         // declare a static debug level for all class instantiations  //  static Integral::DEBUG debug_level_d;    //---------------------------------------------------------------------------  //  // required public methods  //  //---------------------------------------------------------------------------public:    // method: name  //  static const String& name() {    return CLASS_NAME;  }    // other static methods  //  static boolean diagnose(Integral::DEBUG level) {    return MVectorMethods::      diagnose<MVector<TScalar, TIntegral>, TScalar, TIntegral>(level);  }    // method: setDebug  //  static boolean setDebug(Integral::DEBUG level) {    debug_level_d = level;    return true;  }    // method: debug  //  boolean debug(const unichar* message_a) const {    return debug(name(), message_a);  }    // method: destructor  //  ~MVector();    // method: default constructor  //  MVector();    // method: copy constructor  //  MVector(const MVector& vector);    // assign methods:  //  this method is templatized so it can also do conversions  //  template<class TAScalar, class TAIntegral>  boolean assign(const MVector<TAScalar, TAIntegral>& arg_a);    // operator= methods:  //  these methods are omitted because they are defined in the  //  classes that instantiate this template  //    // i/o methods  //  long sofSize() const {    return MVectorMethods::sofSize<TScalar, TIntegral>(*this);  }    boolean read(Sof& sof, long tag, const String& name = CLASS_NAME) {    return MVectorMethods::read<TScalar,TIntegral>(*this, sof, tag, name);  }    boolean write(Sof& sof, long tag, const String& name = CLASS_NAME) const {    return MVectorMethods::write<TScalar,TIntegral>(*this, sof, tag, name);  }    boolean readData(Sof& sof, const String& pname = DEF_PARAM,		   long size = SofParser::FULL_OBJECT,		   boolean param = true, boolean nested = true) {    return MVectorMethods::readData<TScalar,TIntegral>(*this, sof, pname,						       size, param, nested);  }    boolean writeData(Sof& sof, const String& name = DEF_PARAM) const {    return MVectorMethods::writeData<TScalar,TIntegral>(*this, sof, name);  }    // equality methods  //  boolean eq(const MVector& vector) const;    // memory management methods:  //  the new and delete methods are omitted because they are defined in the  //  classes that instantiate this template  //  boolean clear(Integral::CMODE cmode = Integral::DEF_CMODE);    //-------------------------------------------------------------------------  //  // class-specific public methods:  //  extensions to required methods  //  //-------------------------------------------------------------------------    // debug methods:  //  this second debug method is used so that template instantiations can use  //  a common debug method and just pass in their name  //  boolean debug(const String& name, const unichar* message) const;    // constructor(s)  //  MVector(long len);    // assign methods  //  boolean assign(TIntegral value);      boolean assign(long length, TIntegral value);    // array conversion methods  //  template<class TAIntegral>  boolean assign(long num_elem, const TAIntegral* arg) {    return MVectorMethods::assign<TScalar,TIntegral>(*this, num_elem, arg);  }    // conversion from string methods  //  boolean assign(const String& arg, unichar delim = DEF_DELIM) {    return MVectorMethods::assign<TScalar,TIntegral>(*this, arg, delim);  }    boolean assign(const unichar* arg, unichar delim = DEF_DELIM) {    return MVectorMethods::assign<TScalar,TIntegral>(*this, arg, delim);  }    // conversion to string methods  //  boolean get(String& output, const String& delim = DEF_DELIM_STR) const {    return MVectorMethods::get(*this, output, delim);  }    boolean get(String& output, const unichar* delim) const {    String delim_str(delim);    return MVectorMethods::get(*this, output, delim_str);  }    // swap methods:  //  swap the current vector with the input vector  //  boolean swap(MVector& arg) {    return MVectorMethods::swap<TScalar, TIntegral>(*this, arg);  }    // partial read methods  //  boolean readStart(Sof& sof, const String& pname = DEF_PARAM,		    long size = SofParser::FULL_OBJECT,		    boolean param = true,		    boolean nested = true) {    return MVectorMethods::      readStart<TScalar, TIntegral>(*this, sof, pname, size, param, nested);  }    long readPartialData(Sof& sof, long start_pos, long num_elem,		       const String& pname = DEF_PARAM,		       long size = SofParser::FULL_OBJECT,		       boolean param = true,		       boolean nested = false) {    return MVectorMethods::      readPartialData<TScalar,TIntegral>(*this, sof, start_pos,					 num_elem, pname, size, param, nested);  }    // method: readTerminate  //  boolean readTerminate(Sof& sof) {    return sof.stopPartialRead();  }    // partial write methods  //  boolean writeStart(Sof& sof, const String& pname = DEF_PARAM) const {    return MVectorMethods::writeStart<TScalar,TIntegral>(*this, sof, pname);  }    long writePartialData(Sof& sof, long start_pos, long num_elem) const {    return MVectorMethods::      writePartialData<TScalar, TIntegral>(*this, sof, start_pos, num_elem);  }    boolean writeTerminate(Sof& sof, const String& pname = DEF_PARAM) const {    return MVectorMethods::      writeTerminate<TScalar, TIntegral>(*this, sof, pname);  }    // memory size methods  //  long memSize() const {    return MVectorMethods::memSize<TScalar, TIntegral>(*this);  }    //---------------------------------------------------------------------------  //  // class-specific public methods:  //  equality and comparison methods  //  //---------------------------------------------------------------------------    // method: eq  //  boolean eq(TIntegral value) const {    return apply(value, &TScalar::eq);  }    // method: ne  //  boolean ne(const MVector& vector) const {    return (!eq(vector));  }    // method: ne  //  boolean ne(TIntegral value) const {    return apply(value, &TScalar::ne);  }    // method: lt  //  boolean lt(TIntegral value) const {    return apply(value, &TScalar::lt);  }    // method: le  //  boolean le(TIntegral value) const {    return apply(value, &TScalar::le);  }    // method: gt  //  boolean gt(TIntegral value) const {    return apply(value, &TScalar::gt);  }    // method: ge  //  boolean ge(TIntegral value) const {    return apply(value, &TScalar::ge);  }    // method: operator ==  //  boolean operator == (TIntegral arg) const {    return eq(arg);  }    // method: operator !=  //  boolean operator != (TIntegral arg) const {    return ne(arg);  }    // method: operator <  //  boolean operator < (TIntegral arg) const {    return lt(arg);  }    // method: operator <=  //  boolean operator <= (TIntegral arg) const {    return le(arg);  }    // method: operator >  //  boolean operator > (TIntegral arg) const {    return gt(arg);  }    // method: operator >=  //  boolean operator >= (TIntegral arg) const {    return ge(arg);  }    // almostEqual methods  //  boolean almostEqual(const MVector& vector,		      double percent = Integral::DEF_PERCENTAGE,		      double bound = Integral::DEF_BOUND) const;  boolean almostEqual(TIntegral value,		      double percent = Integral::DEF_PERCENTAGE,		      double bound = Integral::DEF_BOUND) const;    //---------------------------------------------------------------------------  //  // class-specific public methods:  //  operator overloads, get and set methods  //  //---------------------------------------------------------------------------    // method: operator()  //  TScalar& operator()(long index_a) {    return v_d[index_a];  }    // method: operator()  //  const TScalar& operator()(long index_a) const {    return v_d[index_a];  }    // method: length  //  long length() const {    return (long)length_d;  }    // method: getCapacity  //  long getCapacity() const {    return (long)capacity_d;  }    // resize methods  //  boolean setLength(long length, boolean preserve_values = true);  boolean setCapacity(long capacity, boolean preserve_values = true);    //---------------------------------------------------------------------------  //  // class-specific public methods:  //  bitwise methods, report error if TIntegral is float or double  //  //--------------------------------------------------------------------------    // method: band  //  boolean band(const MVector& v2) {    return apply(*this, v2, &TScalar::band);  }    // method: band  //  boolean band(const MVector& v1, const MVector& v2) {    return apply(v1, v2, &TScalar::band);  }    // method: band  //  boolean band(TIntegral value) {    return apply(*this, value, &TScalar::band);  }    // method: band  //  boolean band(const MVector& v1, TIntegral value) {    return apply(v1, value, &TScalar::band);  }    // method: bor  //  boolean bor(const MVector& v2) {    return apply(*this, v2, &TScalar::bor);  }    // method: bor  //  boolean bor(const MVector& v1, const MVector& v2) {    return apply(v1, v2, &TScalar::bor);  }    // method: bor  //  boolean bor(TIntegral value) {    return apply(*this, value, &TScalar::bor);  }    // method: bor  //  boolean bor(const MVector& v1, TIntegral value) {    return apply(v1, value, &TScalar::bor);  }    // method: bxor  //  boolean bxor(const MVector& v2) {    return apply(*this, v2, &TScalar::bxor);  }    // method: bxor  //  boolean bxor(const MVector& v1, const MVector& v2) {    return apply(v1, v2, &TScalar::bxor);  }    // method: bxor  //  boolean bxor(TIntegral value) {    return apply(*this, value, &TScalar::bxor);  }    // method: bxor  //  boolean bxor(const MVector& v1, TIntegral value) {    return apply(v1, value, &TScalar::bxor);  }    // method: brs  //  boolean brs(TIntegral shift_amount = DEF_SHIFT) {    return apply(*this, shift_amount, &TScalar::brs);  }    // method: brs  //  boolean brs(const MVector& v1, TIntegral shift_amount = DEF_SHIFT) {    return apply(v1, shift_amount, &TScalar::brs);  }    // method: bls  //  boolean bls(TIntegral shift_amount = DEF_SHIFT) {    return apply(*this, shift_amount, &TScalar::bls);  }    // method: bls  //  boolean bls(const MVector& v1, TIntegral shift_amount = DEF_SHIFT) {    return apply(v1, shift_amount, &TScalar::bls);  }    // method: bcmpl  //  boolean bcmpl(const MVector& v1) {    return apply(v1, &TScalar::bcmpl);  }    // method: bcmpl  //  boolean bcmpl() {    return apply(*this, &TScalar::bcmpl);  }    //---------------------------------------------------------------------------  //  // class-specific public methods:  //  basic mathematical methods  //  //--------------------------------------------------------------------------    // method: add  //  template<class TAScalar, class TAIntegral>  boolean add(const MVector<TAScalar, TAIntegral>& vector) {    return apply(*this, vector, &TScalar::add);  }    // method: add  //  template<class TAScalar, class TAIntegral>  boolean add(const MVector& v1, const MVector<TAScalar, TAIntegral>& v2) {    return apply(v1, v2, &TScalar::add);  }    // method: add  //  boolean add(TIntegral value) {    return apply(*this, value, &TScalar::add);  }    // method: add  //  boolean add(const MVector& vector, TIntegral value) {    return apply(vector, value, &TScalar::add);  }

⌨️ 快捷键说明

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