Fri, 24 May 2013 04:34:20 +0300
Make LDOpenFile's members PROPERTIES
src/bbox.cpp | file | annotate | diff | comparison | revisions | |
src/common.h | file | annotate | diff | comparison | revisions | |
src/dialogs.cpp | file | annotate | diff | comparison | revisions | |
src/dialogs.h | file | annotate | diff | comparison | revisions | |
src/extprogs.cpp | file | annotate | diff | comparison | revisions | |
src/file.cpp | file | annotate | diff | comparison | revisions | |
src/file.h | file | annotate | diff | comparison | revisions | |
src/gldraw.cpp | file | annotate | diff | comparison | revisions | |
src/gui.cpp | file | annotate | diff | comparison | revisions | |
src/gui_actions.cpp | file | annotate | diff | comparison | revisions | |
src/gui_editactions.cpp | file | annotate | diff | comparison | revisions | |
src/history.cpp | file | annotate | diff | comparison | revisions | |
src/ldtypes.cpp | file | annotate | diff | comparison | revisions |
--- a/src/bbox.cpp Fri May 24 03:34:09 2013 +0300 +++ b/src/bbox.cpp Fri May 24 04:34:20 2013 +0300 @@ -37,7 +37,7 @@ if (!g_curfile) return; - for (LDObject* obj : g_curfile->m_objs) + for (LDObject* obj : g_curfile->objs ()) calcObject (obj); }
--- a/src/common.h Fri May 24 03:34:09 2013 +0300 +++ b/src/common.h Fri May 24 04:34:20 2013 +0300 @@ -93,10 +93,24 @@ public: \ T const& GET () const { return m_##GET; } \ +// Same as above except not const +#define MUTABLE_READ_PROPERTY(T, GET) \ +private: \ + T m_##GET; \ +public: \ + T& GET () { return m_##GET; } \ + // Read/write private property with get and set accessors +#define SET_ACCESSOR(T, GET, SET) \ + void SET (T val) { m_##GET = val; } + #define PROPERTY(T, GET, SET) \ READ_PROPERTY(T, GET) \ - void SET (T val) { m_##GET = val; } + SET_ACCESSOR(T, GET, SET) + +#define MUTABLE_PROPERTY(T, GET, SET) \ + MUTABLE_READ_PROPERTY(T, GET) \ + SET_ACCESSOR(T, GET, SET) // Property that triggers a callback when it is changed #define CALLBACK_PROPERTY(T, GET, SET) \
--- a/src/dialogs.cpp Fri May 24 03:34:09 2013 +0300 +++ b/src/dialogs.cpp Fri May 24 04:34:20 2013 +0300 @@ -308,7 +308,7 @@ } // ======================================================================================================================================== -str LDrawPathDialog::path () const { +str LDrawPathDialog::filename () const { return le_path->text (); } @@ -316,7 +316,7 @@ void LDrawPathDialog::slot_findPath () { str newpath = QFileDialog::getExistingDirectory (this, "Find LDraw Path"); - if (~newpath > 0 && newpath != path ()) { + if (~newpath > 0 && newpath != filename ()) { setPath (newpath); slot_tryConfigure (); } @@ -330,7 +330,7 @@ // ======================================================================================================================================== void LDrawPathDialog::slot_tryConfigure () { - if (LDPaths::tryConfigure (path ()) == false) { + if (LDPaths::tryConfigure (filename ()) == false) { lb_resolution->setText (fmt ("<span style=\"color:red; font-weight: bold;\">%s</span>", LDPaths::getError().chars ())); okButton ()->setEnabled (false); return; @@ -395,7 +395,7 @@ short idx; str author = dlg.le_author->text (); - vector<LDObject*>& objs = g_curfile->m_objs; + vector<LDObject*>& objs = g_curfile->objs (); idx = dlg.rb_BFC->value (); const LDBFC::Type BFCType = @@ -482,7 +482,7 @@ // ============================================================================= OpenProgressDialog::OpenProgressDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) { progressBar = new QProgressBar; - progressText = new QLabel; + progressText = new QLabel ("Parsing..."); setNumLines (0); m_progress = 0; @@ -503,7 +503,6 @@ void OpenProgressDialog::updateValues () { progressBar->setValue (progress ()); - progressText->setText (fmt ("%lu/%lu lines parsed", progress (), numLines ())); } void OpenProgressDialog::updateProgress (int progress) {
--- a/src/dialogs.h Fri May 24 03:34:09 2013 +0300 +++ b/src/dialogs.h Fri May 24 04:34:20 2013 +0300 @@ -100,7 +100,7 @@ public: explicit LDrawPathDialog (const bool validDefault, QWidget* parent = null, Qt::WindowFlags f = 0); - str path () const; + str filename () const; void setPath (str path); private:
--- a/src/extprogs.cpp Fri May 24 03:34:09 2013 +0300 +++ b/src/extprogs.cpp Fri May 24 04:34:20 2013 +0300 @@ -154,7 +154,7 @@ // ============================================================================= void writeColorGroup (const short colnum, str fname) { std::vector<LDObject*> objects; - for (LDObject*& obj : g_curfile->m_objs) { + for (LDObject*& obj : g_curfile->objs ()) { if (obj->isColored () == false || obj->color != colnum) continue;
--- a/src/file.cpp Fri May 24 03:34:09 2013 +0300 +++ b/src/file.cpp Fri May 24 04:34:20 2013 +0300 @@ -53,7 +53,7 @@ if (!dlg.exec ()) exit (0); - io_ldpath = dlg.path (); + io_ldpath = dlg.filename (); } } @@ -89,8 +89,8 @@ // ============================================================================= LDOpenFile::LDOpenFile () { - m_implicit = true; - savePos = -1; + setImplicit (true); + setSavePos (-1); } // ============================================================================= @@ -100,14 +100,14 @@ delete obj; // Clear the cache as well - for (LDObject* obj : m_objCache) + for (LDObject* obj : m_cache) delete obj; } // ============================================================================= LDOpenFile* findLoadedFile (str name) { for (LDOpenFile* file : g_loadedFiles) - if (file->m_filename == name) + if (file->name () == name) return file; return null; @@ -147,7 +147,7 @@ #endif // WIN32 if (g_curfile != null) { - str partpath = fmt ("%s" DIRSLASH "%s", dirname (g_curfile->m_filename).c (), relpath.c ()); + str partpath = fmt ("%s" DIRSLASH "%s", dirname (g_curfile->name ()).c (), relpath.c ()); printf ("try %s\n", partpath.c ()); FILE* fp = fopen (partpath, "r"); @@ -316,7 +316,7 @@ LDOpenFile* oldLoad = g_curfile; LDOpenFile* load = new LDOpenFile; - load->m_filename = path; + load->setName (path); if (g_loadingMainFile) g_curfile = load; @@ -331,7 +331,7 @@ } for (LDObject* obj : objs) - load->m_objs.push_back (obj); + load->addObject (obj); fclose (fp); g_loadedFiles.push_back (load); @@ -349,27 +349,27 @@ setlocale (LC_ALL, "C"); // If we have unsaved changes, warn and give the option of saving. - if (!m_implicit && History::pos () != savePos) { + if (!implicit () && History::pos () != savePos ()) { switch (QMessageBox::question (g_win, "Unsaved Changes", fmt ("There are unsaved changes to %s. Should it be saved?", - (m_filename.len () > 0) ? m_filename.chars () : "<anonymous>"), + (name ().len () > 0) ? name ().c () : "<anonymous>"), (QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel), QMessageBox::Cancel)) { case QMessageBox::Yes: // If we don't have a file path yet, we have to ask the user for one. - if (m_filename.len () == 0) { - str path = QFileDialog::getSaveFileName (g_win, "Save As", - g_curfile->m_filename, "LDraw files (*.dat *.ldr)"); + if (name ().len () == 0) { + str newpath = QFileDialog::getSaveFileName (g_win, "Save As", + g_curfile->name (), "LDraw files (*.dat *.ldr)"); - if (path.len () == 0) + if (newpath.len () == 0) return false; - m_filename = path; + setName (newpath); } if (!save ()) { str errormsg = fmt ("Failed to save %s: %s\nDo you still want to close?", - m_filename.chars (), strerror (lastError)); + name ().c (), strerror (errno)); if (QMessageBox::critical (g_win, "Save Failure", errormsg, (QMessageBox::Yes | QMessageBox::No), QMessageBox::No) == QMessageBox::No) @@ -417,8 +417,8 @@ closeAll (); LDOpenFile* f = new LDOpenFile; - f->m_filename = ""; - f->m_implicit = false; + f->setName (""); + f->setImplicit (false); g_loadedFiles.push_back (f); g_curfile = f; @@ -484,7 +484,7 @@ return; } - file->m_implicit = false; + file->setImplicit (false); g_curfile = file; // Recalculate the bounding box @@ -505,39 +505,37 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -bool LDOpenFile::save (str path) { - if (!~path) - path = m_filename; +bool LDOpenFile::save (str savepath) { + if (!~savepath) + savepath = name (); - FILE* fp = fopen (path, "w"); + FILE* fp = fopen (savepath, "w"); - if (!fp) { - lastError = errno; + if (!fp) return false; - } // If the second object in the list holds the file name, update that now. // Only do this if the file is explicitly open. If it's saved into a directory // called "s" or "48", prepend that into the name. LDComment* fpathComment = null; - if (m_implicit == false && m_objs.size () >= 2 && object (1)->getType () == LDObject::Comment) { + if (!implicit () && objs ().size () >= 2 && object (1)->getType () == LDObject::Comment) { fpathComment = static_cast<LDComment*> (object (1)); if (fpathComment->text.substr (0, 6) == "Name: ") { str newfname; - str dir = basename (dirname (path)); + str dir = basename (dirname (savepath)); if (dir == "s" || dir == "48") newfname = fmt ("%s\\", dir.c ()); - newfname += basename (path); + newfname += basename (savepath); fpathComment->text = fmt ("Name: %s", newfname.c ()); g_win->buildObjList (); } } // Write all entries now - for (LDObject* obj : m_objs) { + for (LDObject* obj : objs ()) { // LDraw requires files to have DOS line endings str line = fmt ("%s\r\n", obj->getContents ().chars ()); fwrite (line.chars(), 1, line.len (), fp); @@ -546,8 +544,8 @@ fclose (fp); // We have successfully saved, update the save position now. - savePos = History::pos (); - m_filename = path; + setSavePos (History::pos ()); + setName (savepath); g_win->updateTitle (); return true; @@ -796,7 +794,7 @@ g_loadedFiles.push_back (g_curfile); // Go through all objects in the current file and reload the subfiles - for (LDObject* obj : g_curfile->m_objs) { + for (LDObject* obj : g_curfile->objs ()) { if (obj->getType() == LDObject::Subfile) { // Note: ref->fileInfo is invalid right now since all subfiles were closed. LDSubfile* ref = static_cast<LDSubfile*> (obj); @@ -826,7 +824,7 @@ if (this == g_curfile) g_BBox.calcObject (obj); - return m_objs.size() - 1; + return numObjs () - 1; } // ============================================================================= @@ -922,4 +920,10 @@ return false; return true; +} + +// ============================================================================= +void LDOpenFile::setObject (ulong idx, LDObject* obj) { + assert (idx < numObjs ()); + m_objs[idx] = obj; } \ No newline at end of file
--- a/src/file.h Fri May 24 03:34:09 2013 +0300 +++ b/src/file.h Fri May 24 04:34:20 2013 +0300 @@ -39,22 +39,21 @@ // // The LDOpenFile class stores a file opened in LDForge either as a editable file // for the user or for subfile caching. Its methods handle file input and output. +// +// A file is implicit when they are opened automatically for caching purposes +// and are hidden from the user. User-opened files are explicit (not implicit). // ============================================================================= class LDOpenFile { + PROPERTY (str, name, setName) + PROPERTY (bool, implicit, setImplicit) + MUTABLE_READ_PROPERTY (vector<LDObject*>, objs) + PROPERTY (vector<LDObject*>, cache, setCache) + PROPERTY (long, savePos, setSavePos) + public: typedef std::vector<LDObject*>::iterator it; typedef std::vector<LDObject*>::const_iterator c_it; - str m_filename, m_title; - vector<LDObject*> m_objs; - vector<LDObject*> m_objCache; // Cache of this file's contents, if desired - - int lastError; - - // Is this file implicit? Implicit files are opened automatically for - // caching purposes and are hidden from the user. - bool m_implicit; - LDOpenFile (); ~LDOpenFile (); @@ -70,14 +69,12 @@ // Deletes the given object from the object chain. void forgetObject (LDObject* obj); - // At what point was this file last saved? - long savePos; - - LDObject* object (ulong pos) const { - return m_objs[pos]; - } + LDObject* object (ulong pos) const { return m_objs[pos]; } + LDObject* obj (ulong pos) const { return object (pos); } void insertObj (const ulong pos, LDObject* obj); + ulong numObjs () const { return m_objs.size (); } + void setObject (ulong idx, LDObject* obj); it begin () { return m_objs.begin (); } it end () { return m_objs.end (); }
--- a/src/gldraw.cpp Fri May 24 03:34:09 2013 +0300 +++ b/src/gldraw.cpp Fri May 24 04:34:20 2013 +0300 @@ -387,7 +387,7 @@ if (gl_colorbfc && !m_picking) { glEnable (GL_CULL_FACE); - for (LDObject* obj : g_curfile->m_objs) { + for (LDObject* obj : g_curfile->objs ()) { if (obj->hidden ()) continue; @@ -400,7 +400,7 @@ glDisable (GL_CULL_FACE); } else { - for (LDObject* obj : g_curfile->m_objs) { + for (LDObject* obj : g_curfile->objs ()) { if (obj->hidden ()) continue; @@ -668,7 +668,7 @@ return; } - for (LDObject* obj : g_curfile->m_objs) + for (LDObject* obj : g_curfile->objs ()) compileObject (obj); // Compile axes @@ -1083,7 +1083,7 @@ if (idx == 0xFFFFFF) continue; // White is background; skip - LDObject* obj = g_curfile->object (idx); + LDObject* obj = g_curfile->obj (idx); // If this is an additive single pick and the object is currently selected, // we remove it from selection instead.
--- a/src/gui.cpp Fri May 24 03:34:09 2013 +0300 +++ b/src/gui.cpp Fri May 24 04:34:20 2013 +0300 @@ -500,20 +500,20 @@ // Append our current file if we have one if (g_curfile) { - if (g_curfile->m_filename.len () > 0) - title += fmt (": %s", basename (g_curfile->m_filename).chars ()); + if (g_curfile->name ().len () > 0) + title += fmt (": %s", basename (g_curfile->name ()).c ()); else title += fmt (": <anonymous>"); - if (g_curfile->m_objs.size() > 0 && - g_curfile->m_objs[0]->getType() == LDObject::Comment) + if (g_curfile->numObjs () > 0 && + g_curfile->obj (0)->getType () == LDObject::Comment) { // Append title - LDComment* comm = static_cast<LDComment*> (g_curfile->m_objs[0]); + LDComment* comm = static_cast<LDComment*> (g_curfile->obj (0)); title += fmt (": %s", comm->text.chars()); } - if (History::pos () != g_curfile->savePos) + if (History::pos () != g_curfile->savePos ()) title += '*'; } @@ -589,7 +589,7 @@ m_objList->clear (); - for (LDObject* obj : g_curfile->m_objs) { + for (LDObject* obj : g_curfile->objs ()) { str descr; switch (obj->getType ()) { @@ -732,7 +732,7 @@ m_sel.clear (); const QList<QListWidgetItem*> items = m_objList->selectedItems (); - for (LDObject* obj : g_curfile->m_objs) + for (LDObject* obj : g_curfile->objs ()) for (QListWidgetItem* item : items) { if (item == obj->qObjListEntry) { m_sel.push_back (obj); @@ -805,7 +805,7 @@ } // Otherwise place the object at the end. - return g_curfile->m_objs.size(); + return g_curfile->numObjs (); } // ============================================================================= @@ -827,7 +827,7 @@ void ForgeWindow::updateSelection () { g_bSelectionLocked = true; - for (LDObject* obj : g_curfile->m_objs) + for (LDObject* obj : g_curfile->objs ()) obj->setSelected (false); m_objList->clearSelection (); @@ -970,7 +970,7 @@ // ======================================================================================================================================== DelHistory* ForgeWindow::deleteByColor (const short colnum) { vector<LDObject*> objs; - for (LDObject* obj : g_curfile->m_objs) { + for (LDObject* obj : g_curfile->objs ()) { if (!obj->isColored () || obj->color != colnum) continue; @@ -1077,7 +1077,7 @@ void makeColorSelector (QComboBox* box) { std::map<short, ulong> counts; - for (LDObject* obj : g_curfile->m_objs) { + for (LDObject* obj : g_curfile->objs ()) { if (!obj->isColored ()) continue;
--- a/src/gui_actions.cpp Fri May 24 03:34:09 2013 +0300 +++ b/src/gui_actions.cpp Fri May 24 04:34:20 2013 +0300 @@ -66,11 +66,11 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void doSave (bool saveAs) { - str path = g_curfile->m_filename; + str path = g_curfile->name (); if (~path == 0 || saveAs) { path = QFileDialog::getSaveFileName (g_win, "Save As", - g_curfile->m_filename, "LDraw files (*.dat *.ldr)"); + g_curfile->name (), "LDraw files (*.dat *.ldr)"); if (~path == 0) { // User didn't give a file name. This happens if the user cancelled @@ -80,7 +80,7 @@ } if (g_curfile->save (path)) { - g_curfile->m_filename = path; + g_curfile->setName (path); g_win->updateTitle (); logf ("Saved successfully to %s\n", path.chars ()); @@ -89,7 +89,7 @@ // Tell the user the save failed, and give the option for saving as with it. QMessageBox dlg (QMessageBox::Critical, "Save Failure", - fmt ("Failed to save to %s\nReason: %s", path.chars(), strerror (g_curfile->lastError)), + fmt ("Failed to save to %s\nReason: %s", path.chars(), strerror (errno)), QMessageBox::Close, g_win); QPushButton* saveAsBtn = new QPushButton ("Save As"); @@ -207,7 +207,7 @@ MAKE_ACTION (selectAll, "Select All", "select-all", "Selects all objects.", CTRL (A)) { g_win->sel ().clear (); - for (LDObject* obj : g_curfile->m_objs) + for (LDObject* obj : g_curfile->objs ()) g_win->sel ().push_back (obj); g_win->updateSelection (); @@ -223,7 +223,7 @@ return; // no consensus on color g_win->sel ().clear (); - for (LDObject* obj : g_curfile->m_objs) + for (LDObject* obj : g_curfile->objs ()) if (obj->color == dColor) g_win->sel ().push_back (obj); @@ -237,29 +237,29 @@ if (g_win->sel ().size () == 0) return; - LDObject::Type eType = g_win->uniformSelectedType (); + LDObject::Type type = g_win->uniformSelectedType (); - if (eType == LDObject::Unidentified) + if (type == LDObject::Unidentified) return; // If we're selecting subfile references, the reference filename must also // be uniform. - str zRefName; + str refName; - if (eType == LDObject::Subfile) { - zRefName = static_cast<LDSubfile*> (g_win->sel ()[0])->fileName; + if (type == LDObject::Subfile) { + refName = static_cast<LDSubfile*> (g_win->sel ()[0])->fileName; for (LDObject* pObj : g_win->sel ()) - if (static_cast<LDSubfile*> (pObj)->fileName != zRefName) + if (static_cast<LDSubfile*> (pObj)->fileName != refName) return; } g_win->sel ().clear (); - for (LDObject* obj : g_curfile->m_objs) { - if (obj->getType() != eType) + for (LDObject* obj : g_curfile->objs ()) { + if (obj->getType() != type) continue; - if (eType == LDObject::Subfile && static_cast<LDSubfile*> (obj)->fileName != zRefName) + if (type == LDObject::Subfile && static_cast<LDSubfile*> (obj)->fileName != refName) continue; g_win->sel ().push_back (obj); @@ -384,7 +384,7 @@ // GL and Qt formats have R and B swapped. Also, GL flips Y - correct it as well. QImage img = QImage (imagedata, w, h, QImage::Format_ARGB32).rgbSwapped ().mirrored (); - str root = basename (g_curfile->m_filename); + str root = basename (g_curfile->name ()); if (~root >= 4 && root.substr (~root - 4, -1) == ".dat") root -= 4;
--- a/src/gui_editactions.cpp Fri May 24 03:34:09 2013 +0300 +++ b/src/gui_editactions.cpp Fri May 24 04:34:20 2013 +0300 @@ -265,7 +265,7 @@ // Replace the quad with the first triangle and add the second triangle // after the first one. - g_curfile->m_objs[lIndex] = triangles[0]; + g_curfile->setObject (lIndex, triangles[0]); g_curfile->insertObj (lIndex + 1, triangles[1]); // Delete this quad now, it has been split. @@ -787,7 +787,7 @@ // ========================================================================================================================================= static bool isColorUsed (short colnum) { - for (LDObject* obj : g_curfile->m_objs) + for (LDObject* obj : g_curfile->objs ()) if (obj->isColored () && obj->color == colnum) return true;
--- a/src/history.cpp Fri May 24 03:34:09 2013 +0300 +++ b/src/history.cpp Fri May 24 04:34:20 2013 +0300 @@ -117,7 +117,7 @@ // ============================================================================= void DelHistory::redo () { for (ulong i = 0; i < cache.size(); ++i) { - LDObject* obj = g_curfile->m_objs[indices[i]]; + LDObject* obj = g_curfile->object (indices[i]); g_curfile->forgetObject (obj); delete obj; @@ -138,7 +138,7 @@ void SetColorHistory::undo () { // Restore colors for (ulong i = 0; i < ulaIndices.size (); ++i) - g_curfile->m_objs[ulaIndices[i]]->color = daColors[i]; + g_curfile->object (ulaIndices[i])->color = daColors[i]; g_win->fullRefresh (); } @@ -146,7 +146,7 @@ void SetColorHistory::redo () { // Re-set post color for (ulong i = 0; i < ulaIndices.size (); ++i) - g_curfile->m_objs[ulaIndices[i]]->color = dNewColor; + g_curfile->object (ulaIndices[i])->color = dNewColor; g_win->fullRefresh (); } @@ -195,7 +195,7 @@ std::vector<LDObject*> objs; for (ulong idx : ulaIndices) - objs.push_back (g_curfile->m_objs[idx + ofs]); + objs.push_back (g_curfile->object (idx + ofs)); return objs; } @@ -225,7 +225,7 @@ void AddHistory::undo () { for (ulong i = 0; i < paObjs.size(); ++i) { ulong idx = ulaIndices[ulaIndices.size() - i - 1]; - LDObject* obj = g_curfile->m_objs[idx]; + LDObject* obj = g_curfile->object (idx); g_curfile->forgetObject (obj); delete obj; @@ -260,8 +260,8 @@ // the first with a copy of the quad. ulong idx = ulaIndices[i]; - LDTriangle* tri1 = static_cast<LDTriangle*> (g_curfile->m_objs[idx]), - *tri2 = static_cast<LDTriangle*> (g_curfile->m_objs[idx + 1]); + LDTriangle* tri1 = static_cast<LDTriangle*> (g_curfile->object (idx)), + *tri2 = static_cast<LDTriangle*> (g_curfile->object (idx + 1)); LDQuad* pCopy = paQuads[i]->clone (); tri1->replace (pCopy); @@ -276,10 +276,10 @@ for (long i = paQuads.size() - 1; i >= 0; --i) { ulong idx = ulaIndices[i]; - LDQuad* pQuad = static_cast<LDQuad*> (g_curfile->m_objs[idx]); + LDQuad* pQuad = static_cast<LDQuad*> (g_curfile->object (idx)); std::vector<LDTriangle*> paTriangles = pQuad->splitToTriangles (); - g_curfile->m_objs[idx] = paTriangles[0]; + g_curfile->setObject (idx, paTriangles[0]); g_curfile->insertObj (idx + 1, paTriangles[1]); delete pQuad; } @@ -292,7 +292,7 @@ // ============================================================================= void InlineHistory::undo () { for (long i = ulaBitIndices.size() - 1; i >= 0; --i) { - LDObject* obj = g_curfile->m_objs [ulaBitIndices[i]]; + LDObject* obj = g_curfile->object (ulaBitIndices[i]); g_curfile->forgetObject (obj); delete obj; }
--- a/src/ldtypes.cpp Fri May 24 03:34:09 2013 +0300 +++ b/src/ldtypes.cpp Fri May 24 04:34:20 2013 +0300 @@ -184,7 +184,7 @@ // ============================================================================= void LDObject::replace (LDObject* replacement) { // Replace the instance of the old object with the new object - for (LDObject*& obj : g_curfile->m_objs) { + for (LDObject*& obj : g_curfile->objs ()) { if (obj == this) { obj = replacement; break; @@ -199,7 +199,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void LDObject::swap (LDObject* other) { - for (LDObject*& obj : g_curfile->m_objs) { + for (LDObject*& obj : g_curfile->objs ()) { if (obj == this) obj = other; else if (obj == other) @@ -256,18 +256,18 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -vector<LDObject*> LDSubfile::inlineContents (bool bDeepInline, bool bCache) { - vector<LDObject*> objs, cache; +vector<LDObject*> LDSubfile::inlineContents (bool deep, bool cache) { + vector<LDObject*> objs, objcache; // If we have this cached, just clone that - if (bDeepInline && fileInfo->m_objCache.size ()) { - for (LDObject* obj : fileInfo->m_objCache) + if (deep && fileInfo->cache ().size ()) { + for (LDObject* obj : fileInfo->cache ()) objs.push_back (obj->clone ()); } else { - if (!bDeepInline) - bCache = false; + if (!deep) + cache = false; - for (LDObject* obj : fileInfo->m_objs) { + for (LDObject* obj : fileInfo->objs ()) { // Skip those without schemantic meaning switch (obj->getType ()) { case LDObject::Comment: @@ -290,28 +290,28 @@ // Got another sub-file reference, inline it if we're deep-inlining. If not, // just add it into the objects normally. Also, we only cache immediate // subfiles and this is not one. Yay, recursion! - if (bDeepInline && obj->getType() == LDObject::Subfile) { + if (deep && obj->getType() == LDObject::Subfile) { LDSubfile* ref = static_cast<LDSubfile*> (obj); vector<LDObject*> otherobjs = ref->inlineContents (true, false); for (LDObject* otherobj : otherobjs) { // Cache this object, if desired - if (bCache) - cache.push_back (otherobj->clone ()); + if (cache) + objcache.push_back (otherobj->clone ()); objs.push_back (otherobj); } } else { - if (bCache) - cache.push_back (obj->clone ()); + if (cache) + objcache.push_back (obj->clone ()); objs.push_back (obj->clone ()); } } - if (bCache) - fileInfo->m_objCache = cache; + if (cache) + fileInfo->setCache (objcache); } // Transform the objects @@ -328,9 +328,9 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -long LDObject::getIndex (LDOpenFile* pFile) const { - for (ulong i = 0; i < pFile->m_objs.size(); ++i) - if (pFile->m_objs[i] == this) +long LDObject::getIndex (LDOpenFile* file) const { + for (ulong i = 0; i < file->numObjs (); ++i) + if (file->obj (i) == this) return i; return -1; @@ -354,7 +354,7 @@ target = idx + (bUp ? -1 : 1); if ((bUp == true and idx == 0) or - (bUp == false and idx == (long)(g_curfile->m_objs.size() - 1))) + (bUp == false and idx == (long)(g_curfile->objs ().size() - 1))) { // One of the objects hit the extrema. If this happens, this should be the first // object to be iterated on. Thus, nothing has changed yet and it's safe to just @@ -364,9 +364,9 @@ } objsToCompile.push_back (obj); - objsToCompile.push_back (g_curfile->m_objs[target]); + objsToCompile.push_back (g_curfile->obj (target)); - obj->swap (g_curfile->m_objs[target]); + obj->swap (g_curfile->obj (target)); } // The objects need to be recompiled, otherwise their pick lists are left with @@ -430,10 +430,10 @@ long idx = getIndex (g_curfile); assert (idx != -1); - if (idx == (long) g_curfile->m_objs.size () - 1) + if (idx == (long) g_curfile->numObjs () - 1) return null; - return g_curfile->m_objs[idx + 1]; + return g_curfile->obj (idx + 1); } // ============================================================================= @@ -444,7 +444,7 @@ if (idx == 0) return null; - return g_curfile->m_objs[idx - 1]; + return g_curfile->obj (idx - 1); } // =============================================================================