Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle long serialization mechanism in fmt 5 ? #859

Closed
jcelerier opened this issue Sep 15, 2018 · 2 comments
Closed

How to handle long serialization mechanism in fmt 5 ? #859

jcelerier opened this issue Sep 15, 2018 · 2 comments

Comments

@jcelerier
Copy link
Contributor

I have a bunch of code with 4.x which uses a single fmt::MemoryWriter to write a lot of things - the things being written can change according to runtime conditions, e.g.

 void debug_stuff(fmt::MemoryWriter& wr, some_stuff, some_other_stuff, ...) { 
   if(whatever)
   {
      wr << some_stuff << some_other_stuff;
   }
   else
   {
     wr << "boop boop" << some_stuff << "beep beep";
     debug_other_stuff(wr, other_stuff);
   }
 }

how to handle these cases with fmt 5.x ?

@jcelerier
Copy link
Contributor Author

jcelerier commented Sep 15, 2018

e.g. here's an actual example code I had:

fmt::MemoryWriter& operator<<(fmt::MemoryWriter& w, const ossia::net::node_base& n) {
  auto parent = n.get_parent();
  while (parent != nullptr)
  {
    w << '\t';
    parent = parent->get_parent();
  }
  w << n.get_name();
  if (auto addr = n.get_parameter())
  {
    w << " : " << value_to_pretty_string(addr->value()) << ", AccessMode("
      << addr->get_access() << ")"
      << ", BoundingMode(" << addr->get_bounding() << ")"
      << ", Domain(" << addr->get_domain() << ")"
      << ", Unit(" << ossia::get_pretty_unit_text(addr->get_unit()) << ")";
  }
  return w;
}

@vitaut
Copy link
Contributor

vitaut commented Sep 16, 2018

You can call format_to repeatedly, e.g.

void debug_stuff(fmt::memory_buffer& wr, int some_stuff, int some_other_stuff) { 
   if (whatever)
   {
     format_to(wr, "{}{}", some_stuff, some_other_stuff);
   }
   else
   {
     format_to(wr, "boop boop{}beep beep", some_stuff);
     debug_other_stuff(wr, some_other_stuff);
   }
 }

@vitaut vitaut closed this as completed Sep 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants