#ifndef __rf_vector_ih__ #define __rf_vector_ih__ #include "rf_vector.hh" #include "rf_object.ih" #include "rf_expr.ih" #include "pxx_vector.ih" #include "rf_sysdefs.hh" namespace rftype { inline Vector::Vector (size_t _length /* = 0 */) : Object (), pxx::Vector (_length) {} inline Vector::Vector (size_t _length, Expr const& _fill) : Object (), pxx::Vector (_length) { for (size_t i = 0; i < _length; i++) { self[i] = _fill; } } inline Vector::Vector (Expr const& _expr, size_t _length) : Object (), pxx::Vector (_length) { Term* p = _expr.get_first(); Term* q = _expr.get_last(); size_t index = 0; for ( ; p < q; p++) { if (p->is_ref()) { self[index++] = (Expr(p))(); } else { Vector* v = p->cast_to (type_vector); if (!v) FATAL ("Invalid argument"); for (size_t i = 0; i < v->get_length(); i++) self[index++] = (*v)[i]; } } } inline Vector::Vector(Vector const& _vector, size_t _index, size_t _length) : Object(), pxx::Vector (_length) { for (size_t i = 0; i < _length; i++) self[i] = _vector[_index + i]; } inline Vector::Vector(Vector const& _vector) : Object(), pxx::Vector (_vector) {} inline unsigned Vector::get_type () const { return reg.get_type(); } // // FIXME: Implement real hashing inline uint32_t Vector::hash () const { return 0; } #if 0 inline bool Vector::operator == (Object const& _obj) const { try { Vector const& v = dynamic_cast(_obj); if (get_length() == v.get_length()) { for (size_t i = 0; i < get_length(); i++) { if (self[i] != v[i]) return false; } return true; } return false; } catch (std::bad_cast&) { return false; } } #endif inline const Vector& Vector::operator= (Vector const& _vector) { if (this != &_vector) { size_t len = get_length(); size_t vlen = _vector.get_length(); if (len > vlen) this -> decrease(len-vlen); else if (len < vlen) this -> expand(vlen-len); for (size_t i = 0; i < vlen; i++) self[i] = _vector[i]; } return self; } inline pxx::WString Vector::to_string () const { size_t max_len = hex_ptr_len * 2 + 15; wchar_t* str = static_cast(alloca(max_len * sizeof(wchar_t))); int len = swprintf(str, max_len, L"", this, get_data()); if (-1 == len) { FATAL(" is more then %u wide characters", this, get_data(), max_len); } return pxx::WString(str, len); } } #endif // __rf_vector_ih__