Skip to content

Commit 3adbd23

Browse files
authored
Merge pull request #3439 from roystgnr/xdr_string_view
Xdr string_view comments
2 parents 70b0b6a + 47d25a7 commit 3adbd23

5 files changed

Lines changed: 64 additions & 63 deletions

File tree

include/utils/xdr_cxx.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <iosfwd>
4141
#include <vector>
4242
#include <string>
43+
#include <string_view>
4344

4445
const unsigned int xdr_MAX_STRING_LENGTH=256;
4546

@@ -128,7 +129,7 @@ class Xdr
128129
* Inputs or outputs a single value.
129130
*/
130131
template <typename T>
131-
void data(T & a, const char * comment="");
132+
void data(T & a, std::string_view comment="");
132133

133134
/**
134135
* Same, but provides an \p ostream like interface.

src/mesh/xdr_io.C

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ void XdrIO::write (const std::string & name)
222222

223223
// Write vector of elemset ids to file with comment
224224
std::string comment_string = "# elemset ids for elemset code " + std::to_string(elemset_code);
225-
io.data(elemset_id_vec, comment_string.c_str());
225+
io.data(elemset_id_vec, comment_string);
226226
}
227227
}
228228

@@ -421,7 +421,7 @@ XdrIO::write_serialized_connectivity (Xdr & io,
421421
legend += "p_level ";
422422
legend += "(n0 ... nN-1) ]";
423423
comment += legend;
424-
io.data (n_global_elem_at_level[0], comment.c_str());
424+
io.data (n_global_elem_at_level[0], comment);
425425
}
426426

427427
for (auto pid : make_range(this->n_processors()))
@@ -542,7 +542,7 @@ XdrIO::write_serialized_connectivity (Xdr & io,
542542
buf << "p_level ";
543543
buf << "(n0 ... nN-1) ]";
544544

545-
io.data (n_global_elem_at_level[level], buf.str().c_str());
545+
io.data (n_global_elem_at_level[level], buf.str());
546546
}
547547

548548
for (auto pid : make_range(this->n_processors()))
@@ -1161,7 +1161,7 @@ void XdrIO::write_serialized_bcs_helper (Xdr & io, const new_header_id_type n_bc
11611161
{
11621162
std::stringstream comment_string;
11631163
comment_string << "# number of " << bc_type << " boundary conditions";
1164-
io.data (n_bcs_out, comment_string.str().c_str());
1164+
io.data (n_bcs_out, comment_string.str());
11651165
}
11661166
n_bcs_out = 0;
11671167

src/systems/equation_systems_io.C

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ void EquationSystems::write(std::string_view name,
529529
// Note: There is no Xdr::data overload taking a "const
530530
// std::string &" so we need to make a copy.
531531
std::string copy = sys_name;
532-
io.data (copy, comment.c_str());
532+
io.data (copy, comment);
533533
}
534534

535535
// 4.)
@@ -541,7 +541,7 @@ void EquationSystems::write(std::string_view name,
541541
comment = "# Type, System No. ";
542542
comment += std::to_string(sys_num);
543543

544-
io.data (sys_type, comment.c_str());
544+
io.data (sys_type, comment);
545545
}
546546

547547
// 5.) - 9.)

src/systems/system_io.C

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ void System::write_header (Xdr & io,
13211321
comment += "\"";
13221322

13231323
unsigned int nv = this->n_vars();
1324-
io.data (nv, comment.c_str());
1324+
io.data (nv, comment);
13251325
}
13261326

13271327

@@ -1338,7 +1338,7 @@ void System::write_header (Xdr & io,
13381338
comment += "\"";
13391339

13401340
std::string var_name = this->variable_name(var);
1341-
io.data (var_name, comment.c_str());
1341+
io.data (var_name, comment);
13421342
}
13431343

13441344
// 6.1.) Variable subdomains
@@ -1353,7 +1353,7 @@ void System::write_header (Xdr & io,
13531353
const std::set<subdomain_id_type> & domains = this->variable(var).active_subdomains();
13541354
std::vector<subdomain_id_type> domain_array;
13551355
domain_array.assign(domains.begin(), domains.end());
1356-
io.data (domain_array, comment.c_str());
1356+
io.data (domain_array, comment);
13571357
}
13581358

13591359
// 7.)
@@ -1368,7 +1368,7 @@ void System::write_header (Xdr & io,
13681368
comment += "\"";
13691369

13701370
int order = static_cast<int>(this->variable_type(var).order);
1371-
io.data (order, comment.c_str());
1371+
io.data (order, comment);
13721372
}
13731373

13741374

@@ -1383,7 +1383,7 @@ void System::write_header (Xdr & io,
13831383
comment += "\"";
13841384

13851385
int rad_order = static_cast<int>(this->variable_type(var).radial_order);
1386-
io.data (rad_order, comment.c_str());
1386+
io.data (rad_order, comment);
13871387
}
13881388

13891389
#endif
@@ -1400,7 +1400,7 @@ void System::write_header (Xdr & io,
14001400

14011401
const FEType & type = this->variable_type(var);
14021402
int fam = static_cast<int>(type.family);
1403-
io.data (fam, comment.c_str());
1403+
io.data (fam, comment);
14041404

14051405
#ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
14061406

@@ -1411,7 +1411,7 @@ void System::write_header (Xdr & io,
14111411
comment += "\"";
14121412

14131413
int radial_fam = static_cast<int>(type.radial_family);
1414-
io.data (radial_fam, comment.c_str());
1414+
io.data (radial_fam, comment);
14151415

14161416
comment = "# Infinite Mapping Type, Variable \"";
14171417
comment += this->variable_name(var);
@@ -1420,7 +1420,7 @@ void System::write_header (Xdr & io,
14201420
comment += "\"";
14211421

14221422
int i_map = static_cast<int>(type.inf_map);
1423-
io.data (i_map, comment.c_str());
1423+
io.data (i_map, comment);
14241424
#endif
14251425
}
14261426
} // end of the variable loop
@@ -1437,7 +1437,7 @@ void System::write_header (Xdr & io,
14371437
comment += "\"";
14381438

14391439
unsigned int nvecs = write_additional_data ? this->n_vectors () : 0;
1440-
io.data (nvecs, comment.c_str());
1440+
io.data (nvecs, comment);
14411441
}
14421442

14431443
if (write_additional_data)
@@ -1451,13 +1451,13 @@ void System::write_header (Xdr & io,
14511451
comment = "# Name of " + dth_vector;
14521452
std::string vec_name = pr.first;
14531453

1454-
io.data (vec_name, comment.c_str());
1454+
io.data (vec_name, comment);
14551455
int vec_projection = _vector_projections.at(vec_name);
14561456
comment = "# Whether to do projections for " + dth_vector;
1457-
io.data (vec_projection, comment.c_str());
1457+
io.data (vec_projection, comment);
14581458
int vec_type = _vector_types.at(vec_name);
14591459
comment = "# Parallel type of " + dth_vector;
1460-
io.data (vec_type, comment.c_str());
1460+
io.data (vec_type, comment);
14611461
}
14621462
}
14631463
}
@@ -1580,7 +1580,7 @@ void System::write_parallel_data (Xdr & io,
15801580
comment += "\" Solution Vector";
15811581
}
15821582

1583-
io.data (io_buffer, comment.c_str());
1583+
io.data (io_buffer, comment);
15841584

15851585
// total_written_size += io_buffer.size();
15861586

@@ -1646,7 +1646,7 @@ void System::write_parallel_data (Xdr & io,
16461646
comment += "\"";
16471647
}
16481648

1649-
io.data (io_buffer, comment.c_str());
1649+
io.data (io_buffer, comment);
16501650

16511651
// total_written_size += io_buffer.size();
16521652
}

src/utils/xdr_cxx.C

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ void Xdr::do_write(std::vector<std::complex<T>> & a)
741741

742742

743743
template <typename T>
744-
void Xdr::data (T & a, const char * comment_in)
744+
void Xdr::data (T & a, std::string_view comment_in)
745745
{
746746
switch (mode)
747747
{
@@ -790,7 +790,7 @@ void Xdr::data (T & a, const char * comment_in)
790790

791791
// If there's a comment provided, write a tab character and
792792
// then the comment.
793-
if (std::string(comment_in) != "")
793+
if (comment_in != "")
794794
*out << "\t " << comment_in;
795795

796796
// Go to the next line.
@@ -1297,42 +1297,42 @@ void Xdr::comment (std::string & comment_in)
12971297

12981298

12991299
//
1300-
template LIBMESH_EXPORT void Xdr::data<int> (int &, const char *);
1301-
template LIBMESH_EXPORT void Xdr::data<unsigned int> (unsigned int &, const char *);
1302-
template LIBMESH_EXPORT void Xdr::data<unsigned short int> (unsigned short int &, const char *);
1303-
template LIBMESH_EXPORT void Xdr::data<short int> (short int &, const char *);
1304-
template LIBMESH_EXPORT void Xdr::data<unsigned long int> (unsigned long int &, const char *);
1305-
template LIBMESH_EXPORT void Xdr::data<unsigned long long> (unsigned long long &, const char *);
1306-
template LIBMESH_EXPORT void Xdr::data<long int> (long int &, const char *);
1307-
template LIBMESH_EXPORT void Xdr::data<long long> (long long &, const char *);
1308-
template LIBMESH_EXPORT void Xdr::data<char> (char &, const char *);
1309-
template LIBMESH_EXPORT void Xdr::data<signed char> (signed char &, const char *);
1310-
template LIBMESH_EXPORT void Xdr::data<unsigned char> (unsigned char &, const char *);
1311-
template LIBMESH_EXPORT void Xdr::data<float> (float &, const char *);
1312-
template LIBMESH_EXPORT void Xdr::data<double> (double &, const char *);
1313-
template LIBMESH_EXPORT void Xdr::data<long double> (long double &, const char *);
1314-
template LIBMESH_EXPORT void Xdr::data<std::complex<float>> (std::complex<float> &, const char *);
1315-
template LIBMESH_EXPORT void Xdr::data<std::complex<double>> (std::complex<double> &, const char *);
1316-
template LIBMESH_EXPORT void Xdr::data<std::complex<long double>> (std::complex<long double> &, const char *);
1317-
template LIBMESH_EXPORT void Xdr::data<std::string> (std::string &, const char *);
1318-
template LIBMESH_EXPORT void Xdr::data<std::vector<int>> (std::vector<int> &, const char *);
1319-
template LIBMESH_EXPORT void Xdr::data<std::vector<unsigned int>> (std::vector<unsigned int> &, const char *);
1320-
template LIBMESH_EXPORT void Xdr::data<std::vector<short int>> (std::vector<short int> &, const char *);
1321-
template LIBMESH_EXPORT void Xdr::data<std::vector<unsigned short int>> (std::vector<unsigned short int> &, const char *);
1322-
template LIBMESH_EXPORT void Xdr::data<std::vector<long int>> (std::vector<long int> &, const char *);
1323-
template LIBMESH_EXPORT void Xdr::data<std::vector<long long>> (std::vector<long long> &, const char *);
1324-
template LIBMESH_EXPORT void Xdr::data<std::vector<unsigned long int>> (std::vector<unsigned long int> &, const char *);
1325-
template LIBMESH_EXPORT void Xdr::data<std::vector<unsigned long long>> (std::vector<unsigned long long> &, const char *);
1326-
template LIBMESH_EXPORT void Xdr::data<std::vector<char>> (std::vector<char> &, const char *);
1327-
template LIBMESH_EXPORT void Xdr::data<std::vector<signed char>> (std::vector<signed char> &, const char *);
1328-
template LIBMESH_EXPORT void Xdr::data<std::vector<unsigned char>> (std::vector<unsigned char> &, const char *);
1329-
template LIBMESH_EXPORT void Xdr::data<std::vector<float>> (std::vector<float> &, const char *);
1330-
template LIBMESH_EXPORT void Xdr::data<std::vector<double>> (std::vector<double> &, const char *);
1331-
template LIBMESH_EXPORT void Xdr::data<std::vector<long double>> (std::vector<long double> &, const char *);
1332-
template LIBMESH_EXPORT void Xdr::data<std::vector<std::complex<float>>> (std::vector<std::complex<float>> &, const char *);
1333-
template LIBMESH_EXPORT void Xdr::data<std::vector<std::complex<double>>> (std::vector<std::complex<double>> &, const char *);
1334-
template LIBMESH_EXPORT void Xdr::data<std::vector<std::complex<long double>>> (std::vector<std::complex<long double>> &, const char *);
1335-
template LIBMESH_EXPORT void Xdr::data<std::vector<std::string>> (std::vector<std::string> &, const char *);
1300+
template LIBMESH_EXPORT void Xdr::data<int> (int &, std::string_view);
1301+
template LIBMESH_EXPORT void Xdr::data<unsigned int> (unsigned int &, std::string_view);
1302+
template LIBMESH_EXPORT void Xdr::data<unsigned short int> (unsigned short int &, std::string_view);
1303+
template LIBMESH_EXPORT void Xdr::data<short int> (short int &, std::string_view);
1304+
template LIBMESH_EXPORT void Xdr::data<unsigned long int> (unsigned long int &, std::string_view);
1305+
template LIBMESH_EXPORT void Xdr::data<unsigned long long> (unsigned long long &, std::string_view);
1306+
template LIBMESH_EXPORT void Xdr::data<long int> (long int &, std::string_view);
1307+
template LIBMESH_EXPORT void Xdr::data<long long> (long long &, std::string_view);
1308+
template LIBMESH_EXPORT void Xdr::data<char> (char &, std::string_view);
1309+
template LIBMESH_EXPORT void Xdr::data<signed char> (signed char &, std::string_view);
1310+
template LIBMESH_EXPORT void Xdr::data<unsigned char> (unsigned char &, std::string_view);
1311+
template LIBMESH_EXPORT void Xdr::data<float> (float &, std::string_view);
1312+
template LIBMESH_EXPORT void Xdr::data<double> (double &, std::string_view);
1313+
template LIBMESH_EXPORT void Xdr::data<long double> (long double &, std::string_view);
1314+
template LIBMESH_EXPORT void Xdr::data<std::complex<float>> (std::complex<float> &, std::string_view);
1315+
template LIBMESH_EXPORT void Xdr::data<std::complex<double>> (std::complex<double> &, std::string_view);
1316+
template LIBMESH_EXPORT void Xdr::data<std::complex<long double>> (std::complex<long double> &, std::string_view);
1317+
template LIBMESH_EXPORT void Xdr::data<std::string> (std::string &, std::string_view);
1318+
template LIBMESH_EXPORT void Xdr::data<std::vector<int>> (std::vector<int> &, std::string_view);
1319+
template LIBMESH_EXPORT void Xdr::data<std::vector<unsigned int>> (std::vector<unsigned int> &, std::string_view);
1320+
template LIBMESH_EXPORT void Xdr::data<std::vector<short int>> (std::vector<short int> &, std::string_view);
1321+
template LIBMESH_EXPORT void Xdr::data<std::vector<unsigned short int>> (std::vector<unsigned short int> &, std::string_view);
1322+
template LIBMESH_EXPORT void Xdr::data<std::vector<long int>> (std::vector<long int> &, std::string_view);
1323+
template LIBMESH_EXPORT void Xdr::data<std::vector<long long>> (std::vector<long long> &, std::string_view);
1324+
template LIBMESH_EXPORT void Xdr::data<std::vector<unsigned long int>> (std::vector<unsigned long int> &, std::string_view);
1325+
template LIBMESH_EXPORT void Xdr::data<std::vector<unsigned long long>> (std::vector<unsigned long long> &, std::string_view);
1326+
template LIBMESH_EXPORT void Xdr::data<std::vector<char>> (std::vector<char> &, std::string_view);
1327+
template LIBMESH_EXPORT void Xdr::data<std::vector<signed char>> (std::vector<signed char> &, std::string_view);
1328+
template LIBMESH_EXPORT void Xdr::data<std::vector<unsigned char>> (std::vector<unsigned char> &, std::string_view);
1329+
template LIBMESH_EXPORT void Xdr::data<std::vector<float>> (std::vector<float> &, std::string_view);
1330+
template LIBMESH_EXPORT void Xdr::data<std::vector<double>> (std::vector<double> &, std::string_view);
1331+
template LIBMESH_EXPORT void Xdr::data<std::vector<long double>> (std::vector<long double> &, std::string_view);
1332+
template LIBMESH_EXPORT void Xdr::data<std::vector<std::complex<float>>> (std::vector<std::complex<float>> &, std::string_view);
1333+
template LIBMESH_EXPORT void Xdr::data<std::vector<std::complex<double>>> (std::vector<std::complex<double>> &, std::string_view);
1334+
template LIBMESH_EXPORT void Xdr::data<std::vector<std::complex<long double>>> (std::vector<std::complex<long double>> &, std::string_view);
1335+
template LIBMESH_EXPORT void Xdr::data<std::vector<std::string>> (std::vector<std::string> &, std::string_view);
13361336
template LIBMESH_EXPORT void Xdr::data_stream<unsigned char> (unsigned char * val, const unsigned int len, const unsigned int line_break);
13371337
template LIBMESH_EXPORT void Xdr::data_stream<short int> (short int * val, const unsigned int len, const unsigned int line_break);
13381338
template LIBMESH_EXPORT void Xdr::data_stream<int> (int * val, const unsigned int len, const unsigned int line_break);
@@ -1343,10 +1343,10 @@ template LIBMESH_EXPORT void Xdr::data_stream<unsigned long int> (unsigned long
13431343
template LIBMESH_EXPORT void Xdr::data_stream<unsigned long long> (unsigned long long * val, const unsigned int len, const unsigned int line_break);
13441344

13451345
#ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
1346-
template LIBMESH_EXPORT void Xdr::data<Real> (Real &, const char *);
1347-
template LIBMESH_EXPORT void Xdr::data<std::complex<Real>> (std::complex<Real> &, const char *);
1348-
template LIBMESH_EXPORT void Xdr::data<std::vector<Real>> (std::vector<Real> &, const char *);
1349-
template LIBMESH_EXPORT void Xdr::data<std::vector<std::complex<Real>>> (std::vector<std::complex<Real>> &, const char *);
1346+
template LIBMESH_EXPORT void Xdr::data<Real> (Real &, std::string_view);
1347+
template LIBMESH_EXPORT void Xdr::data<std::complex<Real>> (std::complex<Real> &, std::string_view);
1348+
template LIBMESH_EXPORT void Xdr::data<std::vector<Real>> (std::vector<Real> &, std::string_view);
1349+
template LIBMESH_EXPORT void Xdr::data<std::vector<std::complex<Real>>> (std::vector<std::complex<Real>> &, std::string_view);
13501350
#endif
13511351

13521352
} // namespace libMesh

0 commit comments

Comments
 (0)