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

Go to the SVN repository for this file.

1 /* $Id: su_private.hpp 33815 2007-05-04 17:18:18Z 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 * Authors: Paul Thiessen
27 *
28 * File Description:
29 * private common stuff for alignment utility algorithms
30 *
31 * ===========================================================================
32 */
33 
34 #ifndef STRUCT_UTIL_PRIVATE__HPP
35 #define STRUCT_UTIL_PRIVATE__HPP
36 
37 #include <corelib/ncbistd.hpp>
38 #include <corelib/ncbiexpt.hpp>
39 
40 
41 BEGIN_SCOPE(struct_util)
42 
43 #define ERROR_MESSAGE(s) ERR_POST(ncbi::Error << "struct_util: " << s << '!')
44 #define WARNING_MESSAGE(s) ERR_POST(ncbi::Warning << "struct_util: " << s)
45 #define INFO_MESSAGE(s) ERR_POST(ncbi::Info << "struct_util: " << s)
46 #define TRACE_MESSAGE(s) ERR_POST(ncbi::Trace << "struct_util: " << s)
47 
48 #define THROW_MESSAGE(str) throw ncbi::CException(DIAG_COMPILE_INFO, NULL, ncbi::CException::eUnknown, (str))
49 
50 // utility function to remove some elements from a vector. Actually does this by copying to a new
51 // vector, so T should have an efficient copy ctor.
52 template < class T >
53 void VectorRemoveElements(std::vector < T >& v, const std::vector < bool >& remove, unsigned int nToRemove)
54 {
55  if (v.size() != remove.size()) {
56 #ifndef _DEBUG
57  // MSVC 6 gets internal compiler error here on debug builds... ugh!
58  ERROR_MESSAGE("VectorRemoveElements() - size mismatch");
59 #endif
60  return;
61  }
62 
63  std::vector < T > copy(v.size() - nToRemove);
64  unsigned int i, nRemoved = 0;
65  for (i=0; i<v.size(); ++i) {
66  if (remove[i])
67  ++nRemoved;
68  else
69  copy[i - nRemoved] = v[i];
70  }
71  if (nRemoved != nToRemove) {
72 #ifndef _DEBUG
73  ERROR_MESSAGE("VectorRemoveElements() - bad nToRemove");
74 #endif
75  return;
76  }
77 
78  v = copy;
79 }
80 
81 // utility function to delete all elements from an STL container
82 #define DELETE_ALL_AND_CLEAR(container, ContainerType) \
83 do { \
84  ContainerType::iterator i, ie = (container).end(); \
85  for (i=(container).begin(); i!=ie; ++i) \
86  delete *i; \
87  (container).clear(); \
88 } while (0)
89 
90 END_SCOPE(struct_util)
91 
92 #endif // STRUCT_UTIL_PRIVATE__HPP
Include a standard set of the NCBI C++ Toolkit most basic headers.
static void DLIST_NAME() remove(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
Definition: dlist.tmpl.h:90
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
int i
Defines NCBI C++ exception handling.
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Definition: njn_matrix.hpp:613
void VectorRemoveElements(std::vector< T > &v, const std::vector< bool > &remove, unsigned int nToRemove)
Definition: su_private.hpp:53
#define ERROR_MESSAGE(s)
Definition: su_private.hpp:43
Modified on Wed Apr 17 13:09:51 2024 by modify_doxy.py rev. 669887