UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ikp1dlayers.hpp
1 /* ikp1dlayer.hpp */
2 /* $Id: ikp1dlayers.hpp,v 1.3 2008/04/25 11:16:52 urij Exp $ */
3 #ifndef __ikp1dlayers_hpp
4 #define __ikp1dlayers_hpp
5 
6 #include <vector>
7 #include <string>
8 
9 #include <mix/u_message.hpp>
10 
11 using namespace std;
12 
16 template <class T>
18 {
19 public:
20 
22  IKP1dLayers (string name = "IKP1dLayers") {
23  m_name = name;
24  }
25 
27  IKP1dLayers (const IKP1dLayers& obj);
28 
30  virtual ~IKP1dLayers ();
31 
33  int laysNum () const {
34  return lays.size();
35  }
36 
39  T* layer (int n) const;
40 
42  virtual void push (T& lay) {
43  lays.push_back(new T(lay));
44  }
45 
48  bool erase (int n);
49 
52  void insert (int n, T& lay);
53 
55  void clear();
56 
58  void info () const;
59 
61  const string& getName() const {
62  return m_name;
63  }
64 
65 protected:
66 
68  std::vector <T*> lays;
69 
71  string m_name;
72 };
73 
74 //------------------------------------------------------------------------------------------
75 // Implementation
76 template <typename T> IKP1dLayers<T>::IKP1dLayers (const IKP1dLayers& obj)
77 {
78  //copy all layers
79  for (int i=0; i<obj.laysNum(); i++)
80  push(*obj.layer(i));
81 
82  m_name = obj.getName();
83 }
84 
85 
86 template <typename T> IKP1dLayers<T>::~IKP1dLayers ()
87 {
88  // remove all layers
89  clear();
90 }
91 
92 template <typename T> void IKP1dLayers<T>::clear ()
93 {
94  for (int i=0; i<laysNum(); i++)
95  delete lays[i];
96 #if 0
97  UMessage::info ("%s->clear.", m_name.c_str());
98 #endif
99  lays.clear();
100 }
101 
102 template <typename T> T* IKP1dLayers<T>::layer (int n) const
103 {
104  if (n < 0 || n >= laysNum())
105  {
106  UMessage::error ("%s->layer: Index out of range 0<%d<%d",
107  m_name.c_str(), n, laysNum());
108  return NULL;
109  }
110  else
111  return lays[n];
112 }
113 
114 
115 template <typename T> bool IKP1dLayers<T>::erase (int n)
116 {
117  if (n < 0 || n >= laysNum())
118  {
119  UMessage::error ("%s->erase: Index out of range 0<%d<%d",
120  m_name.c_str(), n, laysNum());
121  return false;
122  }
123  else
124  {
125  lays.erase(lays.begin()+n);
126  return true;
127  }
128 }
129 
130 
131 template <typename T> void IKP1dLayers<T>::insert (int n, T& lay)
132 {
133  if (n < 0)
134  {
135  UMessage::warning ("%s->insert: Index out of range 0<%d<=%d",
136  m_name.c_str(), n, laysNum());
137  n = 0;
138  }
139  if (n > laysNum())
140  {
141  UMessage::warning ("%s->insert: Index out of range 0<%d<=%d",
142  m_name.c_str(), n, laysNum());
143  n = laysNum();
144  }
145  lays.insert(lays.begin() + n, new T(lay));
146 }
147 
148 
149 template <typename T> void IKP1dLayers<T>::info () const
150 {
151  for (int i=0; i<laysNum(); i++)
152  {
153  UMessage::info ("%s->info: Layer %d/%d",
154  m_name.c_str(), i+1, laysNum());
155  lays[i]->info();
156  }
157 }
158 //------------------------------------------------------------------------------------------
159 
160 
161 #endif /* ikp1dlayers.hpp */
const string & getName() const
Definition: ikp1dlayers.hpp:61
static void error(const char *format,...)
virtual void push(T &lay)
Definition: ikp1dlayers.hpp:42
void insert(int n, T &lay)
Definition: ikp1dlayers.hpp:131
T * layer(int n) const
Definition: ikp1dlayers.hpp:102
void clear()
Definition: ikp1dlayers.hpp:92
string m_name
Definition: ikp1dlayers.hpp:71
std::vector< T * > lays
Definition: ikp1dlayers.hpp:68
IKP1dLayers(string name="IKP1dLayers")
Definition: ikp1dlayers.hpp:22
static void info(const char *format,...)
Definition: ikp1dlayers.hpp:17
static void warning(const char *format,...)
bool erase(int n)
Definition: ikp1dlayers.hpp:115
virtual ~IKP1dLayers()
Definition: ikp1dlayers.hpp:86
int laysNum() const
Definition: ikp1dlayers.hpp:33
void info() const
Definition: ikp1dlayers.hpp:149