From: Stirling W. <swe...@gm...> - 2010-03-22 22:27:12
|
On Mon, Mar 22, 2010 at 1:40 PM, Alan Mackenzie <ac...@mu...> wrote: > Hi, Stirling, > > On Sun, Mar 21, 2010 at 01:09:59PM -0400, Stirling Westrup wrote: >> I've used cc-mode on-and-off for years, but I have to confess that >> every time I need to go and update my configuration, I get lost. Here >> is my current problem: I am working on some c++ code that wants to be >> indented like this: > >> int main >> ( int argc >> , char *argv[] >> ) >> { >> opt::get options >> .grp("General", "General Options") >> .opt<bool> >> ( "verbose|V", "!" >> , "Verbose Mode" >> , "A full explanation of Verbose Mode" >> ) >> .opt<std::string> >> ( "Library|lib|l", "s" >> , "Library to load" >> ) >> .opt<float> >> ( "zarg|z", "qq" >> ) >> .grp("Debug", "Debugging Options") >> .opt<unsigned> >> ( "Level", "n" >> , "Library to load" >> ) >> .opt >> ( "Debug|D"); >> opt::grp init("Initialization", "Example name"); >> get.addgrp(init); >> get.parse(argc,argv); >> ... >> } > > I'm feeling a bit bewildered by that code fragment, not being a C++ > hacker. Perhaps you could clue me in a bit about the syntax: > (i) How can the names ".opt" and ".grp" start of with periods? > (ii) What is the syntax of "options" in "opt::get options"? > (iii) How comes there're no semicolons in the ~20 lines following that > line? > (iv) What is the syntax of "opt::grp init(...)"? Is "opt::grp" a type, > and "init(...)" an initialisation of an object of that type? > > Thanks! opt::get and opt::grp are both type names. 'init' and 'options' are just variable names for the newly created objects. The reason for the lack of semicolons is that the first statement is many lines long. Its an initialization followed by a large number of chained method calls on the newly initialized object. This is possible because each method call returns the modified object, so that another method call can be performed on it. In essence, its no different that saying: opt::get options("x"); options.opt("foo"); options.opt("bar"); ... But it leaves out the repetition of the variable name. -- Stirling Westrup Programmer, Entrepreneur. https://www.linkedin.com/e/fpf/77228 http://www.linkedin.com/in/swestrup http://technaut.livejournal.com |