Using clang-format - keep empty braces on the same line - c++

I'm trying to configure clang-format so that usually braces will start on their own line:
void func()
{
if (...)
{
printf("Ta Da\n");
}
}
But I want it to be so when braces are empty, it will be kept in a single line. (Mainly used for ctors):
Bar::Bar(int val):
_val(val)
{}
currently it will look like this:
Bar::Bar(int val):
_val(val)
{
}
Any ideas?
(Edited to make the situation clearer)

UPDATE: Hurray! It is now possible with Clang 5.0 or later with custom BreakBeforeBraces.
See SplitEmptyFunction in the documentation.
Configuration example:
BreakBeforeBraces: Custom
BraceWrapping:
SplitEmptyFunction: false
↓↓↓ Original answer (outdated) ↓↓↓
Unfortunately, it is not possible to achieve with Clang 4.0 the current clang-format options (as of Clang 4.0).
Source: I had the same question. After studying every documented option, and many tweaking attempts, I could not achieve this. In my experience, clang-format is just not as flexible as one would hope. As soon as you want to step out of the predefined styles and tweak things to your liking, it just does not cut it.

I used combination of
"AllowShortFunctionsOnASingleLine": true,
and
"BreakBeforeBraces": "Allman",
to get it to one line when declaring empty constructors etc..

Related

How to beautify/change style in a c++ project using clang/clang-tidy?

Having a large c++ project I would like to change some styles.
I am currently wondering if changing the public class methods from camelCase to PascalCase is actually possible without having to write a full refactoring tool.
eg:
class MyLovelyClassPlentyOfCamelCaseMethods
{
public:
void aCamelCaseMethodIWouldLoveToConvertToPascalCaseEverywhere();
protected:
private:
void anotherCamelCaseMethodIWouldLoveToRemainAsIs();
};
I know that LLVM/clang tools are a high powerful tools that can be oriented to achieve this but I am completely new at clang and clang-tidy in every aspect so any step by step guiding through is greatly welcomed. I have found several resources and documentation about but still couldn't reach to any useful point and started being really confused on how to go along with this.
Thanks a lot to the community in advance!
There is a clang-tidy check designed for this purpose :
readability-identifier-naming
Using the fix option you can use this check to actually convert the case from pascal to camel.
readability-identifier-naming can be used to convert case individually for different categories of identifiers.
To change case of public member methods to pascal* and private member methods to camel* your .clang-tidy file should look like this:
Checks: '-*,readability-identifier-naming'
CheckOptions:
- { key: readability-identifier-naming.PublicMethodCase, value: CamelCase}
- { key: readability-identifier-naming.PrivateMethodCase, value: camelBack}
*note: what you refer to as pascal case is called CamelCase and your camel case is camelBack in clang-tidy

How to install feature based on the property set in custom action?

I am trying to install one from two features based on the value that should be set inside of the custom action.
Firstly, I set the value of a property:
UINT __stdcall ConfigurationCheckAction(MSIHANDLE hInstall)
{
HRESULT hr = S_OK;
UINT er = ERROR_INSTALL_FAILURE;
hr = WcaInitialize(hInstall, "ConfigurationCheckAction");
if (condition) {
MsiSetProperty( hInstall, TEXT("STREAM"), TEXT("RED") );
}
else {
MsiSetProperty( hInstall, TEXT("STREAM"), TEXT("BLUE") );
}
return WcaFinalize(er);
}
Secondly, I make two conditions per two features:
<Feature Id='Complete' Level='1'>
<Feature Id="Red" ConfigurableDirectory="TARGETDIR" Title="F1" Level="0">
<Condition Level="1">STREAM</Condition>
</Feature>
<Feature Id="Blue" ConfigurableDirectory="TARGETDIR" Title="F2" Level="0">
<Condition Level="1">NOT STREAM</Condition>
</Feature>
</Feature>
Note that I don't define property inside of the wxs file previously, as I would like to set it from the custom action.
My custom action is called before InstallInitialize and Execute is immediate.
From the installation log I have confirmation that the property is set.
However, my conditional installation does not work, as it seems like what is in the condition is always evaluated as false.
I tried evaluating conditions:
STREAM, STREAM=RED, STREAM="RED", < ![CDATA[STREAM=RED]]>
I am running out of ideas what to do and would appreciate help.
Too late to test all of this, but here goes with some information. I will check back tomorrow. Essentially I think the problem is your custom action sequencing. Try before Costing.
Some things to consider:
Custom action sequencing: you need to sequence your custom action right and it needs to be present in both silent and interactive installation modes.
Did you try to sequence the set property custom action before CostInitialize? You state you set it before InstallInitialize, but try it before CostInitialize instead (you might have tried).
And did you remember to insert this custom action in the InstallUISequence as well as the InstallExecuteSequence? You need to insert in both sequences in case the setup runs in silent mode. Before CostInitialize in both sequences I believe.
Feature Level: manipulating features via the feature level and INSTALLLEVEL is just one way to do feature control, you can also set features via the command line or using a custom action.
Setting a feature level to 0 should hide the feature from view in the setup's custom dialog.
Setting a feature level higher than the setup's INSTALLLEVEL will deselect the feature from installation.
And the other way around setting a feature level lower or equal to the setup's INSTALLLEVEL will select the feature for installation.
The conditional syntax allowed is quite flexible, and could provide the functionality you need outright - but I have never used them properly. Here is an example from the Installshield forum.
ADDLOCAL & REMOVE: you can manipulate the feature selection by changing the values of the ADDLOCAL and REMOVE properties from a custom action (technically also REINSTALL and ADVERTISE) - and these properties can be set via the command line as well.
Win32: you can also use the Win32 functions MsiGetFeatureState and MsiSetFeatureState - from a C++ custom action - to set feature selection.
Frankly it is a bit mad the whole thing. Also keep in mind that there are feature action states (what is going to happen to a feature) and feature installed states (what state it is in). The Win32 function documentation should explain.
Cross-linking for easy retrieval:
Unselected Feature Being Installed
I have done something similar, but we ended up controlling this at a component level(adding the condition to the <Component/> elements instead of the feature element using a transform during heat). But our condition utilizes CDATA while also using double quotes for the value, which you don't list in what you've tried. So first I'd try the following conditions in your features:
<Condition><![CDATA[STREAM="RED"]]></Condition>
<Condition><![CDATA[STREAM="BLUE"]]></Condition>
If that still does not work, I would try the following:
Add the STREAM property with a default value to your WiX. Then test it with that default value to see if having the default value set to begin with makes it work. That could mean you need to set the property sooner, possibly off a UI event. <Property Id="STREAM" Value="RED"/>
As a last resort, you could add the conditions to each component as I did, but we only did that for very specific reasons, hopefully you can get the conditional feature to work with the above suggestions!
I hope the above fixes your problem, or at least leads you to the answer!
Thank you for your replies. In the end, a combination of your suggestions helped me.
I want to state what did and what did not work:
Adding property to WiX with a default value was not necessary (as well with adding property of this property Secure='yes')
Calling custom action before CostInitialize did not solve the problem on its own, but I believe it was one of the factors that resolved an issue.
Conditional sintax was corrected by:
a) Putting condition inside of CDATA and adding quotes to the value of property as suggested: <Condition><![CDATA[STREAM="RED"]]></Condition>
b) Reversing condition levels so feature has condition level 1 and condition has level 0. This means that feature is always installed, unless the condition expression is false.
Concerning the correct order of the custom actions, the description of the custom action type 51 contains the decisive hint:
"To affect a property used in a condition on a component or feature, the custom action must come before the CostFinalize action in the action sequence."

How to specify delimiter for list.each function in ColdFusion 11?

I have adopted the CFScript syntax for most of the work with ColdFusion now, since with the new version of ColdFusion v11(codenamed Splender), almost all the short-comings of the script style syntax has been given serious thoughts. Thought suprisingly, I came across a requirement where I needed to iterate throught the list with variable delimiter. So I choose the list.each function in CF11 and not any other option would do since I also need the current index value along the way as well.
list.each(function(element,index,list){
writeOutput("#index#:#element#;");
}, ";")
The problem is that this function surprisingly does not seem to support a custom delimiter.
To save the time, I would like to mention that I already tried the for (element in...) with a count variable for my needs.
var idx=1;
for (element in "a,b,c,d,e"){
writeOutput(element);
LOCAL.idx++;
}
But I would appreciate some help with the original list.each function in CF11, is it even possible somehow to implement? or is it what I think a shortcoming.
I'm not using CF11, but i would point you to this bug report, which seems to say the HF3 does exactly what you want.
If that doesn't work, or in the meantime, you could convert it to an array and use ArrayEach().

Infragistics FilterMenuFormatString

Would someone kindly help me understand this property. Below is their explanation:
<ig:TextColumn.FilterColumnSettings>
<ig:FilterColumnSettings FilterMenuFormatString="{}{Regex}"/>
</ig:TextColumn.FilterColumnSettings>
When you are applying the format through XAML and using special symbols in it you should escape it with {}.
I don't understand how to translate this to a pattern and replace. I'd like to replace the first underscore in the string with a double underscore (trying to defeat the RecognizesAccessKey behavior of the checkbox, without creating a new control template).
The FilterMenuFormatString allows you to apply a FormatString to the values displayed in the filter list similar to what the String.Format method does.
Note that the behavior that you are trying to workaround will be addressed in the Next NetAdvantage for WPF/Silverlight service release which is currently scheduled for April 5th according to the release schedule.
If you need to workaround the behavior before then you can use the workaround suggested on the Infragistics forums to set the RecognizesAccessKey of the ContentPresenter to false in the default templates.

ctag ignores classes in c++

how do you make ctags account for class in c++? when i jump to a tag of a function i get to the same name of the function but in a wrong class.
B b;
b.init();
and there are
A::init() {}
B::init() {}
i put the cursor on init of b.init() and the jump is to A::init() {} instead of B::init() {}.
Note, i didn't use a and b in my code. so this might not work if u run ctags. if it's not a common problem i ca post the actual code.
This doesn't solve your original problem, but a mapping such as the following may help:
nnoremap CTRL+] :exe 'tj' expand('<cword>')<CR>
This will at least make CTRL+] show you a selection menu when there are multiple definitions of init().
I am not aware of any method to do this, as it would require vim to do c++ parsing. In that situation I use :tselect to show the whole list and choose one.
I wrote lh-tags to solve this problem [It will require lh-vim-lib.]
It does not recognize whether b is a A or a B, but it proposes a little GUI to select which tag we want to jump to.
See it as an interactive :tselect. Put the cursor on an identifier and type <c-w><m-down> in normal mode (which is configurable). It also proposes ways to build and update the ctags base on <c-x>ta and on :w given that g:/b:ctags_dirname has been set for the current project.