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

Go to the SVN repository for this file.

1 /*
2 * $Id: IntronChain.hpp 38776 2008-07-30 17:34:37Z ucko $
3 *
4 * =========================================================================
5 *
6 * PUBLIC DOMAIN NOTICE
7 * National Center for Biotechnology Information
8 *
9 * This software/database is a "United States Government Work" under the
10 * terms of the United States Copyright Act. It was written as part of
11 * the author's official duties as a United States Government employee and
12 * thus cannot be copyrighted. This software/database is freely available
13 * to the public for use. The National Library of Medicine and the U.S.
14 * Government have not placed any restriction on its use or reproduction.
15 *
16 * Although all reasonable efforts have been taken to ensure the accuracy
17 * and reliability of the software and data, the NLM and the U.S.
18 * Government do not and cannt warrant the performance or results that
19 * may be obtained by using this software or data. The NLM and the U.S.
20 * Government disclaim all warranties, express or implied, including
21 * warranties of performance, merchantability or fitness for any particular
22 * purpose.
23 *
24 * Please cite the author in any work or product based on this material.
25 *
26 * =========================================================================
27 *
28 * Author: Boris Kiryutin
29 *
30 * =========================================================================
31 */
32 
33 
34 #ifndef INTRON_CHAIN_H
35 #define INTRON_CHAIN_H
36 
37 #include <corelib/ncbistl.hpp>
38 #include <stdexcept> // runtime_error
39 
41 BEGIN_SCOPE(prosplign)
42 
43 // CIgapIntron represents intron or gap at the beg/end
44 //in intron chain
46 {
47 public:
48  CIgapIntron() : m_Beg(0), m_Len(0), ref_counter(1) {}
49 
50  void Init(int beg, int len)
51  {
52  m_Beg = beg;
53  m_Len = len;
54  ref_counter = 1;
55  }
56 
57  int m_Beg;//coord of the beginning, 0 - based
58  int m_Len;
59  CIgapIntron* m_Prev;//previous in chain
60 
61 private:
63 
64  friend class CIgapIntronChain;
65 };
66 
67 template <class C>
68 class CObjectPool {
69 public:
71  {
72  }
74  {
75 #ifdef _DEBUG
76  LOG_POST( Info << "pool size = " << m_Chunks.size()*m_ChunkSize );
77  size_t free_obj_count = 0;
78  while (m_Free) {
79  ++free_obj_count;
80  m_Free = m_Free->m_Prev;
81  }
82  _ASSERT( free_obj_count == m_Chunks.size()*m_ChunkSize );
83 #endif
84  ITERATE( typename vector<C*>, i, m_Chunks ) {
85  delete[] (*i);
86  }
87  }
88 
90  {
91  if (m_Free == NULL)
92  GetNewChunk();
93 
94  C* res = m_Free;
95  m_Free = res->m_Prev;
96 
97  return res;
98  }
99  void PutObject(C* object)
100  {
101  object->m_Prev = m_Free;
102  m_Free = object;
103  }
104 
105 private:
106  void GetNewChunk()
107  {
108  C* next = new C[m_ChunkSize];
109  m_Chunks.push_back(next);
110  for (size_t i = 0; i < m_ChunkSize; ++i) {
111  next->m_Prev = m_Free;
112  m_Free = next;
113  ++next;
114  }
115  }
116 
117  size_t m_ChunkSize;
118  vector<C*> m_Chunks;
120 
121 };
122 
124 
126 {
127 public:
130  void SetPool(CIgapIntronPool& pool) {
131  m_Pool = &pool;
132  }
133  inline void Creat(int beg, int len)
134  {
135  m_Top = m_Pool->GetObject();
136  m_Top->Init(beg,len);
137  m_Top->m_Prev = NULL;
138  }
139  inline void Expand(CIgapIntronChain& source, int beg, int len)
140  {
141  Copy(source);
142  CIgapIntron* tmp = m_Top;
143  m_Top = m_Pool->GetObject();
144  m_Top->Init(beg,len);
145  m_Top->m_Prev = tmp;
146  }
147  inline void Copy(CIgapIntronChain& source) {
148  if (m_Top != source.m_Top) {
149  m_Top = source.m_Top;
150  ++m_Top->ref_counter;
151  }
152  }
153  inline void Clear() {
154  while (m_Top && --m_Top->ref_counter < 1) {
157  m_Top = prev;
158  }
159  m_Top = NULL;
160  }
161 
162  CIgapIntron* m_Top;//top of the chain, i.e. last intron
163 
164 private:
166 
167 private:
170 /*
171  inline CIgapIntronChain& operator=(const CIgapIntronChain& source)
172  {
173  if(source.m_Top) throw runtime_error("Copying of non-empty intron chain");
174  Clear();
175  return *this;
176  }
177  inline CIgapIntronChain(const CIgapIntronChain& source)
178  {
179  if(source.m_Top) throw runtime_error("Copying of non-empty intron chain");
180  m_Top = source.m_Top;
181  }
182 */
183 
184 };
185 
186 
187 END_SCOPE(prosplign)
189 
190 #endif //INTRON_CHAIN_H
CObjectPool< CIgapIntron > CIgapIntronPool
CIgapIntron * m_Top
CIgapIntronChain(const CIgapIntronChain &source)
void Expand(CIgapIntronChain &source, int beg, int len)
void Creat(int beg, int len)
void SetPool(CIgapIntronPool &pool)
CIgapIntronPool * m_Pool
CIgapIntronChain & operator=(const CIgapIntronChain &source)
void Copy(CIgapIntronChain &source)
CIgapIntron * m_Prev
Definition: IntronChain.hpp:59
void Init(int beg, int len)
Definition: IntronChain.hpp:50
void PutObject(C *object)
Definition: IntronChain.hpp:99
vector< C * > m_Chunks
size_t m_ChunkSize
CObjectPool(size_t chunk_size=10000)
Definition: IntronChain.hpp:70
C * GetObject()
Definition: IntronChain.hpp:89
void GetNewChunk()
static const int chunk_size
#define C(s)
Definition: common.h:231
static DLIST_TYPE *DLIST_NAME() prev(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
Definition: dlist.tmpl.h:61
static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
Definition: dlist.tmpl.h:56
static char tmp[3200]
Definition: utf8.c:42
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
int i
int len
const CharType(& source)[N]
Definition: pointer.h:1149
The NCBI C++/STL use hints.
#define _ASSERT
Modified on Sat May 25 14:21:46 2024 by modify_doxy.py rev. 669887