[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[certi-cvs] certi RTIA/FederationManagement.cc RTIG/RTIG_pr...
From: |
certi-cvs |
Subject: |
[certi-cvs] certi RTIA/FederationManagement.cc RTIG/RTIG_pr... |
Date: |
Sun, 27 Apr 2008 08:37:47 +0000 |
CVSROOT: /sources/certi
Module name: certi
Changes by: Eric NOULARD <erk> 08/04/27 08:37:47
Modified files:
RTIA : FederationManagement.cc
RTIG : RTIG_processing.cc Federation.cc
Log message:
Prefer C++ style I/O
FILE* --> std::ifstream or std::oftstream
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/RTIA/FederationManagement.cc?cvsroot=certi&r1=3.54&r2=3.55
http://cvs.savannah.gnu.org/viewcvs/certi/RTIG/RTIG_processing.cc?cvsroot=certi&r1=3.62&r2=3.63
http://cvs.savannah.gnu.org/viewcvs/certi/RTIG/Federation.cc?cvsroot=certi&r1=3.82&r2=3.83
Patches:
Index: RTIA/FederationManagement.cc
===================================================================
RCS file: /sources/certi/certi/RTIA/FederationManagement.cc,v
retrieving revision 3.54
retrieving revision 3.55
diff -u -b -r3.54 -r3.55
--- RTIA/FederationManagement.cc 26 Apr 2008 14:59:41 -0000 3.54
+++ RTIA/FederationManagement.cc 27 Apr 2008 08:37:46 -0000 3.55
@@ -18,7 +18,7 @@
// along with this program ; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// $Id: FederationManagement.cc,v 3.54 2008/04/26 14:59:41 erk Exp $
+// $Id: FederationManagement.cc,v 3.55 2008/04/27 08:37:46 erk Exp $
// ----------------------------------------------------------------------------
#include <config.h>
@@ -264,7 +264,7 @@
NM_Get_FED_File requeteFED;
int i, nb ;
- char *filename ; // Needed for working file name
+ char* filename ; // Needed for working file name
G.Out(pdGendoc,"enter FederationManagement::joinFederationExecution");
D.Out(pdInit, "Join Federation %s as %s.", Federation, Federate);
@@ -332,9 +332,10 @@
_FEDid = new char[strlen(filename)+1] ;
strcpy(_FEDid,filename) ;
// RTIA opens working file
- FILE *fdd;
- if ( (fdd=fopen(filename,"w")) == NULL )
+ std::ofstream fedWorkFile(filename);
+ if ( !fedWorkFile.is_open()) {
throw RTIinternalError("FED file has vanished.") ;
+ }
// RTIA says RTIG OK for file transfer
requeteFED.federateName = Federate;
@@ -365,13 +366,11 @@
// Line read
num_line++ ;
// Check for EOF
- if ( reponse->number == 0 )
- break;
+ if ( reponse->number == 0 ) break;
+
assert ( num_line == reponse->number ) ;
reponse->handleArraySize = 1 ;
- //file_line = reponse->getValue(0,&length) ;
- int nbw = fputs(getFedMsg->getFEDLine().c_str(),fdd);
- //file_line = NULL ;
+ fedWorkFile << getFedMsg->getFEDLine();
// RTIA says OK to RTIG
requeteFED.federateName =Federate;
requeteFED.number = num_line ;
@@ -379,7 +378,7 @@
comm->sendMessage(&requeteFED);
}
// close working file
- fclose(fdd);
+ fedWorkFile.close();
}
G.Out(pdGendoc,"joinFederationExecution====> end FED file get from
RTIG");
Index: RTIG/RTIG_processing.cc
===================================================================
RCS file: /sources/certi/certi/RTIG/RTIG_processing.cc,v
retrieving revision 3.62
retrieving revision 3.63
diff -u -b -r3.62 -r3.63
--- RTIG/RTIG_processing.cc 26 Apr 2008 14:59:42 -0000 3.62
+++ RTIG/RTIG_processing.cc 27 Apr 2008 08:37:47 -0000 3.63
@@ -18,13 +18,14 @@
// along with this program ; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// $Id: RTIG_processing.cc,v 3.62 2008/04/26 14:59:42 erk Exp $
+// $Id: RTIG_processing.cc,v 3.63 2008/04/27 08:37:47 erk Exp $
// ----------------------------------------------------------------------------
#include <config.h>
#include "RTIG.hh"
#include "NM_Classes.hh"
+#include <iostream>
#include <assert.h>
using std::endl ;
@@ -216,9 +217,8 @@
// Here begin FED file processing i.e. RTIG gives FED file contents to RTIA
TypeException e = e_NO_EXCEPTION ;
// Open FED file and says to RTIA if success
- FILE *fdd ;
- if ( (fdd=fopen(filename.c_str(),"r")) == NULL )
- {
+ std::ifstream fedFile(filename.c_str());
+ if ( !fedFile.is_open()) {
// Problem : file has been opened during create federation and now we
can't
// May be file has been deleted
cout << "processJoinFederation : FED file " << filename << " has
vanished." << endl;
@@ -248,11 +248,14 @@
assert ( msg.number == 0 );
// RTIA has opened working file then RTIG has to transfer file contents
// line by line
- char file_line[MAX_BYTES_PER_VALUE+1];
+ std::string fileLine;
int num_line = 0 ;
- while ( fgets(file_line,MAX_BYTES_PER_VALUE,fdd) != NULL )
+ while (!fedFile.eof())
{
num_line++;
+ // Read a line
+ std::getline(fedFile,fileLine);
+ fileLine = fileLine+"\n";
// RTIG sends line to RTIA and number gives line number
repFED.exception = e_NO_EXCEPTION ;
repFED.federate = num_federe ;
@@ -260,7 +263,8 @@
repFED.number = num_line ;
repFED.FEDid = filename;
// line transfered
- repFED.setFEDLine(std::string(file_line));
+ repFED.setFEDLine(fileLine);
+ cout << fileLine;
// Send answer
repFED.send(link);
@@ -270,13 +274,12 @@
}
// close
- fclose(fdd) ;
+ fedFile.close();
repFED.exception = e_NO_EXCEPTION ;
repFED.federate = num_federe ;
repFED.federation = num_federation ;
repFED.number = 0 ;
repFED.FEDid = filename;
-
// Send answer
G.Out(pdGendoc,"processJoinFederation====>End FED file transfer");
@@ -1392,4 +1395,4 @@
}} // namespace certi/rtig
-// $Id: RTIG_processing.cc,v 3.62 2008/04/26 14:59:42 erk Exp $
+// $Id: RTIG_processing.cc,v 3.63 2008/04/27 08:37:47 erk Exp $
Index: RTIG/Federation.cc
===================================================================
RCS file: /sources/certi/certi/RTIG/Federation.cc,v
retrieving revision 3.82
retrieving revision 3.83
diff -u -b -r3.82 -r3.83
--- RTIG/Federation.cc 26 Apr 2008 14:59:42 -0000 3.82
+++ RTIG/Federation.cc 27 Apr 2008 08:37:47 -0000 3.83
@@ -18,7 +18,7 @@
// along with this program ; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// $Id: Federation.cc,v 3.82 2008/04/26 14:59:42 erk Exp $
+// $Id: Federation.cc,v 3.83 2008/04/27 08:37:47 erk Exp $
// ----------------------------------------------------------------------------
#include <config.h>
@@ -227,17 +227,16 @@
FEDid = strdup(filename.c_str());
// Try to open to verify if file exists
- FILE *fftry ;
- if ( (fftry=fopen(FEDid,"r")) == NULL)
+ std::ifstream fedTry(FEDid);
+ if (!fedTry.is_open())
{
cout << "... failed : ";
G.Out(pdGendoc,"exit Federation::Federation on exception
CouldNotOpenFED");
throw CouldNotOpenFED("RTIG have found but cannot open FED file");
}
- else
- {
+ else {
cout << "... opened." << endl ;
- fclose(fftry) ;
+ fedTry.close();
}
int nbcar_filename = filename.length() ;
@@ -269,11 +268,11 @@
throw CouldNotOpenFED("Incorrect FED file name : nor .fed nor .xml
file");
}
- ifstream fdd(filename.c_str());
+ std::ifstream fedFile(filename.c_str());
- if (fdd.is_open())
+ if (fedFile.is_open())
{
- fdd.close();
+ fedFile.close();
if ( is_a_fed )
{
int err = fedparser::build(filename.c_str(), root, verbose);
@@ -2282,5 +2281,5 @@
}} // namespace certi/rtig
-// $Id: Federation.cc,v 3.82 2008/04/26 14:59:42 erk Exp $
+// $Id: Federation.cc,v 3.83 2008/04/27 08:37:47 erk Exp $
- [certi-cvs] certi RTIA/FederationManagement.cc RTIG/RTIG_pr...,
certi-cvs <=