typedef VarList<Tail...> VarListTail;
typedef std::pair<Head, typename VarListTail::ListType> ListType;
};
+class a { explicit operator bool() {return true;} };
int main() {
typedef std::unique_ptr<int> intPointer;
intPointer p(new int(10));
/* Line 371 of yacc.c */
#line 56 "parser.y"
-#include "gromacs/utility/scoped_ptr_sfree.h"
+#include "gromacs/utility/scoped_cptr.h"
#include "parser_internal.h"
-using gmx::scoped_ptr_sfree;
+using gmx::scoped_guard_sfree;
using gmx::SelectionParserValue;
using gmx::SelectionParserValueList;
using gmx::SelectionParserValueListPointer;
#line 252 "parser.y"
{
BEGIN_ACTION;
- scoped_ptr_sfree nameGuard((yyvsp[(1) - (1)].str));
+ scoped_guard_sfree nameGuard((yyvsp[(1) - (1)].str));
SelectionTreeElementPointer s
= _gmx_sel_init_group_by_name((yyvsp[(1) - (1)].str), scanner);
SelectionTreeElementPointer p
#line 270 "parser.y"
{
BEGIN_ACTION;
- scoped_ptr_sfree nameGuard((yyvsp[(1) - (2)].str));
+ scoped_guard_sfree nameGuard((yyvsp[(1) - (2)].str));
set((yyval.sel), _gmx_sel_init_selection((yyvsp[(1) - (2)].str), get((yyvsp[(2) - (2)].sel)), scanner));
END_ACTION;
}
#line 277 "parser.y"
{
BEGIN_ACTION;
- scoped_ptr_sfree nameGuard((yyvsp[(1) - (3)].str));
+ scoped_guard_sfree nameGuard((yyvsp[(1) - (3)].str));
set((yyval.sel), _gmx_sel_assign_variable((yyvsp[(1) - (3)].str), get((yyvsp[(3) - (3)].sel)), scanner));
END_ACTION;
}
#line 284 "parser.y"
{
BEGIN_ACTION;
- scoped_ptr_sfree nameGuard((yyvsp[(1) - (3)].str));
+ scoped_guard_sfree nameGuard((yyvsp[(1) - (3)].str));
set((yyval.sel), _gmx_sel_assign_variable((yyvsp[(1) - (3)].str), get((yyvsp[(3) - (3)].sel)), scanner));
END_ACTION;
}
#line 291 "parser.y"
{
BEGIN_ACTION;
- scoped_ptr_sfree nameGuard((yyvsp[(1) - (3)].str));
+ scoped_guard_sfree nameGuard((yyvsp[(1) - (3)].str));
set((yyval.sel), _gmx_sel_assign_variable((yyvsp[(1) - (3)].str), get((yyvsp[(3) - (3)].sel)), scanner));
END_ACTION;
}
#line 383 "parser.y"
{
BEGIN_ACTION;
- scoped_ptr_sfree opGuard((yyvsp[(2) - (3)].str));
+ scoped_guard_sfree opGuard((yyvsp[(2) - (3)].str));
set((yyval.sel), _gmx_sel_init_comparison(get((yyvsp[(1) - (3)].sel)), get((yyvsp[(3) - (3)].sel)), (yyvsp[(2) - (3)].str), scanner));
CHECK_SEL((yyval.sel));
END_ACTION;
#line 394 "parser.y"
{
BEGIN_ACTION;
- scoped_ptr_sfree nameGuard((yyvsp[(2) - (2)].str));
+ scoped_guard_sfree nameGuard((yyvsp[(2) - (2)].str));
set((yyval.sel), _gmx_sel_init_group_by_name((yyvsp[(2) - (2)].str), scanner));
END_ACTION;
}
#line 422 "parser.y"
{
BEGIN_ACTION;
- scoped_ptr_sfree posmodGuard((yyvsp[(1) - (2)].str));
+ scoped_guard_sfree posmodGuard((yyvsp[(1) - (2)].str));
set((yyval.sel), _gmx_sel_init_keyword((yyvsp[(2) - (2)].meth), SelectionParserValueListPointer(), (yyvsp[(1) - (2)].str), scanner));
CHECK_SEL((yyval.sel));
END_ACTION;
#line 430 "parser.y"
{
BEGIN_ACTION;
- scoped_ptr_sfree posmodGuard((yyvsp[(1) - (3)].str));
+ scoped_guard_sfree posmodGuard((yyvsp[(1) - (3)].str));
set((yyval.sel), _gmx_sel_init_keyword_strmatch((yyvsp[(2) - (3)].meth), gmx::eStringMatchType_Auto, get((yyvsp[(3) - (3)].vlist)), (yyvsp[(1) - (3)].str), scanner));
CHECK_SEL((yyval.sel));
END_ACTION;
#line 438 "parser.y"
{
BEGIN_ACTION;
- scoped_ptr_sfree posmodGuard((yyvsp[(1) - (4)].str));
+ scoped_guard_sfree posmodGuard((yyvsp[(1) - (4)].str));
set((yyval.sel), _gmx_sel_init_keyword_strmatch((yyvsp[(2) - (4)].meth), (yyvsp[(3) - (4)].smt), get((yyvsp[(4) - (4)].vlist)), (yyvsp[(1) - (4)].str), scanner));
CHECK_SEL((yyval.sel));
END_ACTION;
#line 446 "parser.y"
{
BEGIN_ACTION;
- scoped_ptr_sfree posmodGuard((yyvsp[(1) - (3)].str));
+ scoped_guard_sfree posmodGuard((yyvsp[(1) - (3)].str));
set((yyval.sel), _gmx_sel_init_keyword((yyvsp[(2) - (3)].meth), get((yyvsp[(3) - (3)].vlist)), (yyvsp[(1) - (3)].str), scanner));
CHECK_SEL((yyval.sel));
END_ACTION;
#line 457 "parser.y"
{
BEGIN_ACTION;
- scoped_ptr_sfree posmodGuard((yyvsp[(1) - (3)].str));
+ scoped_guard_sfree posmodGuard((yyvsp[(1) - (3)].str));
set((yyval.sel), _gmx_sel_init_method((yyvsp[(2) - (3)].meth), get((yyvsp[(3) - (3)].plist)), (yyvsp[(1) - (3)].str), scanner));
CHECK_SEL((yyval.sel));
END_ACTION;
#line 497 "parser.y"
{
BEGIN_ACTION;
- scoped_ptr_sfree posmodGuard((yyvsp[(1) - (2)].str));
+ scoped_guard_sfree posmodGuard((yyvsp[(1) - (2)].str));
set((yyval.sel), _gmx_sel_init_keyword((yyvsp[(2) - (2)].meth), SelectionParserValueListPointer(), (yyvsp[(1) - (2)].str), scanner));
CHECK_SEL((yyval.sel));
END_ACTION;
#line 505 "parser.y"
{
BEGIN_ACTION;
- scoped_ptr_sfree posmodGuard((yyvsp[(1) - (3)].str));
+ scoped_guard_sfree posmodGuard((yyvsp[(1) - (3)].str));
set((yyval.sel), _gmx_sel_init_method((yyvsp[(2) - (3)].meth), get((yyvsp[(3) - (3)].plist)), (yyvsp[(1) - (3)].str), scanner));
CHECK_SEL((yyval.sel));
END_ACTION;
#line 570 "parser.y"
{
BEGIN_ACTION;
- scoped_ptr_sfree posmodGuard((yyvsp[(1) - (2)].str));
+ scoped_guard_sfree posmodGuard((yyvsp[(1) - (2)].str));
set((yyval.sel), _gmx_sel_init_keyword((yyvsp[(2) - (2)].meth), SelectionParserValueListPointer(), (yyvsp[(1) - (2)].str), scanner));
CHECK_SEL((yyval.sel));
END_ACTION;
#line 608 "parser.y"
{
BEGIN_ACTION;
- scoped_ptr_sfree keywordGuard((yyvsp[(1) - (3)].str));
+ scoped_guard_sfree keywordGuard((yyvsp[(1) - (3)].str));
set((yyval.sel), _gmx_sel_init_position(get((yyvsp[(3) - (3)].sel)), (yyvsp[(1) - (3)].str), scanner));
CHECK_SEL((yyval.sel));
END_ACTION;
#line 675 "parser.y"
{
BEGIN_ACTION;
- scoped_ptr_sfree nameGuard((yyvsp[(1) - (2)].str));
+ scoped_guard_sfree nameGuard((yyvsp[(1) - (2)].str));
set((yyval.param), SelectionParserParameter::create((yyvsp[(1) - (2)].str), get((yyvsp[(2) - (2)].vlist))));
END_ACTION;
}
#line 783 "parser.y"
{
BEGIN_ACTION;
- scoped_ptr_sfree stringGuard((yyvsp[(1) - (1)].str));
+ scoped_guard_sfree stringGuard((yyvsp[(1) - (1)].str));
set((yyval.val), SelectionParserValue::createString((yyvsp[(1) - (1)].str)));
END_ACTION;
}
#include "gmxpre.h"
}
%{
-#include "gromacs/utility/scoped_ptr_sfree.h"
+#include "gromacs/utility/scoped_cptr.h"
#include "parser_internal.h"
-using gmx::scoped_ptr_sfree;
+using gmx::scoped_guard_sfree;
using gmx::SelectionParserValue;
using gmx::SelectionParserValueList;
using gmx::SelectionParserValueListPointer;
| string
{
BEGIN_ACTION;
- scoped_ptr_sfree nameGuard($1);
+ scoped_guard_sfree nameGuard($1);
SelectionTreeElementPointer s
= _gmx_sel_init_group_by_name($1, scanner);
SelectionTreeElementPointer p
| string selection
{
BEGIN_ACTION;
- scoped_ptr_sfree nameGuard($1);
+ scoped_guard_sfree nameGuard($1);
set($$, _gmx_sel_init_selection($1, get($2), scanner));
END_ACTION;
}
| IDENTIFIER '=' sel_expr
{
BEGIN_ACTION;
- scoped_ptr_sfree nameGuard($1);
+ scoped_guard_sfree nameGuard($1);
set($$, _gmx_sel_assign_variable($1, get($3), scanner));
END_ACTION;
}
| IDENTIFIER '=' num_expr
{
BEGIN_ACTION;
- scoped_ptr_sfree nameGuard($1);
+ scoped_guard_sfree nameGuard($1);
set($$, _gmx_sel_assign_variable($1, get($3), scanner));
END_ACTION;
}
| IDENTIFIER '=' pos_expr
{
BEGIN_ACTION;
- scoped_ptr_sfree nameGuard($1);
+ scoped_guard_sfree nameGuard($1);
set($$, _gmx_sel_assign_variable($1, get($3), scanner));
END_ACTION;
}
sel_expr: num_expr CMP_OP num_expr
{
BEGIN_ACTION;
- scoped_ptr_sfree opGuard($2);
+ scoped_guard_sfree opGuard($2);
set($$, _gmx_sel_init_comparison(get($1), get($3), $2, scanner));
CHECK_SEL($$);
END_ACTION;
sel_expr: GROUP string
{
BEGIN_ACTION;
- scoped_ptr_sfree nameGuard($2);
+ scoped_guard_sfree nameGuard($2);
set($$, _gmx_sel_init_group_by_name($2, scanner));
END_ACTION;
}
sel_expr: pos_mod KEYWORD_GROUP
{
BEGIN_ACTION;
- scoped_ptr_sfree posmodGuard($1);
+ scoped_guard_sfree posmodGuard($1);
set($$, _gmx_sel_init_keyword($2, SelectionParserValueListPointer(), $1, scanner));
CHECK_SEL($$);
END_ACTION;
| pos_mod KEYWORD_STR basic_value_list
{
BEGIN_ACTION;
- scoped_ptr_sfree posmodGuard($1);
+ scoped_guard_sfree posmodGuard($1);
set($$, _gmx_sel_init_keyword_strmatch($2, gmx::eStringMatchType_Auto, get($3), $1, scanner));
CHECK_SEL($$);
END_ACTION;
| pos_mod KEYWORD_STR str_match_type basic_value_list
{
BEGIN_ACTION;
- scoped_ptr_sfree posmodGuard($1);
+ scoped_guard_sfree posmodGuard($1);
set($$, _gmx_sel_init_keyword_strmatch($2, $3, get($4), $1, scanner));
CHECK_SEL($$);
END_ACTION;
| pos_mod KEYWORD_NUMERIC basic_value_list
{
BEGIN_ACTION;
- scoped_ptr_sfree posmodGuard($1);
+ scoped_guard_sfree posmodGuard($1);
set($$, _gmx_sel_init_keyword($2, get($3), $1, scanner));
CHECK_SEL($$);
END_ACTION;
sel_expr: pos_mod METHOD_GROUP method_params
{
BEGIN_ACTION;
- scoped_ptr_sfree posmodGuard($1);
+ scoped_guard_sfree posmodGuard($1);
set($$, _gmx_sel_init_method($2, get($3), $1, scanner));
CHECK_SEL($$);
END_ACTION;
num_expr: pos_mod KEYWORD_NUMERIC %prec NUM_REDUCT
{
BEGIN_ACTION;
- scoped_ptr_sfree posmodGuard($1);
+ scoped_guard_sfree posmodGuard($1);
set($$, _gmx_sel_init_keyword($2, SelectionParserValueListPointer(), $1, scanner));
CHECK_SEL($$);
END_ACTION;
| pos_mod METHOD_NUMERIC method_params
{
BEGIN_ACTION;
- scoped_ptr_sfree posmodGuard($1);
+ scoped_guard_sfree posmodGuard($1);
set($$, _gmx_sel_init_method($2, get($3), $1, scanner));
CHECK_SEL($$);
END_ACTION;
| pos_mod KEYWORD_STR
{
BEGIN_ACTION;
- scoped_ptr_sfree posmodGuard($1);
+ scoped_guard_sfree posmodGuard($1);
set($$, _gmx_sel_init_keyword($2, SelectionParserValueListPointer(), $1, scanner));
CHECK_SEL($$);
END_ACTION;
pos_expr: KEYWORD_POS OF sel_expr %prec PARAM_REDUCT
{
BEGIN_ACTION;
- scoped_ptr_sfree keywordGuard($1);
+ scoped_guard_sfree keywordGuard($1);
set($$, _gmx_sel_init_position(get($3), $1, scanner));
CHECK_SEL($$);
END_ACTION;
PARAM value_list
{
BEGIN_ACTION;
- scoped_ptr_sfree nameGuard($1);
+ scoped_guard_sfree nameGuard($1);
set($$, SelectionParserParameter::create($1, get($2)));
END_ACTION;
}
| string %prec PARAM_REDUCT
{
BEGIN_ACTION;
- scoped_ptr_sfree stringGuard($1);
+ scoped_guard_sfree stringGuard($1);
set($$, SelectionParserValue::createString($1));
END_ACTION;
}
#include "gromacs/trajectoryanalysis/analysissettings.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/futil.h"
-#include "gromacs/utility/scoped_ptr_sfree.h"
+#include "gromacs/utility/scoped_cptr.h"
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/stringutil.h"
}
sfree(area);
}
- scoped_ptr_sfree dotsGuard(surfacedots);
+ scoped_guard_sfree dotsGuard(surfacedots);
if (retval != 0)
{
GMX_THROW(InternalError("nsc_dclm_pbc failed"));
#include "gromacs/utility/arrayref.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/gmxassert.h"
-#include "gromacs/utility/scoped_ptr_sfree.h"
+#include "gromacs/utility/scoped_cptr.h"
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/stringutil.h"
{
GMX_RELEASE_ASSERT(top_->hasTopology(),
"Topology should have been loaded or an error given earlier");
- t_atoms atoms;
+ t_atoms atoms;
atoms = top_->topology()->atoms;
- t_pdbinfo *pdbinfo;
+ t_pdbinfo *pdbinfo;
snew(pdbinfo, atoms.nr);
- scoped_ptr_sfree pdbinfoGuard(pdbinfo);
+ scoped_guard_sfree pdbinfoGuard(pdbinfo);
if (atoms.pdbinfo != NULL)
{
std::memcpy(pdbinfo, atoms.pdbinfo, atoms.nr*sizeof(*pdbinfo));
*/
/*! \libinternal \file
* \brief
- * Declares gmx::scoped_ptr_sfree.
+ * Declares gmx::scoped_cptr and gmx::scoped_guard_sfree.
*
* \author Teemu Murtola <teemu.murtola@gmail.com>
* \inlibraryapi
#ifndef GMX_UTILITY_SCOPED_PTR_SFREE_H
#define GMX_UTILITY_SCOPED_PTR_SFREE_H
+#include "config.h"
+
#include "gromacs/utility/common.h"
#include "gromacs/utility/smalloc.h"
namespace gmx
{
+//! sfree wrapper to be used as scoped_cptr deleter
+template <class T>
+inline void sfree_wrapper(T *p)
+{
+ sfree(p);
+}
+
/*! \libinternal \brief
- * Stripped-down version of scoped_ptr that uses sfree().
+ * Stripped-down version of scoped_ptr that uses sfree() or custom deleter.
*
- * Currently only implements constructor from a pointer value and destructor;
- * other operations can be added if they become necessary.
+ * Currently only implements some operations; other operations can be added
+ * if they become necessary.
*
- * This class provides a very basic guard/smart pointer for C pointers.
- * Currently, boost::shared_ptr is used in a few locations that require more
- * flexibility, but is not suitable for all cases either. A scoped_ptr with
- * deleter support would be a general enough implementation for all uses.
- * C++11 unique_ptr has this, but for non-C++11 support we need something else.
+ * This class provides a basic guard/smart pointer for C pointers.
*
* Methods in this class do not throw.
*
* \inlibraryapi
* \ingroup module_utility
*/
-class scoped_ptr_sfree
+template <class T, void D(T *) = sfree_wrapper>
+class scoped_cptr
{
public:
/*! \brief
*
* \param[in] ptr Pointer to use for initialization.
*/
- explicit scoped_ptr_sfree(void *ptr) : ptr_(ptr) {}
+ explicit scoped_cptr(T *ptr) : ptr_(ptr) {}
//! Frees the pointer passed to the constructor.
- ~scoped_ptr_sfree() { sfree(ptr_); }
+ ~scoped_cptr() { D(ptr_); }
+ //! Returns the stored pointer.
+ T * get() const { return ptr_; }
+ //! Check for non-null pointer in boolean context.
+#ifdef GMX_CXX11
+ explicit
+#endif
+ operator bool () const { return ptr_ != 0; }
private:
- void *ptr_;
+ T *ptr_;
- GMX_DISALLOW_COPY_AND_ASSIGN(scoped_ptr_sfree);
+ GMX_DISALLOW_COPY_AND_ASSIGN(scoped_cptr);
};
+//! Simple guard which calls sfree. See scoped_cptr for details.
+typedef scoped_cptr<void> scoped_guard_sfree;
+
} // namespace gmx
#endif