void c4_Persist::LoadAll() { c4_Column walk(this); if (!LoadIt(walk)) return ; if (_strategy._rootLen < 0) { _oldSeek = _strategy._rootPos; _oldBuf = d4_new t4_byte[512]; _oldCurr = _oldLimit = _oldBuf; t4_i32 n = FetchOldValue(); d4_assert(n == 0); n = FetchOldValue(); d4_assert(n > 0); c4_Bytes temp; t4_byte *buf = temp.SetBuffer(n); d4_dbgdef(int n2 = )OldRead(buf, n); d4_assert(n2 == n); c4_String s = "[" + c4_String((const char*)buf, n) + "]"; const char *desc = s; c4_Field *f = d4_new c4_Field(desc); d4_assert(! *desc); //?_root->DefineRoot(); _root->Restructure(*f, false); _root->OldPrepare(); // don't touch data inside while converting the file if (_strategy.FileSize() >= 0) OccupySpace(1, _strategy.FileSize()); } else {
void c4_HandlerSeq::Prepare(const t4_byte **ptr_, bool selfDesc_) { if (ptr_ != 0) { d4_dbgdef(t4_i32 sias =)c4_Column::PullValue(*ptr_); d4_assert(sias == 0); // not yet if (selfDesc_) { t4_i32 n = c4_Column::PullValue(*ptr_); if (n > 0) { c4_String s = "[" + c4_String((const char *) * ptr_, n) + "]"; const char *desc = s; c4_Field *f = d4_new c4_Field(desc); d4_assert(! *desc); Restructure(*f, false); *ptr_ += n; } } int rows = (int)c4_Column::PullValue(*ptr_); if (rows > 0) { SetNumRows(rows); for (int i = 0; i < NumFields(); ++i) { NthHandler(i).Define(rows, ptr_); } } }
void c4_HandlerSeq::DefineRoot() { d4_assert(_field == 0); d4_assert(_parent == 0); SetNumRows(1); const char *desc = "[]"; _field = d4_new c4_Field(desc); d4_assert(! *desc); _parent = this; }
/// Define the complete view structure of the storage void c4_Storage::SetStructure(const char *description_) { d4_assert(description_ != 0); if (description_ != Description()) { c4_String s = "[" + c4_String(description_) + "]"; description_ = s; c4_Field *field = d4_new c4_Field(description_); d4_assert(! *description_); d4_assert(field != 0); Persist()->Root().Restructure(*field, false); } }
c4_Field::c4_Field(const char * &description_, c4_Field *parent_): _type(0) { _indirect = this; size_t n = strcspn(description_, ",[]"); const char *p = strchr(description_, ':'); if (p != 0 && p < description_ + n) { _name = c4_String(description_, p - description_); _type = p[1] &~0x20; // force to upper case } else { _name = c4_String(description_, n); _type = 'S'; } description_ += n; if (*description_ == '[') { ++description_; _type = 'V'; if (*description_ == '^') { ++description_; _indirect = parent_; d4_assert(*description_ == ']'); } if (*description_ == ']') ++description_; else do { // 2004-01-20 ignore duplicate property names // (since there is no good way to report errors at this point) c4_Field *sf = d4_new c4_Field(description_, this); for (int i = 0; i < NumSubFields(); ++i) if (SubField(i).Name().CompareNoCase(sf->Name()) == 0) { delete sf; sf = 0; break; } if (sf != 0) _subFields.Add(sf); } while (*description_++ == ','); } }
c4_Field::c4_Field (const char*& description_, c4_Field* parent_) : _type (0) { _indirect = this; size_t n = strcspn(description_, ",[]"); const char* p = strchr(description_, ':'); if (p != 0 && p < description_ + n) { _name = c4_String (description_, p - description_); _type = p[1] & ~0x20; // force to upper case } else { _name = c4_String (description_, n); _type = 'S'; } description_ += n; if (*description_ == '[') { ++description_; _type = 'V'; if (*description_ == '^') { ++description_; _indirect = parent_; d4_assert(*description_ == ']'); } if (*description_ == ']') ++description_; else do _subFields.Add(d4_new c4_Field (description_, this)); while (*description_++ == ','); } }
/// Get a named view, redefining it to match the given structure c4_View c4_Storage::GetAs(const char *description_) { d4_assert(description_ != 0); // Dec 2001: now that GetAs is being used so much more frequently, // add a quick check to see whether restructuring is needed at all const char *q = strchr(description_, '['); if (q != 0) { c4_String vname(description_, q - description_); const char *d = Description(vname); if (d != 0) { c4_String desc(d); if (("[" + desc + "]").CompareNoCase(q) == 0) return View(vname); } } c4_Field *field = d4_new c4_Field(description_); d4_assert(field != 0); d4_assert(! *description_); c4_String name = field->Name(); d4_assert(!name.IsEmpty()); c4_Field &curr = Persist()->Root().Definition(); c4_String newField = "," + field->Description(); bool keep = newField.Find('[') >= 0; c4_String newDef; // go through all subfields for (int i = 0; i < curr.NumSubFields(); ++i) { c4_Field &of = curr.SubField(i); if (of.Name().CompareNoCase(name) == 0) { if (field->IsRepeating()) newDef += newField; // else new is not a repeating entry, so drop this entire field newField.Empty(); // don't append it later on continue; } newDef += "," + of.Description(); // keep original field } if (keep) // added 19990824 ignore if deletion newDef += newField; // appends new definition if not found earlier delete field; const char *p = newDef; SetStructure(*p ? ++p: p); // skip the leading comma if (!keep) // 19990916: avoid adding an empty view again return c4_View(); return View(name); }