How to check if a container only has a specific element? - c++

I apologize if the wording is completely off. I am very very new to C++ syntax. For background, I have an object named system that holds elements called actions. Like so below:
for (event::System system : Ev->getSys())
{
for (event::Action actions : system.actions)
{
switch (thing)
I was wondering if there is a way to check if system (in the first for loop) has the same element within it. For example,
If it has only RUN (or RUN, RUN, RUN...etc), then execute a specific set of code. Or if it has different types like RUN, STOP, WALK, then it can proceed. I know it will be an if/else statement but I can't think of how to build the condition for it.

Related

Question on entry point (beginner level )

I have started learning C++ according to a recommended list in Stack Overflow. There is book called "C++ primer" got me interested .Anyway in that book writer called "main" function an entry point. According to "Wikipedia" (what I understood) entry points are used to run a program .Does it give permission to OS to run my code? Is that why main is needed so OS can recognize and have the authority to run the code?
Does it give permission to OS to run my code?
Nope.
A program is a sequence of commands for the computer, commands such as std::cout << "Hello, world!\n";. The formal term for a such command (in C++) is statement.
Statements are generally executed from top to bottom, but which statement should be executed first? Can't be the first statement in the source code file, because there can be more than one file.
In C++ it was decided that the first statement to be executed is the first statement of main, followed by the rest of statements in it. Even if your program contains more than one source code file, there can't be more than one main.
Execution of statements in a specific order is called control flow, and since control flow enters your program at the beginning of main, it's called the entry point.
It will make more sense once you learn about functions.

How to use HadoopJarStepConfig.StepProperties?

AWS docs state that this property is "A list of Java properties that are set when the job flow step runs. You can use these properties to pass key-value pairs to your main function in the JAR file."
But there is no explanation (at least, I failed to find any) how exactly they are passed, and how to properly access said collection of key-value pairs on a main function side.
Quick check proved that they aren't passed via environment nor command line arguments. Could be some other way?
Okay, seems that this map goes to Java system properties and is accessible from main function side via System.getProperties() call, but there are some non-obvious implications.
First thing to keep in the mind, that internally they are set via environment variable HADOOP_CLIENT_OPTS as -Dkey=value switches. But EMR does not bother itself to properly escape keys nor values by shell rules.
Also, it does not report any syntax errors if there are properties with non-printable characters, just omits setting them altogether. And it plays even worse with special shell characters like * ? ( ) \ and such — it'll fail the task execution without a proper explanation, and the log records will vaguely point only to obscure syntax errors in some eval() call deeply inside of EMR internal shell script wrappers.
Please be aware about that behaviour.
Properties must be shell-escaped, and in some cases even doubly shell-escaped.

How to add a constant spread to an existing YieldTermStructure object in Quantlib

I would really appreciate your inputs on moving from a YieldTermStructure pointer to that of adding a spread as below::
boost::shared_ptr<YieldTermStructure> depoFutSwapTermStructure(new PiecewiseYieldCurve<Discount,
LogLinear>(settlementDate, depoFutSwapInstruments_New, termStructureDayCounter, 1.0e-15));
I tried adding a spread of 50 bps as below...
double OC_Spread(0.50 / 100);
Rate OCSQuote = OC_Spread;
boost::shared_ptr<Quote> OCS_Handler(new SimpleQuote(OCSQuote));
I then proceed to create a zerospreaded object as below:
ZeroSpreadedTermStructure Z_Spread(Handle<YieldTermStructure>(*depoFutSwapTermStructure), Handle<Quote>(OCS_Handler));
But now I am stuck as the code repeatedly breaks down if I go on ahead to do anything like
Z_Spread.zeroYieldImpl;
What is the issue with above code. I have tried several flavors of above approach and failed on all the fronts.
Also is there a native way of calling directly the discount function just like as I do now with the TermStructure object prior to adding the spread currently as below???
depoFutSwapTermStructure->discount(*it)
I'm afraid you got your interfaces a bit mixed up. The zeroYieldImpl method you're trying to call on your ZeroSpreadedTermStructure is protected, so you can't use it from your code (at least, that's how I'm guessing your code breaks, since you're not reporting the error you get).
The way you interact with the curve you created is through the public YieldTermStructure interface that it inherits; that includes the discount method that you want to call, as well as methods such as zeroRate or forwardRate.
Again, it's hard to say why your call to discount fails precisely, since you're not quoting the error and you're not saying what *it is in the call. From the initialization you do report, and from the call you wrote, I'm guessing that you might have instantiated a ZeroSpreadedTermStructure object but you're trying to use it with the -> syntax as if it were a pointer. If that's the case, calling Z_Spread.discount(*it) should work instead (assuming *it resolves to a number).
If that's not the problem, I'm afraid you'll have to add a few more details to your question.
Finally, for a more general treatment of term structures in QuantLib, you can read here and here.

goto statement between methods C++

I am running some code to quickly test. I know I would almost never use a goto statement, but I need to test if certain parts of a method work at a certain period of time, and I'm just curious. I know that I can jump between lines of code in visual by right clicking in a method and say go to cursor, or a goto statement inside of that method, but what if I want to test certain code at a certain time, In a different method? If I wanted to see if it would work in a given situation without recreating that line of code? I read http://www.tutorialspoint.com/cplusplus/cpp_goto_statement.htm about goto statements, but when trying it in between class methods, it won't recognize the statement. I guess I could try method calls and goto's, but I'm really curious for curiosity sake for one, and two it isn't like I'm using the code. I just need to test something quickly.
when trying it in between class methods, it won't recognize the statement.
That's right. You need to define a label in order to use goto statement. The scope of label definitions is local to functions, so jumping to a label in a different function is not allowed.
It wouldn't be of much help anyway, because in order to get into a function you need more context than just the line position in the code: among other things, you need to provide the state for all parameters, all variables, loop counters, and so on.
On top of that, there are restrictions even on using goto within the same function: you cannot jump over a variable definition and use that variable after that.

Custom front end and back end with Pantheios logging

Apologies if I'm missing something really obvious, but I'm trying to understand how to write a custom front end and back end with Pantheios. (I'm using it from C++, not C.)
I can follow the purposes of the initialisation functions (I think) but I'm unsure about the others: pantheios_be_logEntry, pantheios_fe_getProcessIdentity and pantheios_fe_isSeverityLogged.
In particular, I'm confused about the relationship between a front end and a back end. How do I make them communicate with each other?
Not sure I understand exactly what you don't understand, but maybe that's part of the problem. ;-) So I'll try my best and you let me know whether it's near or not.
pantheios_fe_getProcessIdentity() is called once, when Pantheios is initializing. You need to return a string that identifies the process. (Actually, it identifies the link-unit; a term defined in Imperfect C++, written by Pantheios' creator, Matthew Wilson, which means the scope of link names, i.e. an executable program module or a dynamic library module.)
pantheios_fe_isSeverityLogged() is called whenever a log statement is executed in application code. It returns non-zero to indicate that the statement should be processed and sent to the output (via the back-end). If it returns zero, no processing occurs. FWIU, this is the main reason why Pantheios is so fast.
pantheios_be_logEntry() is called whenever a log statement is to be sent for output, when pantheios_fe_isSeverityLogged() has returned non-zero and the Pantheios core has processed the statement (forming all the arguments in your code into a single string). It sends the statement string to wherever it should go. For example, the be.fprintf back-end prints it to the console using fprint().
Once you grok these aspects, the second part of your question is where it gets interesting. When your front-end and back-end are initialized they get to create some context (e.g. a C++ object) that the Pantheios core holds for them, and gives them back each time it calls a front/back end API function. When you're customizing both, you can have them communicate via some shared context that they both know about, but which the Pantheios core does not (and should not) know about, beyond having an opaque handle (void*) to it.
HTH