@@ -158,7 +158,7 @@ int Graph<T>::writeToMTXFile(const std::string &workingDir,
158158 // Check if the adjacency matrix is symmetric, i.e., if all the edges are
159159 // undirected
160160 bool symmetric = !std::any_of (edgeSet.begin (), edgeSet.end (), [](auto edge) {
161- return ( edge->isDirected ().has_value () && edge-> isDirected (). value () );
161+ return edge->isDirected ().value_or ( false );
162162 });
163163 // Write in the header whether the adj matrix is symmetric or not
164164 if (symmetric) {
@@ -180,7 +180,7 @@ int Graph<T>::writeToMTXFile(const std::string &workingDir,
180180 std::string line;
181181 line += edgeIt->getNodePair ().first ->getUserId () + delimitier;
182182 line += edgeIt->getNodePair ().second ->getUserId () + delimitier;
183- if (edgeIt->isWeighted ().has_value () && edgeIt-> isWeighted (). value ( )) {
183+ if (edgeIt->isWeighted ().value_or ( false )) {
184184 line += std::to_string (edgeIt->isWeighted ().value ()) + ' \n ' ;
185185 } else {
186186 line += std::to_string (1 .) + ' \n ' ;
@@ -261,10 +261,10 @@ int Graph<T>::writeToBinary(const std::string &filepath, bool writeNodeFeatures,
261261 writeBinaryString (out, edge->getNodePair ().second ->getUserId ());
262262
263263 uint8_t edgeFlags = 0 ;
264- if (edge->isDirected ().has_value () && edge-> isDirected (). value ( )) {
264+ if (edge->isDirected ().value_or ( false )) {
265265 edgeFlags |= 0x01 ;
266266 }
267- if (edge->isWeighted ().has_value () && edge-> isWeighted (). value ( )) {
267+ if (edge->isWeighted ().value_or ( false )) {
268268 edgeFlags |= 0x02 ;
269269 }
270270 out.write (reinterpret_cast <const char *>(&edgeFlags), sizeof (edgeFlags));
@@ -313,7 +313,7 @@ int Graph<T>::writeToDot(const std::string &workingDir,
313313
314314 for (auto const &edgePtr : edgeSet) {
315315 std::string edgeLine = " " ;
316- if (edgePtr->isDirected ().has_value () && edgePtr-> isDirected (). value ( )) {
316+ if (edgePtr->isDirected ().value_or ( false )) {
317317 auto directedPtr =
318318 std::static_pointer_cast<const DirectedEdge<T>>(edgePtr);
319319 edgeLine += ' \t ' + directedPtr->getFrom ().getUserId () + ' ' ;
@@ -324,7 +324,7 @@ int Graph<T>::writeToDot(const std::string &workingDir,
324324 edgeLine += linkSymbol + ' ' ;
325325 edgeLine += edgePtr->getNodePair ().second ->getUserId ();
326326 }
327- if (edgePtr->isWeighted ().has_value () && edgePtr-> isWeighted (). value ( )) {
327+ if (edgePtr->isWeighted ().value_or ( false )) {
328328 // Weights in dot files must be integers
329329 edgeLine += " [weight=" +
330330 std::to_string (static_cast <int >(
@@ -349,10 +349,7 @@ void Graph<T>::writeGraphToStream(std::ostream &oGraph, std::ostream &oNodeFeat,
349349 for (const auto &edge : edgeSet) {
350350 oGraph << edge->getUserId () << sep << edge->getNodePair ().first ->getUserId ()
351351 << sep << edge->getNodePair ().second ->getUserId () << sep
352- << ((edge->isDirected ().has_value () && edge->isDirected ().value ())
353- ? 1
354- : 0 )
355- << std::endl;
352+ << (edge->isDirected ().value_or (false ) ? 1 : 0 ) << std::endl;
356353 }
357354
358355 if (writeNodeFeat) {
@@ -364,16 +361,13 @@ void Graph<T>::writeGraphToStream(std::ostream &oGraph, std::ostream &oNodeFeat,
364361
365362 if (writeEdgeWeight) {
366363 for (const auto &edge : edgeSet) {
367- oEdgeWeight
368- << edge->getUserId () << sep
369- << (edge->isWeighted ().has_value () && edge->isWeighted ().value ()
370- ? (std::dynamic_pointer_cast<const Weighted>(edge))
371- ->getWeight ()
372- : 0.0 )
373- << sep
374- << (edge->isWeighted ().has_value () && edge->isWeighted ().value () ? 1
375- : 0 )
376- << std::endl;
364+ oEdgeWeight << edge->getUserId () << sep
365+ << (edge->isWeighted ().value_or (false )
366+ ? (std::dynamic_pointer_cast<const Weighted>(edge))
367+ ->getWeight ()
368+ : 0.0 )
369+ << sep << (edge->isWeighted ().value_or (false ) ? 1 : 0 )
370+ << std::endl;
377371 }
378372 }
379373}
@@ -395,27 +389,19 @@ std::ostream &operator<<(std::ostream &os, const Graph<T> &graph) {
395389 if (!(*it)->isDirected ().has_value () && !(*it)->isWeighted ().has_value ()) {
396390 // Edge Case
397391 os << **it << " \n " ;
398- } else if (((*it)->isDirected ().has_value () &&
399- (*it)->isDirected ().value ()) &&
400- ((*it)->isWeighted ().has_value () &&
401- (*it)->isWeighted ().value ())) {
392+ } else if ((*it)->isDirected ().value_or (false ) &&
393+ (*it)->isWeighted ().value_or (false )) {
402394 os << *std::static_pointer_cast<const DirectedWeightedEdge<T>>(*it)
403395 << " \n " ;
404- } else if (((*it)->isDirected ().has_value () &&
405- (*it)->isDirected ().value ()) &&
406- !((*it)->isWeighted ().has_value () &&
407- (*it)->isWeighted ().value ())) {
396+ } else if ((*it)->isDirected ().value_or (false ) &&
397+ !((*it)->isWeighted ().value_or (false ))) {
408398 os << *std::static_pointer_cast<const DirectedEdge<T>>(*it) << " \n " ;
409- } else if (!((*it)->isDirected ().has_value () &&
410- (*it)->isDirected ().value ()) &&
411- ((*it)->isWeighted ().has_value () &&
412- (*it)->isWeighted ().value ())) {
399+ } else if (!((*it)->isDirected ().value_or (false )) &&
400+ (*it)->isWeighted ().value_or (false )) {
413401 os << *std::static_pointer_cast<const UndirectedWeightedEdge<T>>(*it)
414402 << " \n " ;
415- } else if (!((*it)->isDirected ().has_value () &&
416- (*it)->isDirected ().value ()) &&
417- !((*it)->isWeighted ().has_value () &&
418- (*it)->isWeighted ().value ())) {
403+ } else if (!((*it)->isDirected ().value_or (false )) &&
404+ !((*it)->isWeighted ().value_or (false ))) {
419405 os << *std::static_pointer_cast<const UndirectedEdge<T>>(*it) << " \n " ;
420406 } else {
421407 os << *it << " \n " ;
0 commit comments