Caffa  1.1.0
C++ Application Framework for Embedded Systems with introspection
cafMethodInitHelper.h
1 // ##################################################################################################
2 //
3 // CAFFA
4 // Copyright (C) 2024- Kontur AS
5 //
6 // GNU Lesser General Public License Usage
7 // This library is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation; either version 2.1 of the License, or
10 // (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
17 // for more details.
18 //
19 // ##################################################################################################
20 #pragma once
21 
22 #include "cafMethod.h"
23 
24 #include <concepts>
25 #include <memory>
26 
27 namespace caffa
28 {
29 
30 template <typename MethodType>
31 concept DerivesFromMethodHandle = std::is_base_of<MethodHandle, MethodType>::value;
36 template <DerivesFromMethodHandle MethodType>
38 {
39 public:
40  MethodInitHelper( MethodType& method, const std::string& keyword )
41  : m_method( method )
42  , m_keyword( keyword )
43  {
44  }
45 
52  MethodInitHelper& withDoc( const std::string& documentation )
53  {
54  m_method.setDocumentation( documentation );
55  return *this;
56  }
57 
64  MethodInitHelper& withArgumentNames( const std::vector<std::string>& argumentNames )
65  {
66  m_method.setArgumentNames( argumentNames );
67  return *this;
68  }
69 
77  {
78  m_method.setConst( true );
79  return *this;
80  }
81 
82 private:
83  MethodInitHelper() = delete;
84  MethodInitHelper( const MethodInitHelper& ) = delete;
85  MethodInitHelper( MethodInitHelper&& ) = delete;
86 
87  MethodInitHelper& operator=( const MethodInitHelper& ) = delete;
88  MethodInitHelper& operator=( MethodInitHelper&& ) = delete;
89 
90  MethodType& m_method;
91  const std::string& m_keyword;
92 };
93 } // namespace caffa
MethodInitHelper & makeConst()
Make the method a const method that cannot alter values Analoguous to a regular const object method...
Definition: cafMethodInitHelper.h:76
MethodInitHelper & withDoc(const std::string &documentation)
Apply documentation.
Definition: cafMethodInitHelper.h:52
MethodInitHelper & withArgumentNames(const std::vector< std::string > &argumentNames)
Set argument names. Required for positional arguments.
Definition: cafMethodInitHelper.h:64
Definition: cafMethodInitHelper.h:37
Main Caffa namespace.
Definition: cafApplication.h:30