DatabaseStream.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 1999, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** ****************************************************************** */
00020                                                                         
00021 // $Revision: 1.1 $
00022 // $Date: 2006/08/03 23:28:34 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/handler/DatabaseStream.cpp,v $
00024                                                                         
00025 // Written: fmk 
00026 // Date: 10/04
00027 //
00028 // Description: This file contains the class implementation for
00029 // DatabaseStream. 
00030 //
00031 // What: "@(#) DatabaseStream.C, revA"
00032 
00033 #include "DatabaseStream.h"
00034 #include <FE_Datastore.h>
00035 #include <Vector.h>
00036 #include <bool.h>
00037 
00038 DatabaseStream::DatabaseStream(FE_Datastore *database, const char *tName)
00039   :OPS_Stream(OPS_STREAM_TAGS_DatabaseStream),
00040    theDatabase(database), tableName(0), numColumns(0), columns(0), commitTag(0)
00041 {
00042   //
00043   // create memory to store the dataDescription and make a copy of it
00044   //
00045 
00046   if (tName != 0) {
00047     tableName = new char [strlen(tName)+1];
00048     strcpy(tableName, tName);
00049     if (tableName == 0) {
00050       opserr << "DatabaseStream::DatabaseStream - out of memory creating copy of tableName: " << tName << endln;
00051     }
00052   }
00053 }
00054 
00055 DatabaseStream::~DatabaseStream()
00056 {
00057   if (tableName != 0)
00058     delete [] tableName;
00059 
00060   if (columns != 0) {
00061     for (int j=0; j<numColumns; j++)
00062       delete [] columns[j];
00063     delete [] columns;
00064   }
00065 }
00066 
00067 
00068 int 
00069 DatabaseStream::write(Vector &data) 
00070 {
00071   if (descriptionDone == false) {
00072     descriptionDone = true;
00073     this->open();
00074   }
00075     
00076   int result = 0;
00077 
00078   if (data.Size() == numColumns)
00079     if (theDatabase != 0)
00080       result = theDatabase->insertData(tableName, columns, commitTag, data);
00081       else {
00082       opserr << "DatabaseStream::write() - database has not been set\n";
00083       return -1;
00084     } 
00085   else {
00086     opserr << "DatabaseStream::write() - Vector not of correct size or open() has not been called\n" << numColumns << " " << data.Size() << endln;
00087     return -1;
00088   }
00089 
00090   commitTag++;
00091 
00092   return result;
00093 }
00094 
00095 
00096 int 
00097 DatabaseStream::setDatabase(FE_Datastore &database, const char *tName)
00098 {
00099   if (tName == 0 || strlen(tName) == 0) {
00100     opserr << "DatabaseStream::DatabaseStream - no tableName passed\n";
00101     return -1;
00102   }
00103 
00104   if (tableName != 0)
00105     delete [] tableName;
00106   
00107   tableName = new char [strlen(tName)+1];
00108   strcpy(tableName, tName);
00109   if (tableName == 0) {
00110     opserr << "DatabaseStream::DatabaseStream - out of memory creating copy of tableName: " << tName << endln;
00111     return -1;
00112   }
00113 
00114   theDatabase = &database;
00115   return 0;
00116 }
00117 
00118 
00119 int 
00120 DatabaseStream::tag(const char *tagName)
00121 {
00122   // output the xml for it to the file
00123 
00124   return 0;
00125 }
00126 
00127 
00128 int 
00129 DatabaseStream::tag(const char *tagName, const char * value)
00130 {
00131   // output the xml for it to the file
00132 
00133   return 0;
00134 }
00135 
00136 
00137 int 
00138 DatabaseStream::endTag()
00139 {
00140 
00141   return 0;
00142 }
00143 
00144 int 
00145 DatabaseStream::attr(const char *name, int value)
00146 {
00147 
00148   //  outputDatabase << name << " = " << value << endln;
00149   
00150   return 0;
00151 }
00152 
00153 int 
00154 DatabaseStream::attr(const char *name, double value)
00155 {
00156   //  outputDatabase << name << " = " << value << endln;
00157 
00158   return 0;
00159 }
00160 
00161 int 
00162 DatabaseStream::attr(const char *name, const char *value)
00163 {
00164 
00165   //  outputDatabase << name << " = " << value << endln;
00166 
00167   return 0;
00168 }
00169 
00170 
00171 // regular stuff
00172 OPS_Stream& 
00173 DatabaseStream::operator<<(char c)
00174 {
00175 
00176   return *this;
00177 }
00178 
00179 OPS_Stream& 
00180 DatabaseStream::operator<<(unsigned char c)
00181 {
00182 
00183   return *this;
00184 }
00185 
00186 OPS_Stream& 
00187 DatabaseStream::operator<<(signed char c)
00188 {
00189 
00190   return *this;
00191 }
00192 
00193 OPS_Stream& 
00194 DatabaseStream::operator<<(const char *s)
00195 {
00196 
00197   return *this;
00198 }
00199 
00200 OPS_Stream& 
00201 DatabaseStream::operator<<(const unsigned char *s)
00202 {
00203 
00204   return *this;
00205 }
00206 
00207 OPS_Stream& 
00208 DatabaseStream::operator<<(const signed char *s)
00209 {
00210 
00211   return *this;
00212 }
00213 
00214 OPS_Stream& 
00215 DatabaseStream::operator<<(const void *p)
00216 {
00217 
00218   return *this;
00219 }
00220 
00221 OPS_Stream& 
00222 DatabaseStream::operator<<(int n)
00223 {
00224 
00225   return *this;
00226 }
00227 
00228 OPS_Stream& 
00229 DatabaseStream::operator<<(unsigned int n)
00230 {
00231 
00232   return *this;
00233 }
00234 
00235 OPS_Stream& 
00236 DatabaseStream::operator<<(long n)
00237 {
00238 
00239   return *this;
00240 }
00241 
00242 OPS_Stream& 
00243 DatabaseStream::operator<<(unsigned long n)
00244 {
00245 
00246   return *this;
00247 }
00248 
00249 OPS_Stream& 
00250 DatabaseStream::operator<<(short n)
00251 {
00252 
00253   return *this;
00254 }
00255 
00256 OPS_Stream& 
00257 DatabaseStream::operator<<(unsigned short n)
00258 {
00259 
00260   return *this;
00261 }
00262 
00263 OPS_Stream& 
00264 DatabaseStream::operator<<(bool b)
00265 {
00266 
00267   return *this;
00268 }
00269 
00270 OPS_Stream& 
00271 DatabaseStream::operator<<(double n)
00272 {
00273 
00274   return *this;
00275 }
00276 
00277 OPS_Stream& 
00278 DatabaseStream::operator<<(float n)
00279 {
00280 
00281   return *this;
00282 }
00283 
00284  
00285 
00286 int 
00287 DatabaseStream::sendSelf(int commitTag, Channel &theChannel)
00288 {
00289   opserr << "DatabaseStream::sendSelf() - not yet implemented\n";
00290   return -1;
00291 }
00292 int 
00293 DatabaseStream::recvSelf(int commitTag, Channel &theChannel, FEM_ObjectBroker &theBroker)
00294 {
00295   opserr << "DatabaseStream::sendSelf() - not yet implemented\n";
00296   return -1;
00297 }
00298 
00299 
00300 int 
00301 DatabaseStream::open()
00302 {
00303   //
00304   // check the args are valid & that database has been set
00305   //
00306 
00307   if (theDatabase == 0) {
00308     opserr << "DatabaseStream::open() - database has not been set\n";
00309     return -1;
00310   } 
00311 
00312   if (tableName == 0) {
00313     opserr << "DatabaseStream::open() - no tableName passed or failed to get memory\n";
00314     return -1;
00315   }
00316 
00317   // ask database to create a table
00318   return theDatabase->createTable(tableName, numColumns, columns);
00319 }
00320 

Generated on Mon Oct 23 15:05:12 2006 for OpenSees by doxygen 1.5.0