In my BizTalk Decide shape, How can I handle below conditions in one decide shape node?
code == 'code1'
code == 'code2'
code == 'code3'
code == 'code4'
I'm trying to do, this by
(code == 'code1' Or code == 'code2' Or code == 'code3' Or code == 'code4' )
But It is not working, please suggest.
The Decide Shape takes any (mostly) C# formatted condition so you would use:
(code == "code1") || (code == "code2") || (code == "code3") || (code == "code4")
You have to use the double quote since the single quote specifically means char data, not string.
Can somebody please explain to me what is going on here?
I have this line of code:
if ( pt->child == NULL && pt->visits < cutoff+1 || depth > 5 )
and I'm getting a g++ compiler warning:
warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]|
What is it trying to warn me of? And worse, if I put in the "obvious" parens, like so:
if ( ( pt->child == NULL && pt->visits < cutoff+1 ) || depth > 5 )
I get a different behavior -- indicating I really did do something wrong in the first expression. Arithmetic operators have higher precedence over comparisons which have higher precedence over boolean operators where && has higher precedence than ||, right?
What am I missing?
Just like the numeric operators + and *, the logical operators have different precedence. So the order of evaluation of a logical statement will not necessarily be strictly left to right, but will instead evaluate && first and || 2nd. This has been the source of so much confusion and error that the compiler will emit this warning unless you explicitly surround the elements with parentheses.
What going on here? I think in this case it's erroneous because if you make g++ dump it's internal structures
this
if ( pt->child == NULL && pt->visits < cutoff+1 || depth > 5 )
printf("Hello World");
equates to this
D.3367 = pt->child;
if (D.3367 == 0B) goto <D.3368>; else goto <D.3364>;
<D.3368>:
D.3369 = pt->visits;
D.3370 = cutoff + 1;
if (D.3369 < D.3370) goto <D.3365>; else goto <D.3364>;
<D.3364>:
if (depth > 5) goto <D.3365>; else goto <D.3366>;
<D.3365>:
printf ("Hello World");
<D.3366>:
Which does exactly what you would expect.
I can't get working this conditional expression
<!--#if expr="$DOCUMENT_NAME!=index.html || $DOCUMENT_NAME!=links.html" -->
while this one without ! before = works perfect
<!--#if expr="$DOCUMENT_NAME=index.html || $DOCUMENT_NAME=links.html" -->
What's the problem? I get no error simply != doesn't work though || with other condition but works for single condition.
This is because = and != are hardly the same operator. Note that, by De Morgan's law (which I also explained in this old post),
a != b || c != d
is equivalent to
a = b && c = d
which is never true for x = a && x = b where a != b.
Changing the binary operator requires changing the conditionals as well to be equivalent.
Thus, by the above logic,
$DOCUMENT_NAME!=index.html || $DOCUMENT_NAME!=links.html
is equivalent to
$DOCUMENT_NAME=index.html && $DOCUMENT_NAME=links.html
which cannot be true as $DOCUMENT_NAME can be "index.html" or "links.html" but not both.
However, the 2nd snippet,
$DOCUMENT_NAME=index.html || $DOCUMENT_NAME=links.html
"works" because there is not the logical never-true fallacy mentioned above. It will be true when $DOCUMENT_NAME is either "index.html" or "links.html".
Some languages/values will violate the above equivalency .. but that is another topic.
What is the order in which the test or [ expressions are evaluated in a bash script? Is it the same as the order in which they are written? Are they all evaluated?
In the following example:
if [ expr1 -a -n expr2 ]
will expr2 be evaluated if expr1 is false?
It's been a long time since I used that particular syntax. Nowadays, I prefer:
if [[ expr1 && -n expr2 ]]
since I know that these are short-circuited. The bash man page specifically states:
The && and || operators do not evaluate expression2 if the value of expression1 is sufficient to determine the return value of the entire conditional expression.
It doesn't appear to state clearly one way or the other for the [ and test variant (using -a).
However, in the interests of furthering your knowledge and mine (and an indication as to why open source is a good thing), I went trolling through the bash source code.
It turns out that it's not short-circuited in that case. The particular pieces of code are (compressed a bit for readability):
static int or() {
int value, v2;
value = and();
if (pos < argc && argv[pos][0] == '-'
&& argv[pos][1] == 'o' && !argv[pos][2])
{
advance (0);
v2 = or();
return (value || v2);
}
return (value);
}
static int and() {
int value, v2;
value = term();
if (pos < argc && argv[pos][0] == '-'
&& argv[pos][1] == 'a' && !argv[pos][2])
{
advance (0);
v2 = and();
return (value && v2);
}
return (value);
}
You can see in both those cases that it continues to interpret the expressions regardless of the state of the first expression.
That was from bash 2.5 but I've just checked the 4.1 source as well and it hasn't changed. Source was pulled straight from the horse's mouth.
So. bottom line: it appears that all sub-expressions are evaluated when using -a and -o with test or [.
Suppose I have this function:
std::string Func1(std::string myString)
{
//do some string processing
std::string newString = Func2(myString)
return newString;
}
How do I set a conditional break when newString has a specific value? (without changing the source)
Setting the condition newString == "my value" didn't work. The breakpoints were disabled with an error overloaded operator not found.
There is a much easier way in Visual Studio 2010/2012.
To accomplish what you are looking for in ANSI use this:
strcmp(newString._Bx._Ptr,"my value")==0
And in unicode (if newString were unicode) use this:
wcscmp(newString._Bx._Ptr, L"my value")==0
There are more things you can do than just a compare, you can read more about it here:
http://blogs.msdn.com/b/habibh/archive/2009/07/07/new-visual-studio-debugger-2010-feature-for-c-c-developers-using-string-functions-in-conditional-breakpoints.aspx
In VS2017, I was able to set the condition as:
strcmp(&newString[0], "my value") == 0
Some searching has failed to turn up any way to do this. Suggested alternatives are to put the test in your code and add a standard breakpoint:
if (myStr == "xyz")
{
// Set breakpoint here
}
Or to build up your test from individual character comparisons. Even looking at individual characters in the string is a bit dicey; in Visual Studio 2005 I had to dig down into the member variables like
myStr._Bx._Buf[0] == 'x' && myStr._Bx._Buf[1] == 'y' && myStr._Bx._Buf[2] == 'z'
Neither of these approaches is very satisfactory. We should have better access to a ubiquitous feature of the Standard Library.
In VS2017 you can do
strcmp(newString._Mypair._Myval2._Bx._Buf,"myvalue")==0
While I've had to work around this using something similar to Brad's answer (plus using DebugBreak() to break right from the code), sometimes editing/recompiling/re-running a bit of code is either too time consuming or just plain impossible.
Luckily, it's apparently possible to spelunk into the actual members of the std::string class. One way is mentioned here -- and though he calls out VS2010 specifically, you can still access individual chars manually in earlier versions. So if you're using 2010, you can just use the nice strcmp() functions and the like (more info), but if you're like me and still have 2008 or earlier, you can come up with a raggedy, terrible, but functional alternative by setting a breakpoint conditional something like:
strVar._Bx._Ptr[0] == 'a' && strVar._Bx._Ptr[1] == 'b' &&
strVar._Bx._Ptr[2] == 'c'
to break if the first three characters in strVar are "abc". You can keep going with additional chars, of course. Ugly.. but it's saved me a little time just now.
VS2012:
I just used the condition below because newString._Bx._Ptr ( as in OBWANDO's answer ) referenced illegal memory
strcmp( newString._Bx._Buf, "my value")==0
and it worked...
#OBWANDO (almost) has the solution, but as multiple comments rightly point out, the actual buffer depends on the string size; I see 16 to be the threshold. Prepending a size check to the strcmp on the appropriate buffer works.
newString._Mysize < 16 && strcmp(newString._Bx._Buf, "test value") == 0
or
newString._Mysize >= 16 && strcmp(newString._Bx._Ptr, "ultra super long test value") == 0
Tried to use strcmp in gdb8.1 under ubuntu18.04, but it doesn't work:
(ins)(gdb) p strcmp("a", "b")
$20 = (int (*)(const char *, const char *)) 0x7ffff5179d60 <__strcmp_ssse3>
According to this answer, strcmp, is a special IFUNC, one can setup condition like this:
condition 1 __strcmp_ssse3(camera->_name.c_str(), "ping")==0
It's pretty ugly, don't want to do it the second time.
This answer gives a much better solution, it use std::string::compare :
condition 1 camera->_name.compare("ping") == 0
In VS2015 you can do
newstring[0]=='x' && newString[1]=='y' && newString[2]=='z'
Comparing string works better than comparing characters
strcmp(name._Mypair._Myval2._Bx._Buf, "foo")==0
This works, but is very inconvenient to use and error prone.
name._Mypair._Myval2._Bx._Buf[0] == 'f' &&
name._Mypair._Myval2._Bx._Buf[1] == '0' &&
name._Mypair._Myval2._Bx._Buf[2] == '0'
You could convert it into a c string using c_str() like so:
$_streq(myStr.c_str(), "foo")
To set a conditional breakpoint in std::string you need to set it on real internal members of std::string. What you see on watch window is simplified.
You can display real structure of a variable in the watch window by using ,! suffix. In your example:
newString,!
For MSVC 2015 – 2019 you can use:
For string that were never longer than 15 characters:
(newString._Mypair._Myval2._Myres < 16) ?
strcmp(newString._Mypair._Myval2._Bx._Buf, "short") == 0 :
false
For (even historically) longer strings:
(newString._Mypair._Myval2._Myres < 16) ? false :
strcmp(newString._Mypair._Myval2._Bx._Ptr, "My_test_str_value_longer_than_16_chars") == 0
Beware:
The variable name is written twice in each condition!
You need whole expression on single line. Use the copy-paste versions bellow.
Universal condition needs to put the test value twice and variable name three times:
(newString._Mypair._Myval2._Myres < 16) ?
strcmp(newString._Mypair._Myval2._Bx._Buf, "My_test_string") == 0 :
strcmp(newString._Mypair._Myval2._Bx._Ptr, "My_test_string") == 0
Notes: use wcscmp instead of strcmp if you are working with std::wstring.
Find more info on small string optimization in C++ https://vorbrodt.blog/2019/03/30/sso-of-stdstring/ includes sample code to find size of string's internal buffer.
All std:string and std::wstring single line versions for your copy paste convenience:
(newString._Mypair._Myval2._Myres < 16) ? strcmp(newString._Mypair._Myval2._Bx._Buf, "short") == 0 : false
(newString._Mypair._Myval2._Myres < 16) ? false : strcmp(newString._Mypair._Myval2._Bx._Ptr, "My_test_str_value_longer_than_16_chars") == 0
(newString._Mypair._Myval2._Myres < 16) ? strcmp(newString._Mypair._Myval2._Bx._Buf, "My_test_string") == 0 : strcmp(newString._Mypair._Myval2._Bx._Ptr, "My_test_string") == 0
(newString._Mypair._Myval2._Myres < 16) ? wcscmp(newString._Mypair._Myval2._Bx._Buf, L"short") == 0 : false
(newString._Mypair._Myval2._Myres < 16) ? false : wcscmp(newString._Mypair._Myval2._Bx._Ptr, L"My_test_str_value_longer_than_16_chars") == 0
(newString._Mypair._Myval2._Myres < 16) ? wcscmp(newString._Mypair._Myval2._Bx._Buf, L"My_test_string") == 0 : wcscmp(newString._Mypair._Myval2._Bx._Ptr, L"My_test_string") == 0
All above copy/paste samples tested on MSVC version 16.9.10 and program for Windows 10.