NCBI C++ ToolKit
named_parameters.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: named_parameters.hpp 64296 2014-09-02 20:02:06Z kazimird $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Dmitry Kazimirov
27  *
28  * File Description: Support for named parameters in methods.
29  *
30  */
31 
32 
33 #ifndef CONNECT_SERVICES__NAMED_PARAMETERS_HPP
34 #define CONNECT_SERVICES__NAMED_PARAMETERS_HPP
35 
36 #include <corelib/ncbistd.hpp>
37 
39 
41 {
42 public:
43  CNamedParameterList(int tag, const CNamedParameterList* more_params) :
44  m_Tag(tag),
45  m_MoreParams(more_params)
46  {
47  }
48 
49  operator const CNamedParameterList*() const {return this;}
50 
52  const CNamedParameterList& more_params) const
53  {
54  more_params.m_MoreParams = this;
55  return more_params;
56  }
57 
58  bool Is(int tag) const {return m_Tag == tag;}
59 
60  int m_Tag;
62 };
63 
64 template <typename TYPE>
66 {
67 public:
68  CNamedParameterValue(int tag, const CNamedParameterList* more_params,
69  const TYPE& value) :
70  CNamedParameterList(tag, more_params),
71  m_Value(value)
72  {
73  }
74 
76 };
77 
78 template <typename TYPE, int TAG>
80 {
81 public:
82  class CValue : public CNamedParameterValue<TYPE>
83  {
84  public:
85  CValue(const TYPE& value,
86  const CNamedParameterList* more_params = NULL) :
87  CNamedParameterValue<TYPE>(TAG, more_params, value)
88  {
89  }
90  };
91 
93  {
94  return CValue(value);
95  }
96 };
97 
98 template <typename TYPE>
99 const TYPE& Get(const CNamedParameterList* param)
100 {
101  return static_cast<const CNamedParameterValue<TYPE>*>(param)->m_Value;
102 }
103 
105 
106 #endif /* CONNECT_SERVICES__NAMED_PARAMETERS_HPP */
const CNamedParameterList * m_MoreParams
const CNamedParameterList & operator,(const CNamedParameterList &more_params) const
bool Is(int tag) const
CNamedParameterList(int tag, const CNamedParameterList *more_params)
CNamedParameterValue(int tag, const CNamedParameterList *more_params, const TYPE &value)
CValue(const TYPE &value, const CNamedParameterList *more_params=NULL)
CValue operator=(const TYPE &value)
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define TYPE(s)
#define NULL
Definition: ncbistd.hpp:225
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
const TYPE & Get(const CNamedParameterList *param)
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
const char * tag
Modified on Wed May 22 11:32:30 2024 by modify_doxy.py rev. 669887