CodeSonar C++ API
[For improved navigation, enable JavaScript.]
cs_result.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023, an unpublished work by CodeSecure, Inc.
3  * ALL RIGHTS RESERVED
4  *
5  * Copyright (c) 2013-2023, an unpublished work by GrammaTech, Inc.
6  * ALL RIGHTS RESERVED
7  *
8  * This software is furnished under a license and may be used and
9  * copied only in accordance with the terms of such license and the
10  * inclusion of the above copyright notice. This software or any
11  * other copies thereof may not be provided or otherwise made
12  * available to any other person. Title to and ownership of the
13  * software is retained by CodeSecure, Inc.
14  */
15 
16 #ifndef CS_RESULT_HPP
17 #define CS_RESULT_HPP
18 
19 #include "cs_sysutil.h"
20 #include "cs_enum_boilerplate.hpp"
21 #include "cs_std_includes.hpp"
22 #include "cs_api_defs.hpp"
23 
26 namespace cs{
27  // result not inheriting from std::exception is a deliberate
28  // decision; a cs::result potentially gets created in nearly every
29  // API call, and subclassing exception would more than double its
30  // size on 64-bit systems.
31  //
32  // (There is also an implementation complication: exception
33  // declares its destructor as throw(), so result would have a
34  // throw() destructor, and a class called SwigDirector_result
35  // inherits from result so its destructor would need to be
36  // throw(). But SwigDirector_result also inherits from Director,
37  // which (at least under our settings) does not have a throw()
38  // destructor, which means that SwigDirector_result cannot have a
39  // throw() destructor.)
40 
50  class result{
51  CS_ENUM_BOILERPLATE_UB(result, cs_result,
52  rv = cs_resolve_error(inner) + 3,
53  ((csuint64)CS_INTERNAL_ERROR_UNKNOWN)+1);
54 
55  public:
81  void check() const
82  { cs::check(inner); }
83 
85 
86  };
87 #ifndef CSFE_API
88  CS_ENUM_BOILERPLATE_FRIENDS(result,
89  friend class rpc_handler;
90  template <typename T>
91  friend class metric_function;
92  template <typename T>
93  friend class metric_granularity_policy;
94  friend void check(cs_result r);
95  template<typename T>
96  friend class set_mixin;
97  friend class xr_query_iterator_policy_container;
98  friend class derived_metric_compilation_error;
99  friend class warningclass;,
101  )
102 #else /* CSFE_API */
103  CS_ENUM_BOILERPLATE_FRIENDS(result,
104  friend void check(cs_result r);
105  friend void check(cs_result r, const char * file, unsigned line);,
106  cs
107  )
108 #endif /* CSFE_API */
109 #include "cs_result_defs.hpp"
110 
111 #ifndef SWIG
113  inline void check(cs_result r)
114  {
115  if( r != CS_SUCCESS )
116  {
117 #if CS_CPP_NO_EXCEPTIONS
118  cs_fatal( "Uncaught exception from CS C++ API: %s\n",
119  cs_resolve_error(r) + 3 );
120 #else
121  throw result::;
122 #endif
123  }
125  }
126 #endif
127 
128 #ifdef SWIGCSHARP
129  static std::string result_number_to_name(csint64 r)
130  {
131  result obj = result::from_integer(r);
132  return obj.name();
133  }
134 #endif
135 }
137 #endif /* CS_RESULT_HPP */
Handles remote procedure calls (RPCs).
Definition: csonar_visitor.hpp:430
Namespace for CodeSonar/CodeSurfer API.
Definition: cs_ast.hpp:33
cs::set_mixin
Definition: cs_set.hpp:30
static result from_integer(csint64 _inner)
Construct an instance from an integer representation.
Definition: cs_result.hpp:58
The result of an API operation.
Definition: cs_result.hpp:50
std::string name() const
Get the name of a result object.
Definition: cs_result.hpp:58
void check() const
Check this, throwing an exception or fatal error if it is not result::SUCCESS...
Definition: cs_result.hpp:86
The calculation function for a metric class.
Definition: cs_metric.hpp:510
A warning class.
Definition: csonar_warningclass.hpp:1353