source: to-imperative/trunk/runtime/rf_vector.ih @ 1045

Last change on this file since 1045 was 1045, checked in by sveta, 18 years ago
  • Methods for Vector are added.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 KB
Line 
1#ifndef __rf_vector_ih__
2#define __rf_vector_ih__
3
4#include "rf_vector.hh"
5#include "rf_object.ih"
6#include "rf_expr.ih"
7#include "pxx_vector.ih"
8#include <typeinfo>
9
10namespace rftype
11{
12
13inline Vector::Vector (size_t _length /* = 0 */) :
14  Object (),
15  pxx::Vector<Expr> (_length)
16{}
17
18inline Vector::Vector (size_t _length, Expr const& _fill) :
19  Object (),
20  pxx::Vector<Expr> (_length)
21{
22  for (size_t i = 0; i < _length; i++) {
23    self[i] = _fill;
24  }
25
26
27inline Vector::Vector (Expr const& _expr, size_t _length) :
28  Object (),
29  pxx::Vector<Expr> (_length)
30{
31  Term* p = _expr.get_first();
32  Term* q = _expr.get_last();
33  size_t index = 0;
34  for (; p < q; p++) {
35    if (p->is_ref()) {
36      self[index++] = (Expr(p))();
37    } else {
38      FATAL("Invalid argument");               //  RF_LIB_ERROR - ??????
39    }
40  }
41}
42
43inline Vector::Vector(Vector const& _vector, size_t _index, size_t _length) :
44  Object(),
45  pxx::Vector<Expr> (_length)
46{
47  for (size_t i = 0; i < _length; i++)
48    self[i] = _vector[_index + i];
49}
50
51
52inline unsigned Vector::get_type () const
53{
54  return reg.get_type();
55}
56
57//
58// FIXME: Implement real hashing
59inline uint32_t Vector::hash () const
60{
61  return 0;
62}
63
64inline bool Vector::operator == (Object const& _obj) const
65{
66  try {
67    Vector const& v = dynamic_cast<Vector const&>(_obj);
68    if (get_length() == v.get_length()) {
69      for (size_t i = 0; i < get_length(); i++) {
70        if (self[i] != v[i]) return false;
71      }
72      return true;
73    }
74    return false;
75  } catch (std::bad_cast&) {
76    return false;
77  }
78}
79
80inline void Vector::vector_to_exp (Expr& _exp)
81{
82  for (size_t i = 0; i < get_length(); i++)
83    _exp = _exp + self[i];
84}
85
86inline void Vector::vector_init (size_t _length, Expr const& _fill)
87{
88  size_t n = get_length();
89  if (n < _length) 
90      expand (_length - n);
91  else
92    if (n > _length) {
93      decrease(n - _length);
94      n = _length;
95    }
96   for (  ; n  ; n--)
97     self[n-1] = _fill();
98}
99
100inline void Vector::vector_replace (size_t _length, Expr const& _exp)
101{
102  size_t n = get_length();
103  if (n < _length)
104    expand (_length - n);
105  else
106    if (n > _length)
107      decrease(n - _length);
108  Term* p = _exp.get_first();
109  Term* q = _exp.get_last();
110  n = 0;
111  for ( ; p < q ; p++) {
112    if (p->is_ref()) {
113      self[n++] = (Expr(p))();
114    } else {
115      FATAL("Invalid argument");     
116    }
117  }
118}   
119
120inline void  vector_meaning (Expr const& _exp, Expr& _result)
121{
122  Term* p = _exp.get_first();
123  Term* q = _exp.get_last();
124  for ( ; p < q; p++) {
125    if (p->is_ref()) {
126      _result = _result + (Expr(p))();
127    } else {
128      Vector* v = p->cast_to<Vector> (type_vector);
129      if (!v)
130        FATAL ("Invalid argument");
131      for (size_t i = 0; i < v->get_length(); i++)
132        _result = _result + (*v)[i];
133    }
134  }
135}     
136 
137inline void Vector::vector_fill (Expr const& _fill)
138{
139  for (size_t i = 0; i < get_length(); i++)
140    self[i] = _fill();
141}
142
143inline void Vector::subvector_fill (size_t _index, size_t _length, Expr const& _fill)
144{
145  for (size_t i = 0; i < _length; i++)
146    self[_index + i] = _fill();
147}
148
149}
150
151#endif // __rf_vector_ih__
152
Note: See TracBrowser for help on using the repository browser.