CodeSonar C++ API
[For improved navigation, enable JavaScript.]
cs_directory_decl.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_DIRECTORY_DECL_HPP
17 #define CS_DIRECTORY_DECL_HPP
18 
19 #include "cs_directory.h"
20 #include "cs_directory_fwd.hpp"
21 #include "cs_ir_boilerplate.hpp"
22 #include "cs_sfile_decl.hpp"
23 
26 namespace cs{
27  class directory_children_iterator_policy_container{
28  directory_children_iterator_policy_container();
29  public:
30  cs_directory parent;
31  directory_children_iterator_policy_container(
32  cs_directory _parent)
33  : parent(_parent){}
34  };
35 
36  class directory_children_iterator_policy{
37  public:
38  typedef cs_directory_child_directory_iter iterator_impl;
39  typedef directory key;
40  typedef directory_children_iterator_policy_container ctype;
41 
42  static cs_result iter_first(
43  const ctype &container,
44  cglue<key>::ctype *val,
45  iterator_impl *it)
46  { return cs_directory_child_directory_iter_first( container.parent, val, it ); }
47  static cs_result iter_next(
48  const ctype &container,
49  cglue<key>::ctype *val,
50  iterator_impl *it)
51  { return cs_directory_child_directory_iter_next( val, it ); }
52  static cs_result iter_close(iterator_impl *it)
53  { return cs_directory_child_directory_iter_close( it ); }
54  static const char *name()
55  { return "directory_children_iterator"; }
56  };
57 
58  class directory_files_iterator_policy{
59  public:
60  typedef cs_directory_file_iter iterator_impl;
61  typedef sfile key;
62  typedef cs_directory ctype;
63 
64  static cs_result iter_first(
65  ctype container,
66  cglue<key>::ctype *val,
67  iterator_impl *it)
68  { return cs_directory_file_iter_first( container, val, it ); }
69  static cs_result iter_next(
70  ctype container,
71  cglue<key>::ctype *val,
72  iterator_impl *it)
73  { return cs_directory_file_iter_next( val, it ); }
74  static cs_result iter_close(iterator_impl *it)
75  { return cs_directory_file_iter_close( it ); }
76  static const char *name()
77  { return "directory_files_iterator"; }
78  };
79 
91  class directory{
97  CS_IR_BOILERPLATE(directory);
98 
116  csuint64 stable_hash() const
117  {
118  return cs_directory_stable_hash(inner);
119  }
120 
149  int stable_cmp(const directory& other) const
150  {
151  return cs_directory_stable_compare(inner, other.inner);
152  }
153 
161  directory_children_iterator_policy_container(inner)); }
162 
163 
168  size_t child_count() const
169  {
170  size_t rv;
171  check(cs_directory_child_directory_count(inner, &rv));
172  return rv;
173  }
174 
175 
182  { return directory_files_iterator(inner); }
183 
184 
189  size_t file_count() const
190  {
191  size_t rv;
192  check(cs_directory_file_count(inner, &rv));
193  return rv;
194  }
195 
196 
204  directory parent() const;
205 
206 
212  csuint32 depth() const;
213 
214 
221  std::string name() const
222  { return cs_directory_string(inner); }
223 
224 
239  std::string normalized_name() const
240  { return cs_directory_normalized_string(inner); }
241 
242 
244  std::string as_string() const
245  {
246 #if !CS_CPP_NO_EXCEPTIONS
247  try{
248 #endif
249  return name();
250 #if !CS_CPP_NO_EXCEPTIONS
251  }catch(result){
252  return "<unknown_directory>";
253  }
254 #endif
255  }
256 
258  std::string as_repr() const
259  { return CS_AS_REPR_FROM_STRING(directory); }
260  };
261  CS_IR_BOILERPLATE_FRIENDS_PLUS_OSTREAM(directory, cs)
262 }
264 #endif /* CS_DIRECTORY_DECL_HPP */
std::string name() const
Get the directory path associated with a directory.
Definition: cs_directory_decl.hpp:221
Namespace for CodeSonar/CodeSurfer API.
Definition: cs_ast.hpp:33
int stable_cmp(const directory &other) const
Comparison function for directory, with stable results across sufficiently-similar analyses...
Definition: cs_directory_decl.hpp:149
cs::directory_children_iterator_policy
Definition: cs_directory_decl.hpp:36
A directory.
Definition: cs_directory_decl.hpp:91
Iterator over the files (sfile) immediately contained in a directory (directory). ...
Definition: cs_tplt_instantiations.hpp:721
std::string as_repr() const
Get a representation of a directory object that includes information useful for debugging.
Definition: cs_directory_decl.hpp:263
directory_children_iterator children() const
Get an iterator over the immediate subdirectories (directory) of a directory.
Definition: cs_directory_decl.hpp:159
csuint32 depth() const
Get the depth or distance from root of a directory.
Definition: cs_directory.hpp:32
csuint64 stable_hash() const
Get a hash value for a directory, with stable results across sufficiently-similar analyses...
Definition: cs_directory_decl.hpp:116
size_t child_count() const
Get the number of subdirectories.
Definition: cs_directory_decl.hpp:168
directory parent() const
Get the parent directory of a directory.
Definition: cs_directory.hpp:25
cs::directory_files_iterator_policy
Definition: cs_directory_decl.hpp:58
std::string as_string() const
Get a simple string representation of a directory object.
Definition: cs_directory_decl.hpp:246
std::string normalized_name() const
Get the normalized directory path associated with a directory.
Definition: cs_directory_decl.hpp:239
A source file.
Definition: cs_sfile_decl.hpp:98
Iterator over the immediate subdirectories (directory) of a directory (directory).
Definition: cs_tplt_instantiations.hpp:687
The result of an API operation.
Definition: cs_result.hpp:50
directory_files_iterator files() const
Get an iterator over the source files (sfile) directly contained in a directory.
Definition: cs_directory_decl.hpp:181
size_t file_count() const
Get the number of files.
Definition: cs_directory_decl.hpp:189