CodeSonar C++ API
[For improved navigation, enable JavaScript.]
cs_utility.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_UTILITY_HPP
17 #define CS_UTILITY_HPP
18 
19 #include "cs_utility.h"
20 #include "cs_scratchpad.hpp"
21 
24 namespace cs{
29  class csurf_info{
30  private:
31  csurf_info();
32  public:
33 
42  static std::string version()
43  { return cs_version(); }
44 
45  /* /usr/include/sys/sysmacros.h #define's "major", so we
46  * suffix these with _ver to avoid conflict.
47  */
56  static int major_version()
57  { return cs_major_version(); }
58 
67  static int minor_version()
68  { return cs_minor_version(); }
69 
77  static int patch_version()
78  { return cs_patch_version(); }
79 
80  /* csurf_install_prefix intentionally not lifted because it is
81  * confusing -- users will expect+want this more general
82  * function:
83  */
90  static std::string install_path()
91  { return cs_codesecure_home_directory(); }
92 
110  static std::vector<std::string> startup_argv() {
111  std::vector<std::string> ans;
112  for (cs_const_string const* argv = cs_get_startup_argv();
113  *argv;
114  ++argv)
115  {
116  ans.push_back(*argv);
117  }
118  return ans;
119  }
120 
121  };
122 
124  class sysinfo{
125  private:
126  sysinfo();
127  public:
128 
140  static std::string user_name()
141  {
142  string_scratchpad::
143  to_string_functor0_limit<cs_get_user_name>
144  functor(-1);
145  return string_scratchpad::to_string(functor);
146  }
147 
159  static std::string machine_name()
160  {
161  string_scratchpad::
162  to_string_functor0_limit<cs_get_machine_name>
163  functor(-1);
164  return string_scratchpad::to_string(functor);
165  }
166  };
167 
168 
174  object_pager();
175  public:
176 
188  static void flush()
189  { cs_flush_managed_objects(); }
190 
191 
211  static void set_capacity(size_t s)
212  { cs_set_resident_capacity(s); }
213 
221  static size_t get_capacity()
222  { return cs_get_resident_capacity(); }
223 
224 
241  static void set_io_buffer_capacity(size_t s)
242  { cs_set_io_buffer_capacity(s); }
243 
244 
252  { return cs_get_io_buffer_capacity_pending(); }
253 
254 
266  {
267  size_t rv;
268  check(cs_get_io_buffer_capacity_current(&rv));
269  return rv;
270  }
271  };
272 
286  inline csuint64 string_hash(const std::string &s)
287  { return cs_bytes_hash(s.c_str(), s.size()); }
288 
314  inline std::string xmlencode(const std::string &s,
315  bool use_private_use_area = true)
316  { return cs_xmlencode_string(s.data(), s.size(), use_private_use_area); }
328  inline std::string xmldecode(const std::string &s)
329  { return cs_xmldecode_string(s.c_str()); }
331 }
332 
333 #endif /* CS_UTILITY_HPP */
Management for IO buffering.
Definition: cs_utility.hpp:173
Namespace for CodeSonar/CodeSurfer API.
Definition: cs_ast.hpp:33
static void set_capacity(size_t s)
Alter the number of bytes of managed objects that can be kept in memory.
Definition: cs_utility.hpp:211
static size_t get_current_io_buffer_capacity()
Get the number of bytes currently allocated for IO buffering.
Definition: cs_utility.hpp:265
static void set_io_buffer_capacity(size_t s)
Set the number of bytes to allocate for IO buffering.
Definition: cs_utility.hpp:241
static std::string install_path()
Retrieve the file system path for the CodeSecure installation.
Definition: cs_utility.hpp:90
Information about the CodeSurfer installation.
Definition: cs_utility.hpp:29
static std::string machine_name()
Get the user name of the current machine.
Definition: cs_utility.hpp:159
csuint64 string_hash(const std::string &s)
Get a hash of a std::string.
Definition: cs_utility.hpp:286
static std::vector< std::string > startup_argv()
Get the argv array used to start the process hosting the plugin.
Definition: cs_utility.hpp:110
std::string xmlencode(const std::string &s, bool use_private_use_area=true)
XML-encode a std::string.
Definition: cs_utility.hpp:314
static std::string user_name()
Get the user name of the current user.
Definition: cs_utility.hpp:140
static std::string version()
Get the CodeSurfer version number for the current installation.
Definition: cs_utility.hpp:42
static int patch_version()
Get the patch number for the current CodeSurfer installation.
Definition: cs_utility.hpp:77
static size_t get_pending_io_buffer_capacity()
Get the IO buffer capacity specified in the last set_io_buffer_capacity() call.
Definition: cs_utility.hpp:251
static int minor_version()
Get the minor part of the CodeSurfer version number for the current installation. ...
Definition: cs_utility.hpp:67
static int major_version()
Get the major part of the CodeSurfer version number for the current installation. ...
Definition: cs_utility.hpp:56
std::string xmldecode(const std::string &s)
XML-decode a std::string.
Definition: cs_utility.hpp:328
static void flush()
Flush managed objects to disk.
Definition: cs_utility.hpp:188
static size_t get_capacity()
Get the number of bytes of managed objects that can be kept in memory.
Definition: cs_utility.hpp:221
Information about the local system.
Definition: cs_utility.hpp:124