Tag Archives: C++

Convert std::string to FString; the quick method

A quick method I use for transforming a C++ standard library string to an Unreal Engine FString is to call c_str(), the base c string export helper, on a std::string. Provided the result is being implicitly convert to an FString this method will work.

std::string a = “hello”;

FString b = a.c_str();

This method is shorter and simpler than the canonical method Epic Games recommends which calls for an explicit cast. An explicit cast is only required in cases where the compiler cannot otherwise deduce that the result should be an FString.

Progress report and a happy surprise

Since the last blog post most of my work has been less milestone oriented.

  • Full multilingual support for human readable nodes, nodes which show up in UIs
  • Preliminary support for Option XMLs
  • Two fixes for the XML schema to bring it upto date
  • Creation of a script wrapping XMLint and foomatics XML schema XSDes
  • Clean up of the OpenPrinting front page

I felt the the XML schema was important because my Perl module, the one replacing the C programs, is very forgiving. Robustness is of course a desirable trait in production software but Foomatic still needs something to enforce consistency. I knew we had XML XSDes but we were missing a simply script to run them. Once I had my new script in place two bugs in the printer schema came up. After I fixed that a rerun uncovered four XMLs that needed fixing.

When I started writing support for overviews (a massive data structure containing every printer and its drivers) I uncovered a bug, see if you can spot it:

# This variable holds the current time #
my $now = time;
my $Parser = xmlParse->new('en','0');
my @allPrinters
foreach my $xml (<../printer/*.xml>) {
   my$perlData = $Parser->parsePrinter($xml);
   print Dumper($perlData);

# Calculate runtime
$runtime = time - $now;

I hope you didn’t look too hard, the bug is way too easy to be obvious. This is from scaffolding.pl, a script I use to run xmlParse.pl through its paces. Its a throw away script that exists only for testing. Part of this testing is keeping an eye on runtime, and this is where the bug was.

Notice that our runtime calculation includes Dumper(A helper function that outputs Perl data structures in human readable form), when I wrote the script my assumption was that dumping the data structure was trivial. I was very wrong about this. We can read and parse an XML in one third the time it takes Dumper to print it. Every single printer XML can be read and parsed in under four seconds. Parsing every single Driver we get a runtime of 0:00, the one second resolution of the crude runtime calculator is insufficient! Fixing this bug also reduces the runtime of the C programs, but because the data structures are the same the cost of dumping is constant between the two parsing implementations. Thus the Perl implementation’s relative runtime advantage is even greater than I originally thought.

Definitely good news to report for the next OpenPrinting teleconn.