CodeSonar C++ API
[For improved navigation, enable JavaScript.]
cs_metric.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_METRIC_HPP
17 #define CS_METRIC_HPP
18 
19 #include "cs_metric.h"
20 #include "cs_project.hpp"
21 
28 namespace cs{
30 #if defined(SWIG) && defined(SWIGJAVA)
31 %typemap(javabase) cs::derived_metric_compilation_error "java.lang.Exception";
32 
33 %typemap(javacode) cs::derived_metric_compilation_error %{
34  public String getMessage() {
35  return toString();
36  }
37  static final long serialVersionUID = -6534235055391059766L;
38 %}
39 #endif
40 
44  class derived_metric_compilation_error{
45  friend class general_metric_manager;
46  std::string message;
47  std::string metric_def;
48  result res;
49  derived_metric_compilation_error(
50  cs_result r, const std::string &m, const std::string &p)
51  : message(m)
52  , metric_def(p)
53  , res(result::){}
54  public:
61  std::string get_metric_def() const
62  { return metric_def; }
63 
64 #if defined(SWIG) && defined(SWIGPYTHON)
65  %feature("shadow") as_string %{
66  def __str__(*args):
67  try:
68  return $action(*args)
69  except UnicodeDecodeError:
70  return repr(*args)%}
71 #endif
72 
74  std::string as_string() const
75  { return message; }
76 
78  std::string as_repr() const
79  { return CS_AS_REPR(derived_metric_compilation_error, metric_def); }
80 
82  CS_BOILERPLATE_HASH_TYPE hash() const
83  { return 1; }
84  };
85  CS_IR_BOILERPLATE_NONMEMBERS(derived_metric_compilation_error, cs)
86 
87 /* satisfy the one definiton rule by renaming some swig-generated stuff */
88 #if defined(SWIGCSHARP)
89 #define SwigDirector_metric_sfile_filter CSharp_SwigDirector_metric_sfile_filter
90 #elif defined(SWIGJAVA)
91 #define SwigDirector_metric_sfile_filter Java_SwigDirector_metric_sfile_filter
92 #elif defined(SWIGOCAML)
93 #define SwigDirector_metric_sfile_filter OCaml_SwigDirector_metric_sfile_filter
94 #endif
95 #if defined(SWIG) && defined(SWIGPYTHON)
96 %rename(_metric_sfile_filter) metric_sfile_filter;
97 #endif
98 
111  class metric_sfile_filter{
112  bool registered;
113  friend class general_metric_manager;
114  static cs_boolean cs_delegate_metric_filter(
115  cs_sf sf, void *ctx)
116  {
117  metric_sfile_filter *self
118  = static_cast<metric_sfile_filter*>(ctx);
119 #if !CS_CPP_NO_EXCEPTIONS
120  try{
121 #endif
122  return (*self)(sfile::);
123 #if !CS_CPP_NO_EXCEPTIONS
124  } SWIG_CATCH_DUMP_DIRECTOR_EXCEPTION(return true)
125  catch(...){
126  /* C can't unwind this, sorry! Catch it yourself
127  * inside operator() if you want. */
128  std::terminate();
129  return true;
130  }
131 #endif
132  }
133  public:
135  metric_sfile_filter()
136  : registered(false){}
137 
139  metric_sfile_filter(const metric_sfile_filter &)
140  : registered(false){}
141 #if defined(SWIG) && (defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGOCAML))
142  %rename(filter) operator();
143 #endif
144 
158  virtual bool operator()(sfile s) = 0;
159 
166  virtual ~metric_sfile_filter()
167  {
168  if( registered )
169  check(CS_ERROR_IMMUTABLE_DATA_STRUCTURE);
170  }
171  };
172 #if defined(SWIG) && defined(SWIGPYTHON)
173 SWIGPYTHON_CALLABLE_ADAPTER(_metric_sfile_filter)
174 
175 %pythoncode{
176  def metric_sfile_filter(filt):
177  general_metric_manager.set_metric_filter(_metric_sfile_filter_callable_adapter(filt))
178  return filt
179 }
180 #endif
181 
188  template <typename T>
189  class metric_manager{
190  metric_manager();
191  public:
203  static metric<T> lookup(const std::string &tag);
204 
205  DISOWN_PARAMETER(metric_function<T> *metric_func_ptr)
206 
207 
208 
238  static metric<T> create(metric_function<T> *metric_func_ptr,
239  const std::string &tag,
240  const std::string &desc);
241 
248  static iterator_adapter<metric_iterator_policy<T> > metrics();
249  };
250 
251 
254  class general_metric_manager{
255  general_metric_manager();
256 
257  static cs_sf unwrap_sfile(sfile i)
258  { return cglue<sfile>::unwrap(i); }
259 
260  class metric_wrapped_filter: public metric_sfile_filter{
261  cs_metric_should_use_file_fn_t fn;
262  void *ctx;
263  metric_wrapped_filter();
264  public:
265  metric_wrapped_filter(
266  cs_metric_should_use_file_fn_t _fn,
267  void *_ctx)
268  : fn(_fn)
269  , ctx(_ctx){}
270 
271  virtual bool operator()(sfile f)
272  { return !!fn(unwrap_sfile(f), ctx); }
273  };
274 
275  public:
276 DISOWN_PARAMETER(metric_sfile_filter *v)
286  static metric_sfile_filter *set_metric_filter(
287  metric_sfile_filter *v)
288  {
289  cs_metric_should_use_file_fn_t old;
290  void *old_ctx;
291  check(cs_metric_register_file_closure(
292  metric_sfile_filter::cs_delegate_metric_filter,
293  static_cast<void*>(v),
294  &old,
295  &old_ctx));
296  v->registered = true;
297  if( old )
298  return new metric_wrapped_filter(old, old_ctx);
299  return NULL;
300  }
301 #ifdef SWIG
302  %clear metric_sfile_filter *v;
303 #endif
304 
305 #if defined(SWIG) && defined(SWIGJAVA)
306 %javaexception("derived_metric_compilation_error") create_derived_metric {
307  try {
308  $action
309  }
310  catch (cs::derived_metric_compilation_error &e) {
311  jclass clazz = jenv->FindClass("com/codesecure/cs/derived_metric_compilation_error");
312  jobject obj = jenv->NewObject(
313  clazz,
314  jenv->GetMethodID(clazz, "<init>", "(JZ)V"),
315  (jlong)new cs::derived_metric_compilation_error(e),
316  (jboolean)1 );
317  jenv->Throw(static_cast<jthrowable>(obj));
318  return $null;
319  }
320 }
321 #endif
322 
401  static void create_derived_metric(
402  const std::string &defs)
403  {
404  const char *err_log = NULL;
405  cs_result r = cs_metric_create_derived(
406  defs.c_str(), &err_log );
407  if( r != CS_SUCCESS )
408  {
409 #if CS_CPP_NO_EXCEPTIONS
410  cs_fatal("Uncaught exception: derived_metric_compilation_error(`%s', `%s', `%s')\n",
411  cs_resolve_error(r) + 3, err_log, defs.c_str());
412 #else
413  throw derived_metric_compilation_error(r, err_log, defs);
414 #endif
415  }
416  }
417  };
418 
419 #ifdef SWIG
420  %template(project_metric_manager) metric_manager<project>;
421  %template(compunit_metric_manager) metric_manager<compunit>;
422  %template(sfile_metric_manager) metric_manager<sfile>;
423  %template(procedure_metric_manager) metric_manager<procedure>;
424 #endif
425 
426 #if defined(SWIGCSHARP)
427 #define SwigDirector_metric_function CSharp_SwigDirector_metric_function
428 #elif defined(SWIGJAVA)
429 #define SwigDirector_metric_function Java_SwigDirector_metric_function
430 #elif defined(SWIGOCAML)
431 #define SwigDirector_metric_function OCaml_SwigDirector_metric_function
432 #endif
433 
434 
509  template <typename T>
512  friend class metric_manager<T>;
513  friend class metric_granularity_policy<T>;
517  friend class metricclass_manager<T>;
518  friend class metricclass_granularity_policy<T>;
521  bool registered;
522  cs_result delegate(double *val, T elt)
523  {
524 #if !CS_CPP_NO_EXCEPTIONS
525  try{
526 #endif
527  *val = (*this)(elt);
528  return CS_SUCCESS;
529 #if !CS_CPP_NO_EXCEPTIONS
530  } catch(result &r) {
531  return cglue<result>::unwrap(r);
532  } SWIG_CATCH_DUMP_DIRECTOR_EXCEPTION_AND_EXTRACT_CS_RESULT(return res)
533  catch(...) {
534  /* C can't unwind this, sorry! Catch it yourself
535  * inside operator() if you want. */
536  std::terminate();
537  return CS_INTERNAL_ERROR_UNKNOWN;
538  }
539 #endif
540  }
541  public:
543  metric_function(): registered(false){}
544 
546  metric_function(const metric_function &): registered(false){}
547 #if defined(SWIG) && (defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGOCAML))
548  %rename(evaluate) operator();
549 #endif
550 
576  virtual double operator()(T) = 0;
577 
584  {
585  if( registered )
586  check(CS_ERROR_IMMUTABLE_DATA_STRUCTURE);
587  }
588  };
589 
590 #ifdef SWIG
591 #ifdef SWIGPYTHON
592 %define METFUNC_CALLABLE_ADAPTER(cls, T)
593 %template(cls) cs::metric_function<cs::T>;
594 SWIGPYTHON_CALLABLE_ADAPTER(cls)
595 %enddef
596 
597 %define METFUNC_DECORATOR(name, mgr, cls)
598 %pythoncode{
599  def name(*args):
600  if len(args) == 1 and callable(args[0]):
601  if len(args[0].__name__) >= 16:
602  raise ValueError('%s is too long a name for a metric tag' % args[0].__name__)
603  mgr.create(cls##_callable_adapter(args[0]), args[0].__name__,
604  args[0].__name__)
605  return args[0]
606  else:
607  if len(args) == 1:
608  def name##_inner(func):
609  mgr.create(cls##_callable_adapter(func), args[0], args[0])
610  return func
611  else:
612  def name##_inner(func):
613  mgr.create(cls##_callable_adapter(func), *args)
614  return func
615  return name##_inner
616 }
617 %enddef
618 
619 METFUNC_CALLABLE_ADAPTER(_project_metric_function, project)
620 METFUNC_CALLABLE_ADAPTER(_compunit_metric_function, compunit)
621 METFUNC_CALLABLE_ADAPTER(_sfile_metric_function, sfile)
622 METFUNC_CALLABLE_ADAPTER(_procedure_metric_function, procedure)
623 
624 METFUNC_DECORATOR(project_metric_function, project_metric_manager, _project_metric_function)
625 METFUNC_DECORATOR(compunit_metric_function, compunit_metric_manager, _compunit_metric_function)
626 METFUNC_DECORATOR(sfile_metric_function, sfile_metric_manager, _sfile_metric_function)
627 METFUNC_DECORATOR(procedure_metric_function, procedure_metric_manager, _procedure_metric_function)
628 #else
629  %template(project_metric_function) metric_function<project>;
630  %template(compunit_metric_function) metric_function<compunit>;
631  %template(sfile_metric_function) metric_function<sfile>;
632  %template(procedure_metric_function) metric_function<procedure>;
633 #endif
634 #endif
635 
638  template<>
639  class metric_granularity_policy<project>{
640  friend class metric_manager<project>;
641  friend class metric_iterator_policy<project>;
642  friend class metric<project>;
643  static cs_result delegate(double *val, const void *ctx)
644  {
645  metric_function<project> *func
646  = static_cast<metric_function<project>*>(
647  const_cast<void*>(ctx));
648  return func->delegate(val, cs::project::current());
649  }
650 
651  static double value(cs_metric m, project p)
652  {
653  double rv;
654  check(cs_metric_getvalue_analysis(
655  m, &rv));
656  return rv;
657  }
658 
659  static cs_metric create(const char *tag, const char *desc,
660  metric_function<project> *func)
661  {
662  cs_metric m;
663  check(cs_metric_create_analysis(
664  tag, desc,
665  delegate,
666  static_cast<void*>(func),
667  &m));
668  return m;
669  }
670 
671  static cs_metric_granularity granularity()
672  { return csmetric_analysis; }
673 
674  static const char *name()
675  { return "project"; }
676  };
677 
678  template<>
679  class metric_granularity_policy<compunit>{
680  friend class metric_manager<compunit>;
681  friend class metric_iterator_policy<compunit>;
682  friend class metric<compunit>;
683  static cs_result delegate(
684  cglue<compunit>::ctype elt,
685  double *val, const void *ctx)
686  {
687  metric_function<compunit> *func
688  = static_cast<metric_function<compunit>*>(
689  const_cast<void*>(ctx));
690  return func->delegate(val, compunit::);
691  }
692 
693  static double value(cs_metric m, compunit p)
694  {
695  double rv;
696  check(cs_metric_getvalue_compunit(
697  m, cglue<compunit>::unwrap(p), &rv));
698  return rv;
699  }
700 
701  static cs_metric create(const char *tag, const char *desc,
702  metric_function<compunit> *func)
703  {
704  cs_metric m;
705  check(cs_metric_create_compunit(
706  tag, desc,
707  delegate,
708  static_cast<void*>(func),
709  &m));
710  return m;
711  }
712 
713  static cs_metric_granularity granularity()
714  { return csmetric_compunit; }
715 
716  static const char *name()
717  { return "compunit"; }
718  };
719 
720  template<>
721  class metric_granularity_policy<sfile>{
722  friend class metric_manager<sfile>;
723  friend class metric_iterator_policy<sfile>;
724  friend class metric<sfile>;
725  static cs_result delegate(
726  cglue<sfile>::ctype elt,
727  double *val, const void *ctx)
728  {
729  metric_function<sfile> *func
730  = static_cast<metric_function<sfile>*>(
731  const_cast<void*>(ctx));
732  return func->delegate(val, sfile::);
733  }
734 
735  static double value(cs_metric m, sfile p)
736  {
737  double rv;
738  check(cs_metric_getvalue_file(
739  m, cglue<sfile>::unwrap(p), &rv));
740  return rv;
741  }
742 
743  static cs_metric create(const char *tag, const char *desc,
744  metric_function<sfile> *func)
745  {
746  cs_metric m;
747  check(cs_metric_create_file(
748  tag, desc,
749  delegate,
750  static_cast<void*>(func),
751  &m));
752  return m;
753  }
754 
755  static cs_metric_granularity granularity()
756  { return csmetric_file; }
757 
758  static const char *name()
759  { return "sfile"; }
760  };
761 
762  template<>
763  class metric_granularity_policy<procedure>{
764  friend class metric_manager<procedure>;
765  friend class metric_iterator_policy<procedure>;
766  friend class metric<procedure>;
767  static cs_result delegate(
768  cglue<procedure>::ctype elt,
769  double *val, const void *ctx)
770  {
771  metric_function<procedure> *func
772  = static_cast<metric_function<procedure>*>(
773  const_cast<void*>(ctx));
774  return func->delegate(val, procedure::);
775  }
776 
777  static double value(cs_metric m, procedure p)
778  {
779  double rv;
780  check(cs_metric_getvalue_procedure(
781  m, cglue<procedure>::unwrap(p), &rv));
782  return rv;
783  }
784 
785  static cs_metric create(const char *tag, const char *desc,
786  metric_function<procedure> *func)
787  {
788  cs_metric m;
789  check(cs_metric_create_procedure(
790  tag, desc,
791  delegate,
792  static_cast<void*>(func),
793  &m));
794  return m;
795  }
796 
797  static cs_metric_granularity granularity()
798  { return csmetric_procedure; }
799 
800  static const char *name()
801  { return "procedure"; }
802  };
803 
804  CS_NODEFCTOR_TYPE(metric)
805  template<typename T>
806  class cglue<metric<T> >
807  {
808  public:
809  typedef cs_metric ctype;
810  typedef metric<T> type;
811  private:
812  friend class metric_manager<T>;
813  friend class metricclass_manager<T>;
814  friend class metricclass<T>;
815  friend class iterator_adapter<metric_iterator_policy<T> >;
816  friend class metric_dependency_result;
817  friend class metric<T>;
818  friend class scratchpad<metric<T> >;
819  friend class metric_iterator_policy<T>;
820  cglue();
821  static int ccmp(const ctype &a, const ctype &b)
822  { return cs_metric_compare(a, b); }
823  static int chash(const ctype &a)
824  { return cs_metric_hash(a); }
825  CS_CXX_API_CGLUE_ACCESS_MODIFIER:
826  static type wrap(const ctype &c)
827  { return type(c); }
828  static ctype unwrap(const type &c)
829  { return c.unwrap(); }
830  };
831 
832 
841  class metric_dependency_result{
842  public:
850  std::vector<metric<procedure> > get_procedure_metrics() const
851  { return procedure_metrics; }
852 
860  std::vector<metric<sfile> > get_sfile_metrics() const
861  { return sfile_metrics; }
862 
870  std::vector<metric<compunit> > get_compunit_metrics() const
871  { return compunit_metrics; }
872 
880  std::vector<metric<project> > get_project_metrics() const
881  { return project_metrics; }
882 
883  private:
892  void print( std::ostream & s ) const
893  {
894  s << "procedure {";
895  _as_string( procedure_metrics, s );
896  s << "}, sfile {";
897  _as_string( sfile_metrics, s );
898  s << "}, compunit {";
899  _as_string( compunit_metrics, s );
900  s << "}, project {";
901  _as_string( project_metrics, s );
902  s << "}";
903  }
904 
905  NOTSWIG(friend std::ostream &operator<<( std::ostream &out,
906  const metric_dependency_result &a ));
907  public:
908 
910  std::string as_string() const
911  {
912  std::stringstream rv;
913  print( rv );
914  return rv.str();
915  }
916 
918  std::string as_repr() const
919  {
920  std::stringstream buf;
921  buf << CS_AS_REPR_PREFIX
922  << "metric_dependency_result ";
923  print(buf);
924  buf << CS_AS_REPR_SUFFIX;
925  return buf.str();
926  }
927 
928  friend class metric<project>;
929  friend class metric<compunit>;
930  friend class metric<sfile>;
931  friend class metric<procedure>;
932  private:
933  template<typename T>
934  void _as_string( const T & v, std::ostream & s ) const
935  {
936  for( typename T::const_iterator i = v.begin(); i != v.end(); i++ )
937  {
938  if( i != v.begin() )
939  s << ", ";
940  s << i->as_string();
941  }
942  }
943 
944  metric_dependency_result();
945  metric_dependency_result( cs_metric m );
946 
947  std::vector<metric<procedure> > procedure_metrics;
948  std::vector<metric<sfile> > sfile_metrics;
949  std::vector<metric<compunit> > compunit_metrics;
950  std::vector<metric<project> > project_metrics;
951  };
952 
962  inline std::ostream &operator<<( std::ostream &out,
963  const metric_dependency_result &a )
964  {
965  a.print(out);
966  return out;
967  }
968 
996  template <typename T>
997  class metric{
998 
1004  CS_IR_BOILERPLATE_TYPENAME(metric);
1005 
1007  std::string as_string() const
1008  { return cs_metric_tag( inner ); }
1009 
1011  std::string as_repr() const
1012  { return CS_AS_REPR_FROM_STRING(metric); }
1013 
1014 
1021  std::string tag() const
1022  { return cs_metric_tag( inner ); }
1023 
1024 
1031  std::string description() const
1032  {
1033  const char *rv = cs_metric_description( inner );
1034  if( !rv )
1035  return "";
1036  return rv;
1037  }
1038 
1053  double value(T elt) const
1054  { return metric_granularity_policy<T>::value(inner, elt); }
1055 
1056 
1064  metric_dependency_result get_dependencies() const
1065  { return metric_dependency_result( inner ); }
1066  };
1067 
1068 #ifdef SWIG
1069  %template(project_metric) metric<project>;
1070  %template(compunit_metric) metric<compunit>;
1071  %template(sfile_metric) metric<sfile>;
1072  %template(procedure_metric) metric<procedure>;
1073 } // end cs::
1074 
1075  %template(procedure_metric_vector) std::vector<cs::metric<procedure> >;
1076  %template(sfile_metric_vector) std::vector<cs::metric<sfile> >;
1077  %template(compunit_metric_vector) std::vector<cs::metric<compunit> >;
1078  %template(project_metric_vector) std::vector<cs::metric<project> >;
1079 
1080 namespace cs{
1081 #endif
1082 
1083  template<typename T>
1084  class metric_iterator_policy{
1085  public:
1086  typedef cs_metric_iterator iterator_impl;
1087  typedef metric<T> key;
1088  typedef char ctype;
1089 
1090  static cs_result iter_first(
1091  ctype container,
1092  typename cglue<key>::ctype *val,
1093  iterator_impl *it)
1094  { return cs_metric_iter_first(
1095  metric_granularity_policy<T>::granularity(),
1096  val, it ); }
1097  static cs_result iter_next(
1098  ctype container,
1099  typename cglue<key>::ctype *val,
1100  iterator_impl *it)
1101  { return cs_metric_iter_next( val, it ); }
1102  static cs_result iter_close(iterator_impl *it)
1103  { return cs_metric_iter_close( it ); }
1104  static std::string name()
1105  { return std::string(metric_granularity_policy<T>::name())
1106  + std::string("metric_iterator"); }
1107  };
1108 
1109 #ifdef SWIG
1110  %template() metric_iterator_policy<project>;
1111  %template() metric_iterator_policy<compunit>;
1112  %template() metric_iterator_policy<sfile>;
1113  %template() metric_iterator_policy<procedure>;
1114 #endif
1115 
1116  NOT_SWIG_BUILD_ONLY(
1120  template<typename T>
1121  inline bool operator==(const metric<T>& a, const metric<T>& b)
1122  { return a.cmp(b) == 0; }
1123 
1127  template<typename T>
1128  inline bool operator!=(const metric<T>& a, const metric<T>& b)
1129  { return a.cmp(b) != 0; }
1130 
1134  template<typename T>
1135  inline bool operator<(const metric<T>& a, const metric<T>& b)
1136  { return a.cmp(b) < 0; }
1137 
1141  template<typename T>
1142  inline bool operator<=(const metric<T>& a, const metric<T>& b)
1143  { return a.cmp(b) <= 0; }
1144 
1148  template<typename T>
1149  inline bool operator>(const metric<T>& a, const metric<T>& b)
1150  { return a.cmp(b) > 0; }
1151 
1155  template<typename T>
1156  inline bool operator>=(const metric<T>& a, const metric<T>& b)
1157  { return a.cmp(b) >= 0; } )
1158 
1168  template<typename T>
1169  inline std::ostream &operator<<( std::ostream &out, const metric<T> &a )
1170  {
1171  return out << CS_AS_REPR_PREFIX << "metric "
1172  << metric_granularity_policy<T>::name()
1173  << a.as_string() << CS_AS_REPR_SUFFIX;
1174  }
1175 
1176  template <typename T>
1177  inline metric<T> metric_manager<T>::lookup(
1178  const std::string &tag)
1179  {
1180  cs_metric m;
1181  check(cs_metric_get(
1182  tag.c_str(),
1183  metric_granularity_policy<T>::granularity(),
1184  &m));
1185  return cglue<metric<T> >::wrap(m);
1186  }
1187 
1188  template <typename T>
1189  inline metric<T> metric_manager<T>::create(
1190  metric_function<T> *metric_func_ptr,
1191  const std::string &tag,
1192  const std::string &desc )
1193  {
1194  metric<T> rv(
1195  cglue<metric<T> >::wrap(
1196  metric_granularity_policy<T>::create(tag.c_str(),
1197  desc.size()
1198  ? desc.c_str() : NULL,
1199  metric_func_ptr)));
1200  metric_func_ptr->registered = true;
1201  return rv;
1202  }
1203 
1204  template <typename T>
1205  inline iterator_adapter<metric_iterator_policy<T> >
1206  metric_manager<T>::metrics()
1207  {
1208  return iterator_adapter<metric_iterator_policy<T> >(
1209  /* template demands a container */42);
1210  }
1211 
1212 
1213  inline metric_dependency_result::metric_dependency_result( cs_metric m )
1214  {
1215  typedef scratchpad<metric<procedure> > sp;
1216  cs_size_t i, cardinality;
1217 
1218  sp::to_vector_functor2 <metric<procedure>,
1219  const void*,
1220  cs_metric_get_dependencies> functor(m, NULL);
1221  check( sp::execute( functor, cardinality ) );
1222  cs_metric *deps = sp::data();
1223  for( i = 0; i < cardinality; i++ )
1224  {
1225  cs_metric dep = deps[i];
1226  switch( cs_metric_get_granularity( dep ) )
1227  {
1228  case csmetric_procedure:
1229  procedure_metrics.push_back( cglue<metric<procedure> >::wrap( dep ) );
1230  break;
1231  case csmetric_file:
1232  sfile_metrics.push_back( cglue<metric<sfile> >::wrap( dep ) );
1233  break;
1234  case csmetric_compunit:
1235  compunit_metrics.push_back( cglue<metric<compunit> >::wrap( dep ) );
1236  break;
1237  case csmetric_analysis:
1238  project_metrics.push_back( cglue<metric<project> >::wrap( dep ) );
1239  break;
1240  default:
1241  break;
1242  }
1243  }
1244  }
1246 }
1247 
1248 #endif /* CS_METRIC_HPP */
Namespace for CodeSonar/CodeSurfer API.
Definition: cs_ast.hpp:33
metric_function()
Constructor.
Definition: cs_metric.hpp:543
cs::metricclass_granularity_policy
Definition: cs_types.hpp:377
std
Definition: cs_ast_decl.hpp:67
cs::metricclass_manager
Manages the metric classes of granularity T (metricclass<T>) for an analysis.
Definition: cs_iterator_adapter.hpp:47
virtual ~metric_function()
Destructor.
Definition: cs_metric.hpp:583
The result of an API operation.
Definition: cs_result.hpp:50
static project current()
Get the currently-loaded project.
Definition: cs_project.hpp:447
metric_function(const metric_function &)
Copy constructor.
Definition: cs_metric.hpp:546
The calculation function for a metric class.
Definition: cs_metric.hpp:510