mercredi 1 février 2023

Generate C++ string with space behind such that space is automatically adjusted

I am trying to create a text generator which shall generate following output:

localparam  OR_CHANNEL_DATA_WIDTH               = 2;
localparam  RQ_CHANNEL_DATA_WIDTH               = 18;
localparam  RSP_CHANNEL_DATA_WIDTH              = 8;
localparam  VIN_CHANNEL_DATA_WIDTH              = 43;
localparam  VOUT_CHANNEL_DATA_WIDTH             = 123;

I used std::stringstream to build the stream:

std::stringstream ss;
ss << "localparam OR_CHANNEL_DATA_WIDTH" std::right << std::setw(80) << " = " << Sth::get() << ";\n";
ss << "localparam RQ_CHANNEL_DATA_WIDTH" std::right << std::setw(80) << " = " << Sth::get() << ";\n";
ss << "localparam RSP_CHANNEL_DATA_WIDTH" std::right << std::setw(80) << " = " << Sth::get() << ";\n";

Sth::get() will return number. There are many such lines that needs to be generated. But the text in the middle is not fixed. How can I achieve the above output

Aucun commentaire:

Enregistrer un commentaire