C++ logging library that allows HTML/CSS output? - c++

i'm looking for a C++ library, like boost.log or pantheios that easily allows for html/css-formatted log output, maybe with some fancy jquery. i'm sure this can be done with boost.log, but i suppose in that case i'd have to spend days until understanding how to program one owns sink, programming and then debugging it.
i wonder if there is some library that already can produce a html log directly from c++. apart from this it must work cross-platform and support utf-16 (or something alike to allow for non-english output).
any good suggestions?

I haven't used this, though I've seen people reference it. It has threading support and has an HTML layout class, not sure if the latter is sufficient.
log4cxx

http://www.codeproject.com/Articles/3297/HTML-logger-portable-and-thread-safe
Or, somewhat less robust--not easily portable--and something I haven't used, but with a slightly different feature set:
http://www.kikijiki.com/en/2012/01/10/cpp-html-log-class/

Related

Tcl/Tk GUI interface for C++ library

I have a C++ library that we're using to override some functions for testing. However, we just have it set up to prompt from the command line.
I'm looking to create a GUI for it to use as the prompt rather than command line.
I've been looking into Tcl/Tk, but I'm not quite sure if it can do what I'd like. Is it possible to use the Tcl/Tk wrapper to stylize my library functions?
Can I just include Tcl/Tk in my C++ code somehow, so that I call those functions right inside my library?
Probably easiest to wrap your C++ functions with swig and call them from Tcl, see this intro, then you can use Tk to create a GUI for your input parameters and/or displaying your results.
The two mechanisms to consider for this are SWIG and critcl in C++ mode. The former is probably easier to get going with as you already have the C++ code, and the latter produces more natural (more “Tcl-ish”) language embeddings.
Once you've got your library connected up, the first thing to do is probably to write a little test suite (using tcltest, a standard package supplied with Tcl) so that you know that things are working. (That saves a lot of heartache and hair-tearing later on!) If your code is working fine, you'll probably have a good enough test suite within a day or two. Then hook it up to your GUI (Tk is indeed good for that), which can be written safe in the knowledge that it's using a business logic layer that's working fine. I encourage you to avoid putting any GUI code in your C++ code if you can; it's far better to produce a clean interface without entanglements. (OK, it's not always possible to avoid, especially if you're doing heavy visualization, but it's a lot more work…)

replace c++ with go + swig

I recently asked this question https://softwareengineering.stackexchange.com/questions/129076/go-instead-of-c-c-with-cgo and got some very interesting input. However there's a mistake in my question: I assumed cgo could also be used to access c++ code but that's not possible. Instead you need to use SWIG.
The go faq says "The cgo program provides the mechanism for a “foreign function interface” to allow safe calling of C libraries from Go code. SWIG extends this capability to C++ libraries. "
my question:
Is it possible to access high-level c++ frameworks such as QT with SWIG + Go and get productive? I'd like to use Go as a "scripting language" to utilize c++ libraries.
Have you any experience with go and swig? Are there pitfalls I have to be aware of?
Update/Answer: I've asked this over IRC too and I think the question is solved:
SWIG is a rather clean way of interfacing c++ code from other languages. Sadly matching the types of c++ to something like go can be very complex and in most cases you have to specify the mapping yourself. That means that SWIG is a good way to leverage an existing codebase to reuse already written algorithms. However mapping a library like Qt to go will take you ages. Mind it's surely possible but you don't want to do it.
Those of you that came here for gui programming with go might want try go-gtk or the go version of wxWidgets.
Is it possible? Yes.
Can it be done in a reasonably short period of time? No.
If you go back and look at other projects that have taken large frameworks and tried to put an abstraction layer on it, you'll find most are "incomplete". You can probably make a fairly good start and get some initial wrappers in place, but generally even the work to get the simple cases solved takes time when there is a lot of underlying code to wrap, even with automated tools (which help, but are never a complete solution). And then... you get to the nasty remaining 10% that will take you forever (ok, a really really long time at least). And then think about how it's a changing target in the first place. Qt, for example, is about to release the next major rewrite.
Generally, it's safest to stick to the framework language that the framework was designed for. Though many have language extensions within the project itself. For example, for Qt you should check out QML, which provides (among many other things) a javascript binding to Qt. Sort of. But it might meet your "scripting" requirement.
A relevant update on this issue: it is now possible to interact with C++ using cgo with this CL, which is merged for Go 1.2. It is limited, however, to C-like functions calls, and classes, methods and C++ goodies are not supported (yet, I hope).

c/c++ XML library question

I know that a lot of c/c++ XML library questions have been asked already (I tried to read through all of them before getting to this).
Here are the things I'm going to need in my own project:
Excellent performance
SAX2
Validation
Open source
Cross platform
I was going to use Xerces-C, but I see that a simple SAX2 setup with nothing going on in the filter is taking 5 seconds to run. (Perhaps I'm doing something wrong here?)
I would like to use libxml++, but as I tried to get it set up on my MacBook, there were some crazy dependencies that took me all the way back to gtk-doc, at which point I sort of tabled the idea.
So now I'm at libxml2. Is this the way to go? Have I missed an important option, bearing in mind the five requirements above? I don't mind using a (good) c-library like libxml2, but a c++ interface would be nice. (I don't like Xerces-C's API very much.)
I am willing to bend on the SAX2 requirement if comparable functionality is available.
Having spent a goodly amount of time on this same problem, it was my conclusion that libxml2 is the best option available under your guidelines. The C interface is not too difficult to use and it's very fast.
There are some other good options for commercial libraries, but most of the other comparable open-source options are either painfully slow or are mired in a deep, annoying vat of dependency soup.
You say you need these things in your project, but don't give any idea of the pipeline. For example, we had a whole load of static XML files which needed to be loaded quickly, but only validated rarely. So validated using a separate process in batch (using RelaxNG as it was human writable markup ) and loaded the XML using expat. The system also used XMPP, so checked streaming input, but that didn't require validating against a schema (partly because it was streamed, and mostly because most of the possible errors were not expressible in a schema).
If you need a whole host of other facilities, you can consider Qt, which has good XML support. Be warned though, it's WAY more than an XML processing library; it's a full blown application framework with support for GUIs, networking and a whole host of other things.
Qt
You can also try Poco. It's another application framework, but not as huge as Qt (i.e. no GUI-related things etc.)
Poco
Lastly, if you don't mind a C library, you can use Expat. It's not SAX per se, but writing code using Expat is somewhat like SAX. It has C++ wrappers, but they're not officially part of the project IIRC, and may not be as well-maintained or designed. I'm not too sure though.
Expat
Hope this helps!
EDIT: I misread your original post: not too sure about the validation features of these libraries, I've never used them before.

Richer logging/tracing status for C++ applications

There are plenty of logging/trace systems for letting your program output data or strings or state as it runs. Most of these let you print arbitrary strings which you can view live or after your program runs.
I noticed an ad here on SO for Smartinspect which seems to take this to a higher level, giving stack traces for each log, fancier options like plotting graphs and data values which change over time, and a lot of polish to the basic idea of a simple list of output text strings.
Since I use C++, Smartinspect won't even work for me.
A little googling finds tons of logging frameworks, but nothing that seems to do anything more than text dumps. Are their fancier tools (similar to Smartinspect?) that do more? Commercial or open source is fine, and multiplatform is a big plus.
I know this is not the answer you are most probably looking for but I would suggest that such a framework will be very hard (if not impossible) to find for C++. Doing something like dumping the stack cannot be done in a portable way as it can in a language like Java, which not only shares a common runtime accross all platforms, but provides powerful introspection capabilities too.
I don't program in Java, but my guess is that it can provide a stack-trace in the same way as Python: the stack is probably just another object in the runtime which can be inspected and manipulated.
C++ on the other hand has none of these niceities: its meant to be a close-to-the-metal language that basically adds object-orientism to C (I'm sure others will come up with much more elanorate explanations of C++'s benefit's over C but thats another discussion).
In short, C++ is not rich enough at the level required to provide the kind of features you require in a generic way. There may be some platform-specific code that could get some of this info at defined points for you out there, but it certainly wont be standards compliant, cross-platform C++.
With regards to graphs etc, that sounds much more like post-processing, which you should either be able to find something for, or more likely, you can perhaps output your log messages in a format which can be interpreted by some of these existing tools.
Other things you could look at would be integrating with syslogd, for which again, there may be richer analysis tools for (this would provide you with a capability along the lines of the one advertised for SmartInspect - that is TCP/IP based logging).
NB: a lot of what I said here about C++ comes from previous experiences trying to find decent frameworks in C++ to do tweaky, introspective type things (such as proper mock objects etc).
I wrote a article about dumping the stack in C/C++ with Windows and Unix/Linux at DDJ some years ago. Maybe it helps you:
See http://www.ddj.com/architect/185300443
If you can restrict yourself to a certain platform you can add stack traces to your logs manually. We use e.g. the glibc functionality to get stack traces on Linux to attach stack traces into our exception class. There is similar functionalyty available on Windows, but as mentioned these infrastructures are not portable.

How to convert Cardinal numbers into Ordinal ones

Is there an easy way to convert the number 1, 2, 3, ... to "1st", "2nd", "3rd", ..., and in such a way that I can give the function a language and have it return me the correct form for the language I'm targeting? Either standard C++ (stl or boost OK), MFC or ATL, win32 api or a small, single-purpose and free library that I can download from somewhere. Thanks.
I doubt whether it is possible at all, since in many languages this form will depend on the context, like gender or case of the noun it describes and different languages will require different kind of context information to allow to determine the correct form.
EDIT: E.g. in Polish it is "5-ta klasa" (5th class) vs. "5-ty miesiąc" (5th month) vs. "w 5-tym miesiącu" (in the 5th month).
I've spend quite some time researching this, because it's too large a project to get right myself. It looks like the ICU library is the only one that provides this functionality in a somewhat comprehensive way (http://www.icu-project.org/apiref/icu4c/classRuleBasedNumberFormat.html). I'm not too keen on incorporating a huge library like that, though. I'll keep on looking and I'm still open to suggestions.
Did you look up the CLDR repository on the Unicode site? I don't know if they have this kind of thing but since it's probably the most comprehensive locale data repository out there, it's probably worth a look.
http://www.unicode.org/cldr/
Since you use C++, I assume you could use GNU gettext (there's a Windows port as well) for all the translations, or at least get the idea how they solved it. Here's the relevant manual page on plural forms that explains the problem (which you already found, but in more detail) and their solution:
http://www.gnu.org/software/automake/manual/gettext/Plural-forms.html
Here is the piece of code on CodeProject that does the job. Haven't tried it on my own.