CPPLapack
 All Classes Files Functions Variables Friends
dcovector-io.hpp
Go to the documentation of this file.
00001 //=============================================================================
00002 /*! operator() for non-const object */
00003 inline double& dcovector::operator()(const long& i)
00004 {VERBOSE_REPORT;
00005 #ifdef  CPPL_DEBUG
00006   if( i<0 || l<=i ){
00007     ERROR_REPORT;
00008     std::cerr << "The required component is out of the vector size." << std::endl
00009               << "Your input was (" << i << ")." << std::endl;
00010     exit(1);
00011   }
00012 #endif//CPPL_DEBUG
00013   
00014   return array[i];
00015 }
00016 
00017 //=============================================================================
00018 /*! operator() for const object */
00019 inline double dcovector::operator()(const long& i) const
00020 {VERBOSE_REPORT;
00021 #ifdef  CPPL_DEBUG
00022   if( i<0 || l<=i ){
00023     ERROR_REPORT;
00024     std::cerr << "The required component is out of the vector size." << std::endl
00025               << "Your input was (" << i << ")." << std::endl;
00026     exit(1);
00027   }
00028 #endif//CPPL_DEBUG
00029   
00030   return array[i];
00031 }
00032 
00033 ///////////////////////////////////////////////////////////////////////////////
00034 ///////////////////////////////////////////////////////////////////////////////
00035 ///////////////////////////////////////////////////////////////////////////////
00036 
00037 //=============================================================================
00038 /*! set value for const object */
00039 inline dcovector& dcovector::set(const long& i, const double& v) //const
00040 {VERBOSE_REPORT;
00041 #ifdef  CPPL_DEBUG
00042   if( i<0 || l<=i ){
00043     ERROR_REPORT;
00044     std::cerr << "The required component is out of the vector size." << std::endl
00045               << "Your input was (" << i << ")." << std::endl;
00046     exit(1);
00047   }
00048 #endif//CPPL_DEBUG
00049   
00050   array[i] =v;
00051   return *this;
00052 }
00053 
00054 ///////////////////////////////////////////////////////////////////////////////
00055 ///////////////////////////////////////////////////////////////////////////////
00056 ///////////////////////////////////////////////////////////////////////////////
00057 
00058 //=============================================================================
00059 inline std::ostream& operator<<(std::ostream& s, const dcovector& vec)
00060 {VERBOSE_REPORT;
00061   for(long i=0; i<vec.l; i++){
00062     s << " " << vec.array[i] << std::endl;
00063   }
00064   
00065   return s;
00066 }
00067 
00068 ///////////////////////////////////////////////////////////////////////////////
00069 ///////////////////////////////////////////////////////////////////////////////
00070 ///////////////////////////////////////////////////////////////////////////////
00071 
00072 //=============================================================================
00073 inline void dcovector::write(const char *filename) const
00074 {VERBOSE_REPORT;
00075   std::ofstream ofs(filename, std::ios::trunc);
00076   ofs.setf(std::cout.flags());
00077   ofs.precision(std::cout.precision());
00078   ofs.width(std::cout.width());
00079   ofs.fill(std::cout.fill());
00080   
00081   ofs << "#dcovector" << " " << l << std::endl;
00082   for(long i=0; i<l; i++){
00083     ofs << operator()(i) << std::endl;
00084   }
00085   
00086   ofs.close();
00087 }
00088 
00089 //=============================================================================
00090 inline void dcovector::read(const char *filename)
00091 {VERBOSE_REPORT;
00092   std::ifstream s(filename);
00093   if(!s){
00094     ERROR_REPORT;
00095     std::cerr << "The file \"" << filename << "\" can not be opened." << std::endl;
00096     exit(1);
00097   }
00098 
00099   std::string id;
00100   s >> id;
00101   if( id != "dcovector" && id != "#dcovector" ){
00102     ERROR_REPORT;
00103     std::cerr << "The type name of the file \"" << filename << "\" is not dcovector." << std::endl
00104               << "Its type name was " << id << " ." << std::endl;
00105     exit(1);
00106   }
00107   
00108   s >> l;
00109   resize(l);
00110   for(long i=0; i<l; i++) { s >> operator()(i); }
00111   if(s.eof()){
00112     ERROR_REPORT;
00113     std::cerr << "There is something is wrong with the file \"" << filename << "\"." << std::endl
00114               << "Most likely, there is a lack of data components, or a linefeed code or space code is missing at the end of the last line." << std::endl;
00115     exit(1);
00116   }
00117   
00118   s >> id;
00119   if(!s.eof()){
00120     ERROR_REPORT;
00121     std::cerr << "There is something is wrong with the file \"" << filename << "\"." << std::endl
00122               << "Most likely, there are extra data components." << std::endl;
00123     exit(1);
00124   }
00125   
00126   
00127   s.close();
00128 }
 All Classes Files Functions Variables Friends