00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 int
00027 FileDatastore::sendID(int dataTag, int commitTag,
00028 const ID &theID,
00029 ChannelAddress *theAddress)
00030 {
00031
00032
00033 int idSize = theID.Size();
00034 if (idSize >= maxIDsize) {
00035 opserr << "FileDatastore::sendID() - the database does not deal with IDs of this size ";
00036 opserr << idSize << endln;
00037 }
00038
00039
00040
00041 if (ids[idSize] == 0) {
00042 char fileName[70];
00043 char intName[10];
00044 strcpy(fileName, dataBase);
00045 itoa(idSize, intName);
00046 strcat(fileName,".IDs.");
00047 strcat(fileName,intName);
00048 ids[idSize] = this->openFile(fileName);
00049 int loc = ids[idSize]->tellg();
00050 if (loc == -1) loc = 0;
00051 opserr << "LOCATION: " << loc << endln;
00052 fileEnds.ids[idSize] = loc;
00053 }
00054
00055
00056 fstream *theStream = ids[idSize];
00057 int fileEnd = fileEnds.ids[idSize];
00058 int stepSize = (2 + idSize)*sizeof(int);
00059
00060 theStream->seekg(0);
00061 bool found = false;
00062 int pos =0;
00063
00064 while ((pos < fileEnd) && (found == false)) {
00065 theStream->read((char *)&idBuffer, stepSize);
00066 if ((idBuffer.dbTag == dataTag) && (idBuffer.commitTag == commitTag))
00067 found = true;
00068 else {
00069 pos += stepSize;
00070 }
00071 }
00072
00073
00074 idBuffer.dbTag = dataTag;
00075 idBuffer.commitTag = commitTag;
00076 for (int i=0; i<idSize; i++)
00077 idBuffer.data[i] = theID(i);
00078
00079
00080 if (found == true)
00081 theStream->seekp(pos);
00082
00083 theStream->write((char *)&idBuffer, stepSize);
00084
00085
00086 if (fileEnd <= pos)
00087 fileEnds.ids[idSize] += stepSize;
00088
00089 return 0;
00090 }
00091
00092 int
00093 FileDatastore::recvID(int dataTag, int commitTag,
00094 ID &theID,
00095 ChannelAddress *theAddress)
00096 {
00097
00098 int idSize = theID.Size();
00099 if (idSize >= maxIDsize) {
00100 opserr << "FileDatastore::recvID() - the database does not deal with IDs";
00101 opserr << " of this size " << idSize << endln;
00102 return -1;
00103 }
00104
00105
00106 if (ids[idSize] == 0) {
00107 char fileName[70];
00108 char intName[10];
00109 strcpy(fileName, dataBase);
00110 itoa(idSize, intName);
00111 strcat(fileName,".IDs.");
00112 strcat(fileName,intName);
00113 ids[idSize] = this->openFile(fileName);
00114 int loc = ids[idSize]->tellg();
00115 if (loc == -1) loc = 0;
00116 fileEnds.ids[idSize] = loc;
00117 }
00118
00119
00120 int stepSize = (2 + idSize)*sizeof(int);
00121 fstream *theStream = ids[idSize];
00122
00123 theStream->seekg(0);
00124 bool found = false;
00125 int pos =0;
00126 int fileEnd = fileEnds.ids[idSize];
00127
00128 while ((pos < fileEnd) && (found == false)) {
00129 theStream->read((char *)&idBuffer, stepSize);
00130 if ((idBuffer.dbTag == dataTag) && (idBuffer.commitTag == commitTag))
00131 found = true;
00132 pos += stepSize;
00133 }
00134
00135 if (found == false) {
00136 opserr << "FileDatastore::recvID() - failed to find data for ID of size ";
00137 opserr << idSize << endln;
00138 return -1;
00139 }
00140
00141
00142 idBuffer.dbTag = dataTag;
00143 idBuffer.commitTag = commitTag;
00144 for (int i=0; i<idSize; i++)
00145 theID(i) = idBuffer.data[i];
00146
00147 return 0;
00148 }