Change std::endl to linefeed as appropriate. (#773)

* Fix endl issue in variable server JSON generation. Ref #766

* Change std::endl to line feed as appropraite. #766

* Change std::endl to line feed in MemoryManager as appropriate. #766

* Change std::endl to linefeed as appropriate. #766

* Change std::endl to line feed as appropriate in JSONVariableServer. #766

* Change std::endl to line feed as appropriate in still more files. #766
This commit is contained in:
jmpenn
2019-05-13 16:05:01 -05:00
committed by GitHub
parent 3187dd9012
commit 3f35388b49
11 changed files with 68 additions and 67 deletions

View File

@ -116,7 +116,7 @@ void Trick::ClassicCheckPointAgent::write_decl(std::ostream& chkpnt_os, ALLOC_IN
if ( info->num_index == 0 ) { if ( info->num_index == 0 ) {
chkpnt_os << type_spec << " " << info->name << ";" << std::endl; chkpnt_os << type_spec << " " << info->name << ";\n";
} else if ((info->num_index > 0) && (info->num_index <= TRICK_MAX_INDEX)) { } else if ((info->num_index > 0) && (info->num_index <= TRICK_MAX_INDEX)) {
int ii; int ii;
@ -978,7 +978,7 @@ void Trick::ClassicCheckPointAgent::write_rvalue( std::ostream& chkpnt_os, void*
array_len = attr->index[curr_dim].size ; array_len = attr->index[curr_dim].size ;
chkpnt_os << std::endl; chkpnt_os << "\n";
for (ii=0 ; ii < curr_dim+1 ; ii++) { for (ii=0 ; ii < curr_dim+1 ; ii++) {
chkpnt_os << " "; chkpnt_os << " ";
@ -993,7 +993,7 @@ void Trick::ClassicCheckPointAgent::write_rvalue( std::ostream& chkpnt_os, void*
// Conditionally line-break and indent. // Conditionally line-break and indent.
if (( (ii+1) % array_elements_per_line[attr->type]) == 0 ) { if (( (ii+1) % array_elements_per_line[attr->type]) == 0 ) {
// Line-break. // Line-break.
chkpnt_os << std::endl; chkpnt_os << "\n";
// Indent. // Indent.
for (jj=0 ; jj < curr_dim+1 ; jj++) { for (jj=0 ; jj < curr_dim+1 ; jj++) {
chkpnt_os << " "; chkpnt_os << " ";
@ -1011,7 +1011,7 @@ void Trick::ClassicCheckPointAgent::write_rvalue( std::ostream& chkpnt_os, void*
int ii; int ii;
chkpnt_os << std::endl; chkpnt_os << "\n";
for (ii=0 ; ii < curr_dim+1 ; ii++) { for (ii=0 ; ii < curr_dim+1 ; ii++) {
chkpnt_os << " "; chkpnt_os << " ";
} }
@ -1024,7 +1024,7 @@ void Trick::ClassicCheckPointAgent::write_rvalue( std::ostream& chkpnt_os, void*
write_rvalue( chkpnt_os, address, attr, curr_dim + 1, offset * attr->index[curr_dim].size + ii); write_rvalue( chkpnt_os, address, attr, curr_dim + 1, offset * attr->index[curr_dim].size + ii);
} }
chkpnt_os << std::endl; chkpnt_os << "\n";
for (ii=0 ; ii < curr_dim+1 ; ii++) { for (ii=0 ; ii < curr_dim+1 ; ii++) {
chkpnt_os << " " ; chkpnt_os << " " ;

View File

@ -82,7 +82,7 @@ bool ClassicChkPtAgent:: writeDeclaration( std::ostream& out_s, std::string name
bool errorCondition = false; bool errorCondition = false;
if (dataType != NULL) { if (dataType != NULL) {
out_s << dataType->makeDeclaration(name, true); out_s << dataType->makeDeclaration(name, true);
out_s << ";" << std::endl; out_s << ";\n";
} else { } else {
errorCondition = true; errorCondition = true;
} }
@ -98,12 +98,12 @@ bool ClassicChkPtAgent::writeVariable( std::ostream& out_s, MemMgr* memMgr, void
std::stringstream rightHandSide; std::stringstream rightHandSide;
dataType->printValue( rightHandSide, address ); dataType->printValue( rightHandSide, address );
writeAssignment( out_s, rightHandSide.str() ); writeAssignment( out_s, rightHandSide.str() );
out_s << std::endl; out_s << "\n";
} else if ( typeClass == TypeClass::POINTER ) { } else if ( typeClass == TypeClass::POINTER ) {
std::stringstream pointerName; std::stringstream pointerName;
errorCondition |= writePointerValue( pointerName, memMgr, address, (const PointerDataType*) dataType); errorCondition |= writePointerValue( pointerName, memMgr, address, (const PointerDataType*) dataType);
writeAssignment(out_s, pointerName.str()); writeAssignment(out_s, pointerName.str());
out_s << std::endl; out_s << "\n";
} else if ( typeClass == TypeClass::COMPOSITE ) { } else if ( typeClass == TypeClass::COMPOSITE ) {
errorCondition |= writeCompositeAssignments( out_s, memMgr, address, (const CompositeDataType*)dataType); errorCondition |= writeCompositeAssignments( out_s, memMgr, address, (const CompositeDataType*)dataType);
} else if ( typeClass == TypeClass::ARRAY ) { } else if ( typeClass == TypeClass::ARRAY ) {
@ -167,7 +167,7 @@ bool ClassicChkPtAgent:: writeArrayAssignments( std::ostream& out_s, MemMgr* mem
} }
rightHandSide << "}"; rightHandSide << "}";
writeAssignment( out_s, rightHandSide.str() ); writeAssignment( out_s, rightHandSide.str() );
out_s << std::endl; out_s << "\n";
} else { } else {
for (int ii=0; ii < elementCount; ii++) { for (int ii=0; ii < elementCount; ii++) {
void * elementAddress = (char*) address + (ii * elementTypeSize ); void * elementAddress = (char*) address + (ii * elementTypeSize );
@ -200,7 +200,7 @@ bool ClassicChkPtAgent::writeCompositeAssignments( std::ostream& out_s, MemMgr*
std::stringstream rightHandSide; std::stringstream rightHandSide;
structMember->printValue( rightHandSide, address ); structMember->printValue( rightHandSide, address );
writeAssignment( out_s, rightHandSide.str() ); writeAssignment( out_s, rightHandSide.str() );
out_s << std::endl; out_s << "\n";
} else { } else {
char* memberAddress; char* memberAddress;
const DataType* memberDataType; const DataType* memberDataType;

View File

@ -216,12 +216,12 @@ void CompositeDataType::printValue(std::ostream &s, void *address) const {
std::string CompositeDataType::toString() const { std::string CompositeDataType::toString() const {
std::stringstream ss; std::stringstream ss;
int memberCount = memberList.size() ; int memberCount = memberList.size() ;
ss << "composite {" << std::endl; ss << "composite {\n";
for (int ii=0; ii < memberCount ; ii++) { for (int ii=0; ii < memberCount ; ii++) {
ss << memberList[ii]->toString(); ss << memberList[ii]->toString();
ss << ";" << std::endl; ss << ";\n";
} }
ss << "}" << std::endl; ss << "}\n";
return ss.str(); return ss.str();
} }

View File

@ -161,14 +161,14 @@ void EnumDataType::printValue(std::ostream &s, void *address) const {
std::string EnumDataType::toString() const { std::string EnumDataType::toString() const {
std::stringstream ss; std::stringstream ss;
int enum_count = enum_list.size() ; int enum_count = enum_list.size() ;
ss << "enum {" << std::endl; ss << "enum {\n";
for (int ii=0; ii < enum_count ; ii++) { for (int ii=0; ii < enum_count ; ii++) {
if (ii) { if (ii) {
ss << "," << std::endl; ss << ",\n";
} }
ss << enum_list[ii]->toString(); ss << enum_list[ii]->toString();
} }
ss << "}" << std::endl; ss << "}\n";
return ss.str(); return ss.str();
} }

View File

@ -183,10 +183,10 @@ int Trick::JSONVariableServer::restart() {
} }
void Trick::JSONVariableServer::dump( std::ostream & oss ) { void Trick::JSONVariableServer::dump( std::ostream & oss ) {
oss << "Trick::JSONVariableServer (" << name << ")" << std::endl ; oss << "Trick::JSONVariableServer (" << name << ")\n";
oss << " enabled = " << enabled << std::endl ; oss << " enabled = " << enabled << "\n";
oss << " source_address = " << source_address << std::endl ; oss << " source_address = " << source_address << "\n";
oss << " port = " << port << std::endl ; oss << " port = " << port << "\n";
oss << " user_port_requested = " << user_port_requested << std::endl ; oss << " user_port_requested = " << user_port_requested << std::endl ;
Trick::ThreadBase::dump(oss) ; Trick::ThreadBase::dump(oss) ;
} }

View File

@ -2,30 +2,30 @@
#include "trick/MemoryManager.hh" #include "trick/MemoryManager.hh"
void Trick::MemoryManager::write_JSON_alloc_info(std::ostream& s, ALLOC_INFO *alloc_info) { void Trick::MemoryManager::write_JSON_alloc_info(std::ostream& s, ALLOC_INFO *alloc_info) {
s << "{" << std::endl; s << "{\n";
if (!alloc_info->name) { if (!alloc_info->name) {
s << "\"name\":null," << std::endl; s << "\"name\":null,\n";
} else { } else {
s << "\"name\":\"" << alloc_info->name << "\"," << std::endl; s << "\"name\":\"" << alloc_info->name << "\",\n";
} }
s << "\"start\":\"" << alloc_info->start << "\"," << std::endl; s << "\"start\":\"" << alloc_info->start << "\",\n";
s << "\"end\":\"" << alloc_info->end << "\"," << std::endl; s << "\"end\":\"" << alloc_info->end << "\",\n";
s << "\"num\":\"" << alloc_info->num << "\"," << std::endl; s << "\"num\":\"" << alloc_info->num << "\",\n";
s << "\"size\":\"" << alloc_info->size << "\"," << std::endl; s << "\"size\":\"" << alloc_info->size << "\",\n";
s << "\"type\":\"" << trickTypeCharString(alloc_info->type, alloc_info->user_type_name) << "\"," << std::endl; s << "\"type\":\"" << trickTypeCharString(alloc_info->type, alloc_info->user_type_name) << "\",\n";
s << "\"stcl\":" ; s << "\"stcl\":" ;
if (alloc_info->stcl == TRICK_LOCAL) { if (alloc_info->stcl == TRICK_LOCAL) {
s << "\"TRICK_LOCAL\"," << std::endl; s << "\"TRICK_LOCAL\",\n";
} }
if (alloc_info->stcl == TRICK_EXTERN) { if (alloc_info->stcl == TRICK_EXTERN) {
s << "\"TRICK_EXTERN\"," << std::endl; s << "\"TRICK_EXTERN\",\n";
} }
s << "\"language\":"; s << "\"language\":";
if (alloc_info->language == Language_C ) { if (alloc_info->language == Language_C ) {
s << "\"Language_C\"," << std::endl; s << "\"Language_C\",\n";
} }
if (alloc_info->language == Language_CPP) { if (alloc_info->language == Language_CPP) {
s << "\"Language_CPP\"," << std::endl; s << "\"Language_CPP\",\n";
} }
s << "\"index\": [" ; s << "\"index\": [" ;
for (int ii=0; ii<alloc_info->num_index; ii++) { for (int ii=0; ii<alloc_info->num_index; ii++) {
@ -34,7 +34,7 @@ void Trick::MemoryManager::write_JSON_alloc_info(std::ostream& s, ALLOC_INFO *al
} }
s << alloc_info->index[ii] ; s << alloc_info->index[ii] ;
} }
s << "]}" ; s << "]}" << std::endl;
} }
@ -44,18 +44,18 @@ void Trick::MemoryManager::write_JSON_alloc_list(std::ostream& s, int chunk_star
ALLOC_INFO* alloc_info; ALLOC_INFO* alloc_info;
int size = alloc_info_map.size(); int size = alloc_info_map.size();
s << "{" << std::endl; s << "{\n";
s << "\"alloc_total\":" << size << "," << std::endl; s << "\"alloc_total\":" << size << ",\n";
s << "\"chunk_size\":" << chunk_size << "," << std::endl; s << "\"chunk_size\":" << chunk_size << ",\n";
s << "\"chunk_start\":" << chunk_start << "," << std::endl; s << "\"chunk_start\":" << chunk_start << ",\n";
s << "\"alloc_list\":[" << std::endl; s << "\"alloc_list\":[\n";
pos = alloc_info_map.begin(); pos = alloc_info_map.begin();
std::advance(pos, chunk_start); std::advance(pos, chunk_start);
for (int count = 0; count < chunk_size && pos!=alloc_info_map.end() ; pos++, count++) { for (int count = 0; count < chunk_size && pos!=alloc_info_map.end() ; pos++, count++) {
alloc_info = pos->second; alloc_info = pos->second;
if (count != 0) { if (count != 0) {
s << "," << std::endl; s << ",\n";
} }
write_JSON_alloc_info(s, alloc_info); write_JSON_alloc_info(s, alloc_info);
} }

View File

@ -91,7 +91,7 @@ void * Trick::MessageTCDeviceListenThread::thread_body() {
} }
void Trick::MessageTCDeviceListenThread::dump( std::ostream & oss ) { void Trick::MessageTCDeviceListenThread::dump( std::ostream & oss ) {
oss << "Trick::MessageTCDeviceListenThread (" << name << ")" << std::endl ; oss << "Trick::MessageTCDeviceListenThread (" << name << ")\n";
oss << " port = " << get_port() << std::endl ; oss << " port = " << get_port() << std::endl ;
Trick::ThreadBase::dump(oss) ; Trick::ThreadBase::dump(oss) ;
} }

View File

@ -26,15 +26,15 @@ void Trick::MonteCarlo::dryrun() {
of.open(std::string(buffer_stream.str() + "/monte_input").c_str()) ; of.open(std::string(buffer_stream.str() + "/monte_input").c_str()) ;
of << "# This run can be executed in stand alone (non-Monte Carlo) mode by running\n" of << "# This run can be executed in stand alone (non-Monte Carlo) mode by running\n"
"# the S_main executable with this file specified as the input file.\n\n" ; "# the S_main executable with this file specified as the input file.\n\n" ;
of << "if (sys.version_info > (3, 0)):" << std::endl ; of << "if (sys.version_info > (3, 0)):\n";
of << " exec(open(\"" << command_line_args_get_input_file() << "\").read())" << std::endl ; of << " exec(open(\"" << command_line_args_get_input_file() << "\").read())\n";
of << "else:" << std::endl ; of << "else:\n";
of << " execfile(\"" << command_line_args_get_input_file() << "\")" << std::endl << std::endl ; of << " execfile(\"" << command_line_args_get_input_file() << "\")\n\n";
of << "trick.mc_set_enabled(0)" << std::endl ; of << "trick.mc_set_enabled(0)\n";
for (std::vector<std::string>::size_type j = 0; j < curr_run->variables.size(); ++j) { for (std::vector<std::string>::size_type j = 0; j < curr_run->variables.size(); ++j) {
of << curr_run->variables[j] << std::endl ; of << curr_run->variables[j] << "\n";
} }
of << "trick.set_output_dir(\"" << buffer_stream.str() << "\")" << std::endl ; of << "trick.set_output_dir(\"" << buffer_stream.str() << "\")\n";
of << "trick.mc_set_current_run(" << curr_run->id << ")" << std::endl ; of << "trick.mc_set_current_run(" << curr_run->id << ")" << std::endl ;
of.close() ; of.close() ;
} }

View File

@ -322,10 +322,10 @@ void * Trick::ThreadBase::thread_helper( void * context ) {
} }
void Trick::ThreadBase::dump( std::ostream & oss ) { void Trick::ThreadBase::dump( std::ostream & oss ) {
oss << " from Trick::ThreadBase" << std::endl ; oss << " from Trick::ThreadBase\n";
oss << " pthread_id = " << pthread_id << std::endl ; oss << " pthread_id = " << pthread_id << "\n";
oss << " process_id = " << pid << std::endl ; oss << " process_id = " << pid << "\n";
oss << " rt_priority = " << rt_priority << std::endl ; oss << " rt_priority = " << rt_priority << "\n";
#if __linux #if __linux
oss << " cpus = " ; oss << " cpus = " ;
bool first_print = true ; bool first_print = true ;

View File

@ -21,17 +21,17 @@ Trick::VariableServer::~VariableServer() {
std::ostream& Trick::operator<< (std::ostream& s, Trick::VariableServer& vs) { std::ostream& Trick::operator<< (std::ostream& s, Trick::VariableServer& vs) {
std::map < pthread_t , VariableServerThread * >::iterator it ; std::map < pthread_t , VariableServerThread * >::iterator it ;
s << "{\"variable_server_connections\":[" << std::endl; s << "{\"variable_server_connections\":[\n";
int count = 0; int count = 0;
int n_connections = (int)vs.var_server_threads.size(); int n_connections = (int)vs.var_server_threads.size();
for ( it = vs.var_server_threads.begin() ; it != vs.var_server_threads.end() ; it++ ) { for ( it = vs.var_server_threads.begin() ; it != vs.var_server_threads.end() ; it++ ) {
s << "{" << std::endl; s << "{\n";
s << *(*it).second; s << *(*it).second;
s << "}"; s << "}";
if ((n_connections-count)>1) { if ((n_connections-count)>1) {
s << "," ; s << "," ;
} }
s << std::endl; s << "\n";
count ++; count ++;
} }
s << "]}" << std::endl; s << "]}" << std::endl;

View File

@ -67,33 +67,34 @@ Trick::VariableServerThread::~VariableServerThread() {
std::ostream& Trick::operator<< (std::ostream& s, Trick::VariableServerThread& vst) { std::ostream& Trick::operator<< (std::ostream& s, Trick::VariableServerThread& vst) {
// Write a JSON representation of a Trick::VariableServerThread to an ostream.
std::vector <Trick::VariableReference *>::iterator it; std::vector <Trick::VariableReference *>::iterator it;
struct sockaddr_in otherside; struct sockaddr_in otherside;
socklen_t len = (socklen_t)sizeof(otherside); socklen_t len = (socklen_t)sizeof(otherside);
s << " \"connection\":{" << std::endl; s << " \"connection\":{\n";
s << " \"client_tag\":\"" << vst.connection.client_tag << "\"," << std::endl; s << " \"client_tag\":\"" << vst.connection.client_tag << "\",\n";
int err = getpeername(vst.connection.socket, (struct sockaddr*)&otherside, &len); int err = getpeername(vst.connection.socket, (struct sockaddr*)&otherside, &len);
if (err == 0) { if (err == 0) {
s << " \"client_IP_address\":\"" << inet_ntoa(otherside.sin_addr) << "\"," << std::endl; s << " \"client_IP_address\":\"" << inet_ntoa(otherside.sin_addr) << "\",\n";
s << " \"client_port\":\"" << ntohs(otherside.sin_port) << "\"," << std::endl; s << " \"client_port\":\"" << ntohs(otherside.sin_port) << "\",\n";
} else { } else {
s << " \"client_IP_address\":\"unknown\"," << std::endl; s << " \"client_IP_address\":\"unknown\",\n";
s << " \"client_port\":\"unknown\"," << std::endl; s << " \"client_port\":\"unknown\",";
} }
if (vst.binary_data) { if (vst.binary_data) {
s << " \"format\":\"BINARY\","; s << " \"format\":\"BINARY\",\n";
} else { } else {
s << " \"format\":\"ASCII\","; s << " \"format\":\"ASCII\",\n";
} }
s << std::endl; s << " \"update_rate\":" << vst.update_rate << ",\n";
s << " \"update_rate\":" << vst.update_rate << "," << std::endl;
s << " \"variables\":[" << std::endl; s << " \"variables\":[\n";
int n_vars = (int)vst.vars.size(); int n_vars = (int)vst.vars.size();
for (int i=0 ; i<n_vars ; i++) { for (int i=0 ; i<n_vars ; i++) {
@ -101,9 +102,9 @@ std::ostream& Trick::operator<< (std::ostream& s, Trick::VariableServerThread& v
if ((n_vars-i)>1) { if ((n_vars-i)>1) {
s << "," ; s << "," ;
} }
s << std::endl; s << "\n";
} }
s << " ]" << std::endl; s << " ]\n";
s << " }" << std::endl; s << " }" << std::endl;
return s; return s;
} }