|
Ciaphas posted:I'm trying to use xerces-c and XQilla to parse some documents. Unfortunately these documents have problems at the source like double-declared or undeclared namespaces, and it chokes trying to parse these documents until I manually fix the declaration (a no go in production). I don't actually care about the name spaces at all, is it possible to just programmatically ignore them? Would this help you: https://xerces.apache.org/xerces-c/apiDocs-3/classDOMConfiguration.html#details , more specifically the namespaces paragraph: quote:"namespaces"
|
# ? Jul 29, 2016 01:19 |
|
|
# ? Jun 2, 2024 11:07 |
|
Yeah, I tried that one already, though using the xercesc::XMLUni::fgDOMNamespaces constant instead of "namespaces". I assume they're one and the same from docs, but I'll go back upstairs and try that. Another link also shows "namespace-declarations" as a config option (constant fgDOMNamespaceDeclarations) and says not supported, but gently caress it at this stage I'ma try that too. I'll report back. Ciaphas fucked around with this message at 01:36 on Jul 29, 2016 |
# ? Jul 29, 2016 01:29 |
|
No joy, "namespaces" is indeed the value of the constant I was using, and trying "namespace-declarations" raised a SIGABRT. No matter what parameters I twiddle before setting off the parser, it just comes back with a DOMDocument containing the <?xml ... ?> stuff and nothing else, like it outright gave up on the <kml xmlns:atom="blah" xmlns:atom="blah2">...</kml> (the k is not a typo, it's Google Earth data I guess??) A pox on customers who provide invalid data that isn't even consistent in how it's invalid. Ciaphas fucked around with this message at 02:27 on Jul 29, 2016 |
# ? Jul 29, 2016 02:21 |
|
Maybe try the SAX Parser then? https://xerces.apache.org/xerces-c/program-sax2-3.html Or other parsing libraries (if possible)? Libxml2 or pugixml? Libxml is quite heavy , but so is xerces. Pugixml I used in the past and so far it served me well (http://pugixml.org/).
|
# ? Jul 29, 2016 05:11 |
|
xerces is too thoroughly embedded in this thing, near as I can tell. Not my code. I'll look up the other parsing libraries, though, if I get some spare time, so thanks for that. Got it to kind of sort of work, anyway--one of the config parameters is to force it to continue parsing (with the expected caveat emptor of course), and the result of that got me most of what I wanted. Should hold up until we get better versions of this data, at least.
|
# ? Jul 29, 2016 07:49 |
|
I have a question about formatting try/catch blocks. I've created a paste here. To be more specific all it will do is try to read and open a file, and if there's any errors it'll return false. I try to minimize the amount of returns in a function as a personal taste, but I'd like feedback on what others might think. This is a personal project, so there is no official code formatting to follow.
|
# ? Aug 5, 2016 02:07 |
|
I personally find 3 the best, 1 reasonable, and 2 ridiculous.
|
# ? Aug 5, 2016 02:18 |
|
If you want to minimize returns, you can always create a variable and just have one:code:
|
# ? Aug 5, 2016 02:24 |
|
if you want to minimize returns you're in the wrong thread, try this one instead
|
# ? Aug 6, 2016 11:33 |
|
Thanks raminasi and peepsalot for your input. I am trying to use try/catches more and worry about readability.
|
# ? Aug 6, 2016 17:37 |
|
Bonfire Lit posted:if you want to minimize returns you're in the wrong thread, try this one instead Disappointed that wasn't a link to a bitcoin thread or something.
|
# ? Aug 6, 2016 19:32 |
|
So, regarding micro-optimization of checking whether a float is non-zero or not... When I set a float specifically to zero, are all 32 bits zero? If so, when I want to check whether it was not specifically set to zero, can I do magic like this? code:
|
# ? Aug 8, 2016 03:16 |
|
That's an aliasing rules violation.
|
# ? Aug 8, 2016 03:44 |
Combat Pretzel posted:So, regarding micro-optimization of checking whether a float is non-zero or not... Yes, when you set a float to zero it gets set to positive zero, which has all bits equal zero. quote:
That's undefined behavior because it violates strict aliasing.
|
|
# ? Aug 8, 2016 03:49 |
|
Combat Pretzel posted:So, regarding micro-optimization of checking whether a float is non-zero or not... What gives you the impression that "some_float == 0" is not already as fast as it gets? If you need more speed, look into hand-rolled SIMD or throw hardware at it or something.
|
# ? Aug 8, 2016 04:00 |
|
Negative zero is not all zero bits, so your code won't work on -0.0f. Shouldn't just casting it to a bool work? It seems like that would be the most obvious hint to the compiler about what you're trying to do.
Sex Bumbo fucked around with this message at 04:26 on Aug 8, 2016 |
# ? Aug 8, 2016 04:21 |
|
Sex Bumbo posted:Negative zero is not all zero bits, so your code won't work on -0.0f. Shouldn't just casting it to a bool work? It seems like that would be the most obvious hint to the compiler about what you're trying to do. You don't get bonus points for using obscure synonyms.
|
# ? Aug 8, 2016 04:32 |
|
I saw some JavaScript (I think?) code where the programmer had done the equivalent of something like:code:
I recall also seeing stuff where they would do if(!(!thing)) for the same dumb reason. The moral of the story: just compare against what you're trying to compare against. So if you want to test if a float is nonzero, just do if(f != 0.0f) or if(f) or whatever. Doc Block fucked around with this message at 08:48 on Aug 8, 2016 |
# ? Aug 8, 2016 05:18 |
|
VikingofRock posted:Yes, when you set a float to zero it gets set to positive zero, which has all bits equal zero. Strictly speaking, neither the C nor the C++ standard specifies the bit pattern of floats, although in practice, unless you're on something extremely weird, it's going to be IEEE754. Doc Block posted:I saw some JavaScript (I think?) code where the programmer had done the equivalent of something like: !!x is a somewhat common idiom in C to coerce to 0 or 1.
|
# ? Aug 8, 2016 06:23 |
|
"!!thing" is a pretty common idiom, like it or not. Mostly in C as short for thing == 0 ? 0 : 1, but I've seen it often enough in C++ to cast to bool. You'll come across it in perfectly sane code. E:F,b.
|
# ? Aug 8, 2016 06:26 |
|
Yeah, I can understand doing !!integer as a short way to force an integer value to be 0 or 1, or if for some weird reason you really needed the comparison to be against 0 or 1 instead of zero/nonzero, but I was more poking fun at cargo cult web developers doing it needlessly in comparisons, like if(!thing == false) instead of just if(thing) because somehow doing a "true boolean comparison" (a thing a web developer actually told me) was somehow better or faster. Guess it was only tangential to the point, which was that the OP should just write if(!myFloat) or if(myFloat == 0.0f) and be done with it, as opposed to trying to micro-optimize it or casting it to a bool first as a hint to the compiler etc. etc. etc. Doc Block fucked around with this message at 08:56 on Aug 8, 2016 |
# ? Aug 8, 2016 08:44 |
|
Doc Block posted:somehow doing a "true boolean comparison" (a thing a web developer actually told me) was somehow better or faster. I assumed it was some hack around idiotic truthiness testing, but I don't know JavaScript.
|
# ? Aug 8, 2016 14:38 |
|
When it comes to JavaScript, who knows? vv But at True Boolean ComparisonTM. Even if that really is a faster/better way of doing it in JavaScript, I got the distinct impression he was just cargo culting.
|
# ? Aug 8, 2016 14:46 |
|
Doc Block posted:Even if that really is a faster/better way of doing it in JavaScript It's not.
|
# ? Aug 8, 2016 16:42 |
|
Combat Pretzel posted:So, regarding micro-optimization of checking whether a float is non-zero or not... Anytime you're thinking about optimizing code, there is only one thing that matters: measurements. Write both test cases, verify validity of results and measure performance. Then pick the most readable option that is not "too" slow (where "too" is specific to your project).
|
# ? Aug 8, 2016 17:45 |
|
Combat Pretzel posted:So, regarding micro-optimization of checking whether a float is non-zero or not... You're barking wayyyyy up the wrong tree with that kind of thinking. My advice, try to get a feel for where the compiler needs help and where it doesn't before you go off on an optimisation adventure. Cases like this aren't the kind it needs help with, that code could even be slower than normal depending on a few factors. You were posting about making a synth before so I'm assuming you're optimising that. Probably the biggest gains will be cache aware datastructure layout and memory access patterns, use of vector instructions (SSE2 can safely be assumed on any PC), and the usual DSP tricks like factoring out trigonometry ops.
|
# ? Aug 8, 2016 19:32 |
|
Making xerces-c and xqilla work correctly on both solaris and linux is driving me bugfuck insane and i'm giving up as soon as I pin down an alternative set of libraries. Anyone have any recommendations for xml parsing and XPath 1.0 support? I've been pointed at libxml2 and pugixml but don't really have any specific recommendations yet. Prefer something simple enough that it'll have a reasonable shot at compiling on Linux/Intel and Solaris/SPARC. Preferably something that can capably either handle or completely ignore xml namespaces, too, so I can use XPath queries like /kml//Placemark/*:Track or //gx:Track/when or whatever without it flipping its goddamned lid on one operating system or the other but never both at the same time loving argh Ciaphas fucked around with this message at 22:20 on Aug 8, 2016 |
# ? Aug 8, 2016 22:17 |
|
Ciaphas posted:I've been pointed at libxml2 and pugixml but don't really have any specific recommendations yet. Prefer something simple enough that it'll have a reasonable shot at compiling on Linux/Intel and Solaris/SPARC. Have you tried either of them on your dataset? Since the documents are malformed to start with I doubt you're going to get any useful off-the-cuff suggestions. Here's an example of a useless suggestion: I've used xerces on Windows/linux/AIX and pugi on Windows and they're both fine, though pugi seems a little more user-friendly. and our XML documents are well-formed and don't use namespacing
|
# ? Aug 9, 2016 13:57 |
|
In this particular case, xqilla on Linux fails to work on even well-formed (but still namespaced) documents, which is why I was getting so frustrated. Guess I'll just pick one and try it and hope
|
# ? Aug 9, 2016 18:56 |
|
Maybe everyone knew this but I found out you can put lambdas into constructor initializers and call them and I'm all ready to write incredibly stupid code now. https://ideone.com/YvSAcX
|
# ? Aug 11, 2016 00:25 |
|
Yeah that's pretty stupid, because if the lambda is simple you can just use an expression directly, and if it's complicated you should probably factor it into a named function.
|
# ? Aug 11, 2016 00:43 |
|
I was specifically thinking of making a COM object which is created by an output parameter and storing it in a smart pointer object making it impossible to do in the initializer list without a wrapping function (I think? )
|
# ? Aug 11, 2016 01:01 |
|
Yes, but your wrapping function can be a named function. No need for a lambda.
|
# ? Aug 11, 2016 02:03 |
|
raminasi posted:Yes, but your wrapping function can be a named function. No need for a lambda. On the other hand, is there a need to name the function if you're only using it there?
|
# ? Aug 11, 2016 04:39 |
|
leper khan posted:On the other hand, is there a need to name the function if you're only using it there?
|
# ? Aug 11, 2016 07:33 |
|
Remember, this is still C++ you're talking about.
|
# ? Aug 11, 2016 10:11 |
|
I had do this this ugly thing where I turned a "regular" class (class Butt) into a Singleton, but it calls methods from another singleton class (class Poop). In the constructor of Butt, I call a method in Poop to initialize an entry in it's std::map member. Unfortunately, it looks like the map is empty when I try and access it later. For example: code:
code:
code:
code:
My main function is like this: code:
code:
Thanks!
|
# ? Aug 12, 2016 08:19 |
|
Whatever the answer is, you will probably be able to post it in coding horrors. Avoid singletons in C++, but I'm sure someone forced you. Put a break at the Poop::load line and see if it is actually executed. execute() does not depend on any state from Butt, so perhaps there is some optimization going on where gcc sees a static dispatch on a static instance and just calls get() without going by the load() in ctor. I was not able to reproduce it though.
|
# ? Aug 12, 2016 10:14 |
|
leper khan posted:On the other hand, is there a need to name the function if you're only using it there? Yes, to give the future maintenance programmer some idea of what the hell you were doing. Like, there's definitely some daylight between "a single expression" and "a named function" - like, maybe, two expressions - but in most cases putting a lambda in an initializer list is going to be pretty obfuscatory.
|
# ? Aug 12, 2016 15:56 |
|
|
# ? Jun 2, 2024 11:07 |
|
Naming (any) functions just gets in the way of letting the code speak for itself. It's like the language is trying to force you to spoil the code with pseudo-comments.
|
# ? Aug 12, 2016 16:05 |