XSMELL: measurably awesomer XML creation

Posted on 2 Jul 2009

A little library I made recently seems to be amusing people. I hadn’t found time to post it here until now. From the readme:

XSMELL README

Congratulations! You have in your hands the MOST BRILLIANTEST C++ XML CREATION
LIBRARY EVER CREATED.

Have you ever needed to embed a quick snippet of HTML or XML in your C++ source
code? Didn’t you just hate having to use that obscure string concatenation
syntax?

Well no more! With the advent of XSMELL you can now use regular XML syntax
directly in your source code, thanks to the reckless use of operator
overloading, template meta-programming and preprocessor macros:

using namespace xsmell;

document doc =
      _
      <html>_
          <head>_
              <title>"XSMELL demo"<!title>_
          <!head>_
          <body>_
              <p>"Yesssssssssssssssss!"<!p>_
              <img .src("chucknorris.png") .alt("sneezing eyes open")>_ <!img>_
          <!body>_
      <!html>
      _;

std::cout << doc << '\\n';

That’s right! Thanks to XSMELL you’ll no longer suffer from S-Expression
envy. You’ve got one up on those Lisp guys now — smug bastards!

And you no longer have to worry about generating malformed XML! After spending
hours fighting obscure C++ compiler errors, you’ll be 100% certain that your
XML is correct.

NOTE: XSMELL requires Boost headers and a modern C++ compiler with support for
C99 variadic macros.

If you really must get the code, it is available on bitbucket.

No comments

Tags:

A problem with the rule of three

Posted on 15 Mar 2009

When flicking through forums where C++ advice is doled out, the Rule of Three is often mentioned.

It can be summarized as follows:

If your class requires a user-defined destructor, copy constructor or copy assignment operator, then it probably requires all three.

It’s certainly a useful guideline to internalize and it’s a good thought experiment to understand where that advice comes from.

However, it’s important to realize that the the negation is often not true. That is to say, if your class does not require a user-defined destructor or a copy constructor, it doesn’t necessarily follow that you can forgo implementing a custom copy assignment operator. Read the rest of this entry…

3 comments

Tags:

So pointers to members aren’t useless after all?

Posted on 12 Jan 2009

I remember the when I was learning C++ and first came across pointers to members and sitting there in puzzlement, wondering what on earth they could be used for. To this day I still don’t really know why they’re part of the language. Pointers to member functions are handy sometimes, but pointers to data members?

However, there are a couple of uses that I know of. They’re both tricks, C++ slight of hand if you will, that allow you to add a little extra syntactic flair to your code. I suspect that neither was a motivation for including pointers to members in the language, though.

The first one isn’t particularly new, but nor is it particularly widely known despite the fact that it’s a pretty sweet hack. The second is something I actually rustled up today. It was one of those times where you find yourself thinking “man, I wish I could write this yucky expression like this instead” and then realize that you actually can.
Read the rest of this entry…

8 comments

Tags:

Refinements of my tips for exceptions design

Posted on 30 Nov 2008

A short while ago (well, a few months back now — where does the time go?!), I listed 9 of the guidelines I like to use when designing exception classes. I still think they’re generally fine, but I feel I should provide a fix for #7. I have also come up with a #10.

Read the rest of this entry…

No comments

Tags:

jpegxx and pngxx 0.2.0 released

Posted on 29 Nov 2008

I’ve been busy updating jpegxx over the past few weeks and preparing a new library, pngxx, for release.

The new pngxx library has a very similar interface to jpegxx, so if you’ve ever used jpegxx, you’ll get along fine with pngxx.

A brief introduction is available on this website, but the main place to go for information, downloads and Mercurial repository access is sharesource:

Enjoy!

No comments

Tags: