- Remarks
- Control Statements
- Standard (and boost) Types
- Standard (and boost) Functions and Idioms
- Classes
- Doxygen
- Miscellaneous
- Internal templates
-
Styling options from lh-dev are applied on the snippets. In other words, the code presented here may be formatted differently regarding spaces and newlines.
-
Placeholders are represented within «French quotation marks».
-
Default snippets from mu-template aren't documented yet.
-
About variation points ... TBD
-
About so called snippet parameter ... TBD
-
About surrounding numbers ... TBD
Produces:
catch(«...») {
«catch-code»
}
Surround:
- The selection can be surrounded to become the catch-code
Produces:
for («Enum»::type «exception_type»(«exception_args»)=«Enum»::type()
; «exception_type»(«exception_args»)!=«Enum»::MAX__
; ++«exception_type»(«exception_args»))
{
«code»
}
Surround:
- The selection can be surrounded to become the loop code
Note:
- This snippet is meant to be used with cpp/enum snippets
Produces:
for («clsname»::«const_»iterator «b»=«cont»begin(), «exception_type»(«exception_args»)=«cont».end()
; «b»!=«exception_type»(«exception_args»)
; ++«b»)
{
«code»
}
Surround:
- The selection can be surrounded to become the loop code
Notes:
- Container name («cont»), and iterators names («b» and «exception_type»(«exception_args»)) are asked to the end user
Produces:
for («type» «elem» : «range») {
«code»
}
Parameters:
- type, default:
auto&&
- elem, default:
e
- range, default:
«range»
Surround:
- The selection can be surrounded to become the loop code
To do:
- Have type default to nothing in C++17
Produces:
for («int» «i»=0;«i»!=«N»;++«i») {
«code»
}
Surround:
- The selection can be surrounded to become the loop code
Produces:
for («std::size_t» «i»=0, «N»=...;«i»!=«N»;++«i») {
«code»
}
Surround:
- The selection can be surrounded to become the loop code
Produces: namespace «ns» { ... } // «ns»
Parameters:
- ns, default:
(bg):[{ft}_]project_namespace
Options:
(bg):[{ft}_]project_namespace
, which defaults to«ns»
lh#cpp#use_cpp17()
(bg):cpp_use_nested_namespaces
Surround:
- The selection can be surrounded to become the namespace code
Notes:
- If the namespace parameter is
foo::bar
, this snippet produces two nested namespace definitions. - If C++17 flavour is selected, and
(bg):cpp_use_nested_namespaces
is true, then a C++17 nested namespace will be used.
Produces:
throw «exception_type»(«exception_args»);«»
(within code context)- or
@throw «exception_type»«»
(within Doxygen comments)
Parameters:
exception_text
, default: «text»
Options:
(bg):({ft}_)exception_type
, default:std:runtime_error
(bg):({ft}_)exception_args
, default:v:1_
, functor that getsexception_txt
injected as parameter
Also includes:
<stdexcept>
ifexception_type
starts withstd::
Produces:
try {
«code»
} catch(«std::exception const& e») {
«catch-code»
}
Surround:
- The selection can be surrounded to become the try-code
- The selection can be surrounded to become the catch-code
Produces:
while(std::getline(«stream»,«line»)) {
«code»;
}
Surround:
- The selection can be surrounded to become the loop code
Also includes:
<string>
Produces: std::auto_ptr<«type»>
Surround:
- The selection can be surrounded to become the value type
Also includes:
<memory>
Produces: std::auto_ptr<«type»> ptr(new «type»(args));
Surround:
- The selection can be surrounded to become the value type
Also includes:
<memory>
Notes:
- I hesitate to called it
cpp/make_auto_ptr
Produces: «i»fstream f(«filename»);
Surround:
- The selection can be surrounded to become the filename
Also includes:
<fstream>
Produces: std::list<«type»> «»
Surround:
- The selection can be surrounded to become the value type
Also includes:
<list>
Produces: std::map<«key»,«value»> «»
Surround:
- The selection can be surrounded to become the value type
- The selection can be surrounded to become the key type
Also includes:
<map>
Produces: boost::noncopyable
Also includes:
<boost/noncopyable.hpp>
Produces: boost::filesystem::path
Also includes:
<boost/filesystem.hpp>
Produces: boost::ptr_vector<«type»> «»
Surround:
- The selection can be surrounded to become the value type
Also includes:
<boost/ptr_container/ptr_vector.hpp>
Produces: std::set<«type»> «»
Surround:
- The selection can be surrounded to become the value type
Also includes:
<set>
Produces:
std::shared_ptr<«type»> «»
, in C++11 or moreboost::shared_ptr<«type»> «»
, otherwise
Options:
Surround:
- The selection can be surrounded to become the value type
Also includes:
<memory>
in C++11<boost/shared_ptr.hpp>
otherwise
Produces: std::string «»
Also includes:
<string>
Produces: std::unique_ptr<«type»>
Surround:
- The selection can be surrounded to become the value type
Also includes:
<memory>
Produces: std::vector<«type»> «»
Surround:
- The selection can be surrounded to become the value type
Also includes:
<vector>
Produces:
std::weak_ptr<«type»> «»
, in C++11 or moreboost::weak_ptr<«type»> «»
, otherwise
Options:
Surround:
- The selection can be surrounded to become the value type
Also includes:
<memory>
in C++11<boost/shared_ptr.hpp>
otherwise
Produces: assert(«assertion»)
Surround:
- The selection can be surrounded to become the «assertion»
Also includes:
<assert.h>
in C,<cassert>
in C++
Produces: srand(time(NULL));
Also includes:
<time.h>
in C,<ctime>
in C++<stdlib.h>
in C,<cstdlib>
in C++
Produces:
type lhs = (type) realloc(ptr, size); macro
if (! lhs) { macro
free(ptr); macro
ptr = NULL; macro
count = 0; macro
«error_message»; macro
return false macro
} macro
ptr = lhs;
Parameters:
- A dictionary that contains:
"ptr"
, default«p»
"lhs"
, defaultnew
+ ptr"type"
, default«clsname»
"count"
, default«count»
"size"
, default count* sizeof(
type)
"realloc"
, defaultrealloc
"free"
, defaultfree
"false"
, defaultfalse
"macro"
, default: an empty string, expected value:\\
Produces:
// C++98/03
array_size(«array»)
// C++11
std::extent<decltype(«array»)>::value`
// C++17
std::size(«array»)
Parameters:
- array, default «array»
Options:
Surround:
- The selection can be surrounded to become the array name
Also includes:
<type_traits>
in C++11
Notes:
- In C++98/03, the definition of
array_size()
macro is provided along the way
TODO:
- Make the snippet easier to use multiple times in C++98/03
- Define the unsafe C equivalent
c/array_size
:sizeof «array»/sizeof «array»[0]
Produces:
- or
std::begin(«container»), std::end(«container»)
if C++11 flavour is used, or if(bg):({ft}_)begin_end_style
equals "std" - or
boost::begin(«container»), boost::end(«container»)
if(bg):({ft}_)begin_end_style
equals "boost" - or
begin(«container»), end(«container»)
- or
«container».begin(), «container».end()
if(bg):({ft}_)begin_end_style
equals "adl"
Parameters:
- container, default: «container»
Options:
TODO:
- Surround container
Produces: std::cerr <<
Also includes:
<iostream>
Produces: std::cin >>
Also includes:
<iostream>
Produces: std::copy(first, last, dest)
Parameters:
- container, default: «container»
Surround:
- The selection can be surrounded to become the container name
Also includes:
<algorithm>
TODO:
- Use
cpp/b-e
snippet
Produces: std::copy(«origin».begin(), «origin».end(), std::back_inserter(«dest»));
Parameters:
- origin, default: «origin»
- dest, default: «destination»
Surround:
- The selection can be surrounded to become the container name
- The selection can be surrounded to become the destination name
Also includes:
<algorithm>
<iterator>
TODO:
- Use
cpp/b-e
snippet
Produces: std::cout <<
Also includes:
<iostream>
Produces: boost::algorithm::ends_with(«input», «prefix_searched»)
Also includes:
<boost/algorithm/string/predicate.hpp>
Produces: erase-remove idiom
Parameters:
- container, default: «container»
Surround:
- The selection can be surrounded to become the container name
Also includes:
<algorithm>
TODO:
- Use
cpp/b-e
snippet
Produces: forward<«type»>(«var»)
Parameters:
- type, default: «type»
- var, default: «var»
Surround:
- The selection can be surrounded to become the variable
- The selection can be surrounded to become the type
Produces:
std::istringstream iss(str);
if (iss >> «»)
{ ... }
Also includes:
<sstream>
Produces:
std::ostringstream oss(str);
oss << «»;
Also includes:
<sstream>
Produces: std::sort(range.begin(), range.end());
Parameters:
- range, default: «range»
Surround:
- The selection can be surrounded to become the range name
Also includes:
<algorithm>
TODO:
- Use
cpp/b-e
snippet
Produces: boost::algorithm::starts_with(«input», «prefix_searched»)
Also includes:
<boost/algorithm/string/predicate.hpp>
Produces:
// C++11
static_assert(«cond», «msg»)
// C++98/03
BOOST_STATIC_ASSERT(«cond»)
Parameters:
- condition, default: «condition»
- message, default: «message»
Options:
Also includes:
<boost/static_assert.hpp>
, in C++98/03
Produces: typeid(«type»).name()
Parameters:
- type, default: «type»
Surround:
- The selection can be surrounded to become the type
Also includes:
<typeinfo>
Produces: «clsname»& operator=(«clsname» const&);
Parameters:
"clsname"
, the class name, default: automatically deduced bylh#cpp#AnalysisLib_Class#CurrentScope
, «clsname» otherwise"use_copy_and_swap"
: boolean, default: asked to the end-user
"copy-constructor"
: (dictionary)- "visibility": "public"/"protected"/"private"
- "how": ""/"deleted"/"defaulted"
Options:
Variation Points:
cpp/copy-and-swap
snippet, if the idiom is usedcpp/internals/function-comment
snippet
Relies on:
TODO:
- Detect C++11 to insert
noexcept
(through a variation point (snippet/option) as some frameworks have their own macro/keyword fornoexcept
)
Produces: A safe bool operator
compatible with C++98/03
Notes:
- The code produced follows the pattern presented by Matthew Wilson in Imperfect C++, Addisson-Welsey, §24.6
See:
- The snippet code
TODO:
- Detect C++11 to produce an
explicit bool operator()
instead.
Produces: assignment operator + swap
// + comments generated with cpp/function-comment
T& operator=(R rhs) {
this->swap(rhs);
return * this;
}
// + comments generated with cpp/function-comment
void swap(T & other);
Parameters:
"clsname"
, the class name, default: automatically deduced bylh#cpp#AnalysisLib_Class#CurrentScope
, «clsname» otherwise
Options:
Variation Points:
cpp/internals/function-comment
snippet
TODO:
- Detect C++11 to insert
noexcept
(through a variation point (snippet/option) as some frameworks have their own macro/keyword fornoexcept
)
Produces: T(T const&);
Parameters:
"clsname"
, the class name, default: automatically deduced bylh#cpp#AnalysisLib_Class#CurrentScope
, «clsname» otherwise
"copy-constructor"
: (dictionary)- "visibility": "public"/"protected"/"private"
- "how": ""/"deleted"/"defaulted"
Options:
Variation Points:
cpp/internals/function-comment
snippet
TODO:
- Add move copy-constructor, and move assignment-operator
- Detect C++11 to insert
noexcept
(through a variation point (snippet/option) as some frameworks have their own macro/keyword fornoexcept
)
Produces: T();
Parameters:
"clsname"
, the class name, default: automatically deduced bylh#cpp#AnalysisLib_Class#CurrentScope
, «clsname» otherwise
"default-constructor"
: (dictionary)- "visibility": "public"/"protected"/"private"
- "how": ""/"deleted"/"defaulted"
Options:
Variation Points:
cpp/internals/function-comment
snippet
TODO:
- Detect C++11 to insert
noexcept
(through a variation point (snippet/option) as some frameworks have their own macro/keyword fornoexcept
)
Produces: «virtual »~T();
Parameters:
"clsname"
, the class name, default: automatically deduced bylh#cpp#AnalysisLib_Class#CurrentScope
, «clsname» otherwise"is_virtual"
: boolean, default: «virtual »
"copy-constructor"
: (dictionary)- "visibility": "public"/"protected"/"private"
- "how": ""/"deleted"/"defaulted"/"pure"
Variation Points:
cpp/internals/function-comment
snippet
Options:
Produces:
«clsname» operator«X»(«clsname» lhs, «clsname» const& rhs)
{ return lhs «X»= rhs; }
Parameters:
"operator"
: binary operation name, default: «X»"clsname"
, the class name, default: automatically deduced bylh#cpp#AnalysisLib_Class#search_closest_class
Options:
Note:
- The code generated may change to encompass C++11 best practices and performances. See some experimentations I've done.
TODO:
cpp/internals/function-comment
snippet
Produces: istream& operator>>(istream &, class-type)
Relies on:
Produces: ostream& operator<<(ostream &, class-type)
Relies on:
Note: Unlike other snippets, class patterns are often under a BSL license
TBD
Produces: A base class to inherit from with:
- A virtual pure public destructor
- A protected default constructor (unless specified otherwise)
- Non-copy-ability enforced
Parameters:
- Any parameter passed to
cpp/internals/class-skeleton
Options:
- Any options used by
cpp/internals/class-skeleton
. In particular:
Relies on:
Produces: A base class to inherit from with:
- A virtual public destructor, not necessarily pure (see
cpp/abstract-class
) - A protected default constructor (unless specified otherwise)
- Non-copy-ability enforced
Parameters:
- Any parameter passed to
cpp/internals/class-skeleton
Options:
- Any options used by
cpp/internals/class-skeleton
. In particular:
Relies on:
Produces: A base class to inherit from with:
- A protected non-virtual destructor
- A protected default constructor (unless specified otherwise)
- Non-copy-ability enforced
Parameters:
- Any parameter passed to
cpp/internals/class-skeleton
Options:
- Any options used by
cpp/internals/class-skeleton
. In particular:
Relies on:
Produces: Wizard that produces a class definition, and asks for class semantics to the user:
- Value semantics (stack-based, copyable, comparable)
- Stack based semantics (non-copyable)
- Entity semantics (reference semantics, non-copyable)
- Entity semantics (reference semantics, clone-able)
Parameters:
- singleton name, default: asked to the user
Options:
(bg):dox_group
, default: «Project»(bg):({ft_}dox_TagLeadingChar)
Variation Points/Relies on:
- mu-template "c/section-sep" snippet
- cpp/internals/formatted-comment
- cpp/internals/function-comment
- cpp/copy-constructor
- cpp/copy-and-swap
- cpp/destructor
Also includes:
<boost/noncopyable.hpp>
Todo:
- Have all class variations in their own template-file, and have the wizard glob compatible files to ask the use which one he prefers
- Enhance the semantics (see Big Rule of Two in C++98/03, Rule of All or
Nothing is C++11). We should have:
- value-semantics, no resources
- value-semantics, responsible for one resource
- value-semantics, with RAII encapsulated resource(s)
TBD:
TBD:
TBD:
TBD:
TBD:
Produces: Wizard that produces a singleton class definition
Parameters:
- singleton name, default: asked to the user
Options:
(bg):dox_group
, default: «Project»(bg):({ft_}dox_TagLeadingChar)
Notes:
- A Doxygen documentation skeleton is inserted
- The user is asked to choose the kind of singleton implementation he desires
- Scott Meyer's singleton (local-static, MT-safe (C++11), lazy-construction supported)
- My own appreciation of what a singleton shall look like (MT-safe, no lazy construction, but explicit initialisation)
Also includes:
<boost/noncopyable.hpp>
Variation Points:
- mu-template "c/section-sep" snippet
Relies on:
CppDox_SingletonWizard()
Todo:
- Have all singleton variations in their own template-file, and have the wizard glob compatible files to ask the use which one he prefers
- Use cpp/internals/function-comment
Produces: traits-class
/** «name» traits class.
*/
template <typename «T»> struct «name»_traits
{ <++> };
Produces: @author
Options:
Relies on:
Produces: <code>«code»</code>
Parameters:
- «code», default: empty placeholder «»
Options:
Surround:
- The selection can be surrounded by
<code>
tags.
Relies on:
Produces: <em>«text»</em>
Parameters:
- «text», default: empty placeholder «»
Options:
Surround:
- The selection can be surrounded by
<em>
tags.
Relies on:
Produces: /** @file ... */
Options:
(bg):dox_group
, default: «Project»(bg):ProjectVersion
, default: «1.0»(bg):({ft_}dox_TagLeadingChar)
Notes:
- The filename written with the
@file
tag is deduced fromexpand(%:t)
Relies on:
TODO:
- Recognize SVN/CVS context to not always include RCS tags like
$Id$
Produces: /** @ingroup, @params, @exceptions, @pre, ... */
Note:
- This snippet is used to organize the various elements computed by
:DOX
- Its internal are likely to change in the future to factorize the code with
autoload/lh/dox.vim
and other snippets like cpp/internals/function-comment
Produces: Doxygen local group
//@{
«»
//@}
Surround:
- The selection can be surrounded by the group tags
Produces: <html-tag>«text»</html-tag>
Parameters:
- «text», default: empty placeholder «»
Options:
Surround:
- The selection can be surrounded by the html-tags
- The selection can become the HTML tags
Relies on:
Produces: /**@ingroup ... */
Options:
(bg):dox_group
, default: «Project»(bg):({ft_}dox_TagLeadingChar)
Relies on:
Produces: @since Version
Options:
(bg):ProjectVersion
, default: «1.0»(bg):({ft_}dox_TagLeadingChar)
Relies on:
Produces: <tt>«text»</tt>
Parameters:
- «text», default: empty placeholder «»
Options:
Surround:
- The selection can be surrounded by
<tt>
tags.
Relies on:
TBD
Produces: The empty definition for a stream operation.
Parameters
s:direction
:i
oro
Notes:
s:clsname
: The name of the current class/type is searched withCpp_SearchClassDefinition()
, it will be asked to the user if none is founds:friend
is assigned tofriend
if a class was founds:const
is assigned toconst
if a class was founds:op
,s:type
ands:stream_param
are deduced froms:direction
Relies on:
Produces:
{
return «s:stream_param» «s:op» «fields»;
}
Parameters
s:stream_param
:is
oros
s:op
:>>
or<<
s:direction
:i
oro
Options:
Also includes:
<istream>
ifs:direction == "i"
- or
<ostream>
ifs:direction == "o"
Produces:
«s:friend»«s:type»& operator«s:op»(«s:type» & «s:stream_param», «s:clsname» «s:const»& v)
Parameters
s:clsname
: The name of the class/type the operator applies to.s:stream_param
:is
oros
s:type
:std::istream
orstd::ostream
s:op
:>>
or<<
s:friend
:friend
or empty strings:const
:const
or empty string
Options: