00001
00003 inline double& drovector::operator()(const long& i)
00004 {
00005 #ifdef CPPL_VERBOSE
00006 std::cerr << "# [MARK] drovector::operator()(const long&)"
00007 << std::endl;
00008 #endif//CPPL_VERBOSE
00009
00010 #ifdef CPPL_DEBUG
00011 if( i<0 || L<=i ){
00012 std::cerr << "[ERROR] drovector::operator()(const long&)"
00013 << std::endl
00014 << "The required component is out of the vector size."
00015 << std::endl
00016 << "Your input was (" << i << ")." << std::endl;
00017 exit(1);
00018 }
00019 #endif//CPPL_DEBUG
00020
00021 return Array[i];
00022 }
00023
00024
00026 inline double drovector::operator()(const long& i) const
00027 {
00028 #ifdef CPPL_VERBOSE
00029 std::cerr << "# [MARK] drovector::operator()(const long&) const"
00030 << std::endl;
00031 #endif//CPPL_VERBOSE
00032
00033 #ifdef CPPL_DEBUG
00034 if( i<0 || L<=i ){
00035 std::cerr << "[ERROR] drovector::operator()(const long&) const"
00036 << std::endl
00037 << "The required component is out of the vector size."
00038 << std::endl
00039 << "Your input was (" << i << ")." << std::endl;
00040 exit(1);
00041 }
00042 #endif//CPPL_DEBUG
00043
00044 return Array[i];
00045 }
00046
00050
00051
00053 inline void drovector::set(const long& i, const double& v) const
00054 {
00055 #ifdef CPPL_VERBOSE
00056 std::cerr << "# [MARK] drovector::set(const long&, const double&) const"
00057 << std::endl;
00058 #endif//CPPL_VERBOSE
00059
00060 #ifdef CPPL_DEBUG
00061 if( i<0 || L<=i ){
00062 std::cerr << "[ERROR] drovector::set(const long&, const double&) const"
00063 << std::endl
00064 << "The required component is out of the vector size."
00065 << std::endl
00066 << "Your input was (" << i << ")." << std::endl;
00067 exit(1);
00068 }
00069 #endif//CPPL_DEBUG
00070
00071 Array[i] =v;
00072 }
00073
00077
00078
00079 inline std::ostream& operator<<(std::ostream& s, const drovector& vec)
00080 {
00081 #ifdef CPPL_VERBOSE
00082 std::cerr << "# [MARK] operator<<(std::ostream&, const drovector&)"
00083 << std::endl;
00084 #endif//CPPL_VERBOSE
00085
00086 for(long i=0; i<vec.L; i++){ s << " " << vec.Array[i]; }
00087 s << std::endl;
00088
00089 return s;
00090 }
00091
00095
00096
00097 inline void drovector::write(const char *filename) const
00098 {
00099 #ifdef CPPL_VERBOSE
00100 std::cerr << "# [MARK] drovector::write(const char*) const"
00101 << std::endl;
00102 #endif//CPPL_VERBOSE
00103
00104 std::ofstream s(filename, std::ios::trunc);
00105
00106 s << "drovector" << " " << L << std::endl;
00107 for(long i=0; i<L; i++){
00108 s << operator()(i) << " ";
00109 }
00110 s << std::endl;
00111
00112 s.close();
00113 }
00114
00115
00116 inline void drovector::read(const char *filename)
00117 {
00118 #ifdef CPPL_VERBOSE
00119 std::cerr << "# [MARK] drovector::read(const char*)"
00120 << std::endl;
00121 #endif//CPPL_VERBOSE
00122
00123 std::ifstream s( filename );
00124 if(!s){
00125 std::cerr << "[ERROR] drovector::read(const char*) " << std::endl
00126 << "The file \"" << filename << "\" can not be opened."
00127 << std::endl;
00128 exit(1);
00129 }
00130
00131 std::string id;
00132 s >> id;
00133 if( id != "drovector" ){
00134 std::cerr << "[ERROR] drovector::read(const char*) " << std::endl
00135 << "The type name of the file \"" << filename
00136 << "\" is not drovector." << std::endl
00137 << "Its type name was " << id << " ." << std::endl;
00138 exit(1);
00139 }
00140
00141 s >> L;
00142 resize(L);
00143 for(long i=0; i<L; i++) { s >> operator()(i); }
00144 if(s.eof()){
00145 std::cerr << "[ERROR] drovector::read(const char*) " << std::endl
00146 << "There is something is wrong with the file \""
00147 << filename << " ." << std::endl
00148 << "Most likely, there is not enough data components, "
00149 << "or a linefeed code or space code is missing "
00150 << "at the end of the last line." << std::endl;
00151 exit(1);
00152 }
00153
00154 s.close();
00155 }