| 24 | |
| 25 | |
| 26 | int |
| 27 | FileDatastore::sendID(int dataTag, int commitTag, |
| 28 | const ID &theID, |
| 29 | ChannelAddress *theAddress) |
| 30 | { |
| 31 | |
| 32 | // we first ensure that the ID is not too big |
| 33 | int idSize = theID.Size(); |
| 34 | if (idSize >= maxIDsize) { |
| 35 | opserr << "FileDatastore::sendID() - the database does not deal with IDs of this size "; |
| 36 | opserr << idSize << endln; |
| 37 | } |
| 38 | |
| 39 | |
| 40 | // open a file if not already opened |
| 41 | if (ids[idSize] == 0) { |
| 42 | char fileName[70]; |
| 43 | char intName[10]; |
| 44 | strcpy(fileName, dataBase); |
| 45 | itoa(idSize, intName); |
| 46 | strcat(fileName,".IDs."); |
| 47 | strcat(fileName,intName); |
| 48 | ids[idSize] = this->openFile(fileName); |
| 49 | int loc = ids[idSize]->tellg(); |
| 50 | if (loc == -1) loc = 0; |
| 51 | opserr << "LOCATION: " << loc << endln; |
| 52 | fileEnds.ids[idSize] = loc; |
| 53 | } |
| 54 | |
| 55 | // we now found the location in the file to write the data |
| 56 | fstream *theStream = ids[idSize]; |
| 57 | int fileEnd = fileEnds.ids[idSize]; |
| 58 | int stepSize = (2 + idSize)*sizeof(int); |
| 59 | |
| 60 | theStream->seekg(0); |
| 61 | bool found = false; |
| 62 | int pos =0; |
| 63 | |
| 64 | while ((pos < fileEnd) && (found == false)) { |
| 65 | theStream->read((char *)&idBuffer, stepSize); |
| 66 | if ((idBuffer.dbTag == dataTag) && (idBuffer.commitTag == commitTag)) |
| 67 | found = true; |
| 68 | else { |
| 69 | pos += stepSize; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // we now place the data to be sent into our buffer |
| 74 | idBuffer.dbTag = dataTag; |
| 75 | idBuffer.commitTag = commitTag; |
| 76 | for (int i=0; i<idSize; i++) |
| 77 | idBuffer.data[i] = theID(i); |
| 78 | |
| 79 | // we now write the data |
| 80 | if (found == true) |
| 81 | theStream->seekp(pos); |
| 82 | |
| 83 | theStream->write((char *)&idBuffer, stepSize); |
no test coverage detected