"Fossies" - the Fresh Open Source Software Archive

Member "MP3Diags-unstable-1.5.01/src/DebugDlgImpl.cpp" (16 Feb 2019, 26826 Bytes) of package /linux/privat/MP3Diags-unstable-1.5.01.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "DebugDlgImpl.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.3.04_vs_1.5.01.

    1 /***************************************************************************
    2  *   MP3 Diags - diagnosis, repairs and tag editing for MP3 files          *
    3  *                                                                         *
    4  *   Copyright (C) 2009 by Marian Ciobanu                                  *
    5  *   ciobi@inbox.com                                                       *
    6  *                                                                         *
    7  *   This program is free software; you can redistribute it and/or modify  *
    8  *   it under the terms of the GNU General Public License version 2 as     *
    9  *   published by the Free Software Foundation.                            *
   10  *                                                                         *
   11  *   This program is distributed in the hope that it will be useful,       *
   12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
   13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
   14  *   GNU General Public License for more details.                          *
   15  *                                                                         *
   16  *   You should have received a copy of the GNU General Public License     *
   17  *   along with this program; if not, write to the                         *
   18  *   Free Software Foundation, Inc.,                                       *
   19  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
   20  ***************************************************************************/
   21 
   22 
   23 
   24 #include  <algorithm>
   25 #include  <sstream>
   26 
   27 #include  <QFileDialog>
   28 #include  <QMessageBox>
   29 #include  <QHeaderView>
   30 
   31 //#include  "SerSupport.h"
   32 
   33 #include  "DebugDlgImpl.h"
   34 
   35 #include  "CommonData.h"
   36 #include  "DataStream.h"
   37 #include  "Helpers.h"
   38 #include  "StoredSettings.h"
   39 #include  "LogModel.h"
   40 #include  "Widgets.h"
   41 //#include  "Serializable.h"
   42 
   43 /*#include  <boost/archive/binary_oarchive.hpp>
   44 #include  <boost/archive/binary_iarchive.hpp>
   45 #include  <boost/serialization/vector.hpp>
   46 */
   47 
   48 using namespace std;
   49 using namespace pearl;
   50 
   51 
   52 
   53 DebugDlgImpl::DebugDlgImpl(QWidget* pParent, CommonData* pCommonData) : QDialog(pParent, getDialogWndFlags()), Ui::DebugDlg(), m_pCommonData(pCommonData)
   54 {
   55     setupUi(this);
   56 
   57     int nWidth, nHeight;
   58     m_pCommonData->m_settings.loadDebugSettings(nWidth, nHeight);
   59     if (nWidth > 400 && nHeight > 200)
   60     {
   61         resize(nWidth, nHeight);
   62     }
   63     else
   64     {
   65         defaultResize(*this);
   66     }
   67 
   68     {
   69         m_pEnableTracingCkB->setChecked(m_pCommonData->m_bTraceEnabled);
   70         m_pUseAllNotesCkB->setChecked(m_pCommonData->m_bUseAllNotes);
   71         m_pLogTransfCkB->setChecked(m_pCommonData->m_bLogTransf);
   72         m_pSaveDownloadedDataCkB->setChecked(m_pCommonData->m_bSaveDownloadedData);
   73     }
   74 
   75     {
   76         m_pLogModel = new LogModel(m_pCommonData, m_pLogG);
   77         m_pLogG->setModel(m_pLogModel);
   78 
   79         m_pLogG->verticalHeader()->setMinimumSectionSize(CELL_HEIGHT);
   80         m_pLogG->verticalHeader()->setDefaultSectionSize(CELL_HEIGHT);
   81         decreaseRowHeaderFont(*m_pLogG);
   82 
   83         m_pLogG->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
   84         m_pLogG->verticalHeader()->setDefaultAlignment(Qt::AlignRight | Qt::AlignVCenter);
   85 
   86         //m_pLogG->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
   87         m_pLogG->verticalHeader()->setSectionResizeMode(QHeaderView::Interactive);
   88     }
   89 
   90     m_pUseAllNotesCkB->setToolTip(
   91             tr("If this is checked, ignored notes and trace notes\n"
   92             "are shown in the note list and exported, regardless\n"
   93             "of the \"Ignored\" settings.\n\n"
   94             "Note that if this is not checked, the trace notes\n"
   95             "are discarded during file scanning, so checking it\n"
   96             "later won't bring them back. A new scan is needed\n"
   97             "to see them.", "this is a multiline tooltip"));
   98 
   99     m_pLogG->setFocus();
  100 
  101     if (!m_pCommonData->m_bShowCustomCloseButtons)
  102     {
  103         m_pCloseB->hide();
  104     }
  105 
  106     { QAction* p (new QAction(this)); p->setShortcut(QKeySequence("F1")); connect(p, SIGNAL(triggered()), this, SLOT(onHelp())); addAction(p); }
  107 }
  108 
  109 
  110 void DebugDlgImpl::run()
  111 {
  112     //if (QDialog::Accepted != exec()) { return false; }
  113     exec();
  114 
  115     m_pCommonData->m_settings.saveDebugSettings(width(), height());
  116     m_pCommonData->m_bTraceEnabled = m_pEnableTracingCkB->isChecked();
  117     m_pCommonData->m_bUseAllNotes = m_pUseAllNotesCkB->isChecked();
  118     m_pCommonData->m_bLogTransf = m_pLogTransfCkB->isChecked();
  119     m_pCommonData->m_bSaveDownloadedData = m_pSaveDownloadedDataCkB->isChecked();
  120     //return true;
  121 }
  122 
  123 
  124 DebugDlgImpl::~DebugDlgImpl()
  125 {
  126 }
  127 
  128 
  129 void DebugDlgImpl::on_m_pCloseB_clicked()
  130 {
  131     reject(); // !!! doesn't matter if it's accept()
  132 }
  133 
  134 void DebugDlgImpl::exportLog(const string& strFileName)
  135 {
  136     const deque<std::string>& v (m_pCommonData->getLog());
  137 
  138     ofstream_utf8 out (strFileName.c_str());
  139     for (int i = 0, n = cSize(v); i < n; ++i)
  140     {
  141         out << v[i] << endl;
  142     }
  143 }
  144 
  145 
  146 
  147 void DebugDlgImpl::on_m_pSaveLogB_clicked()
  148 {
  149     QFileDialog dlg (this, tr("Choose destination file"), "", tr("Text files (*.txt)"));
  150 
  151     dlg.setFileMode(QFileDialog::AnyFile);
  152     if (QDialog::Accepted != dlg.exec()) { return; }
  153 
  154     QStringList fileNames (dlg.selectedFiles());
  155     if (1 != fileNames.size()) { return; }
  156 
  157     QString s (fileNames.first());
  158     exportLog(convStr(s));
  159 }
  160 
  161 
  162 void DebugDlgImpl::on_m_pDecodeMpegFrameB_clicked()
  163 {
  164     istringstream s (m_pFrameHdrE->text().toUtf8().constData());
  165     s >> hex;
  166     unsigned int n;
  167     s >> n;
  168     showInfo(this, tr("Decoded MPEG frame header"), convStr(decodeMpegFrame(n, "\n")));
  169 }
  170 
  171 
  172 
  173 
  174 void DebugDlgImpl::onHelp()
  175 {
  176     openHelp("310_advanced.html");
  177 }
  178 
  179 
  180 //========================================================================================================================================================
  181 //========================================================================================================================================================
  182 //========================================================================================================================================================
  183 
  184 
  185 void tstFont();
  186 void tstGenre();
  187 void tstSer01();
  188 
  189 void DebugDlgImpl::on_m_pTst01B_clicked()
  190 {
  191     //tstSer01();
  192 //m_pLogModel->selectTopLeft();
  193 
  194     /*TestThread01* p (new TestThread01());
  195 
  196     ThreadRunnerDlgImpl dlg (p, true, this);
  197     dlg.exec();*/
  198 
  199     /*bool b;
  200     QFont f (QFontDialog::getFont(&b, this));
  201     //cout << "font: " << QFontInfo(myOption.font).family().toStdString() << endl;
  202     //cout << "font from dlg: " << f.toString().toStdString() << endl;
  203     printFontInfo("font from dlg", f);
  204 
  205     for (int i = 6; i < 18; ++i)
  206     {
  207         QFont f ("B&H LucidaTypewriter", i);
  208 
  209         QFontInfo info (f);
  210         cout << i << ": " << info.family().toStdString() << ", exactMatch:" << info.exactMatch() << ", fixedPitch:" << info.fixedPitch() << ", italic:" << info.italic() <<
  211             ", pixelSize:" << info.pixelSize() << ", pointSize" << info.pointSize() << endl;
  212     }
  213 */
  214     //tstFont();
  215 
  216 /*
  217     { const char* a ("1998-10-04"); QDateTime dt (QDateTime::fromString(a, Qt::ISODate)); if (!dt.isValid()) cout << a << " is invalid\n"; else cout << dt.toString(Qt::ISODate).toStdString() << endl; }
  218     { const char* a ("1998-10"); QDateTime dt (QDateTime::fromString(a, Qt::ISODate)); if (!dt.isValid()) cout << a << " is invalid\n"; else cout << dt.toString(Qt::ISODate).toStdString() << endl; }
  219     { const char* a ("1998-1-4"); QDateTime dt (QDateTime::fromString(a, Qt::ISODate)); if (!dt.isValid()) cout << a << " is invalid\n"; else cout << dt.toString(Qt::ISODate).toStdString() << endl; }
  220     { const char* a ("1998-1"); QDateTime dt (QDateTime::fromString(a, Qt::ISODate)); if (!dt.isValid()) cout << a << " is invalid\n"; else cout << dt.toString(Qt::ISODate).toStdString() << endl; }
  221     { const char* a ("1998"); QDateTime dt (QDateTime::fromString(a, Qt::ISODate)); if (!dt.isValid()) cout << a << " is invalid\n"; else cout << dt.toString(Qt::ISODate).toStdString() << endl; }
  222     { const char* a ("98"); QDateTime dt (QDateTime::fromString(a, Qt::ISODate)); if (!dt.isValid()) cout << a << " is invalid\n"; else cout << dt.toString(Qt::ISODate).toStdString() << endl; }
  223     { const char* a ("1998-10-04T11:12:13"); QDateTime dt (QDateTime::fromString(a, Qt::ISODate)); if (!dt.isValid()) cout << a << " is invalid\n"; else cout << dt.toString(Qt::ISODate).toStdString() << endl; }
  224     { const char* a ("1998-10-04 11:12:13"); QDateTime dt (QDateTime::fromString(a, Qt::ISODate)); if (!dt.isValid()) cout << a << " is invalid\n"; else cout << dt.toString(Qt::ISODate).toStdString() << endl; }
  225     { const char* a ("1998-10-04T11:12"); QDateTime dt (QDateTime::fromString(a, Qt::ISODate)); if (!dt.isValid()) cout << a << " is invalid\n"; else cout << dt.toString(Qt::ISODate).toStdString() << endl; }
  226     { const char* a ("1998-10-04T11"); QDateTime dt (QDateTime::fromString(a, Qt::ISODate)); if (!dt.isValid()) cout << a << " is invalid\n"; else cout << dt.toString(Qt::ISODate).toStdString() << endl; }
  227     { const char* a ("1998-10-04T11:6"); QDateTime dt (QDateTime::fromString(a, Qt::ISODate)); if (!dt.isValid()) cout << a << " is invalid\n"; else cout << dt.toString(Qt::ISODate).toStdString() << endl; }
  228 */
  229 
  230     //m_transfConfig.testRemoveSuffix();
  231 
  232     //tstGenre();
  233 
  234 
  235 
  236 
  237 
  238 
  239     /*m_pFilesModel->notifyModelChanged();
  240 
  241     char a [100];
  242     sprintf(a, "%d %d", m_pFilesModel->rowCount(QModelIndex()), m_pFilesModel->columnCount(QModelIndex()));
  243     m_pStreamsM->append(a);*/
  244 
  245     //m_pContentM->setTextFormat(LogText);
  246 
  247 /*
  248     QItemSelectionModel* pSelModel (m_pCommonData->m_pFilesG->selectionModel());
  249 m_pCommonData->printFilesCrt();
  250     pSelModel->clear();
  251 m_pCommonData->printFilesCrt();
  252 
  253 if (m_pCommonData->getFilesGCrtRow() > 400000) exit(2);
  254 return;
  255 */
  256 
  257     //resizeEvent(0);
  258 
  259     //m_pContentM->setReadOnly(TRUE);
  260 #if 0
  261     static bool b1 (false);
  262     b1 = !b1;
  263     if (b1)
  264     {
  265         char a [100];
  266         for (int i = 0; i < 10000; ++ i)
  267         {
  268             sprintf(a, "%d                 //Mp3Handler* pMp3Handler (new Mp3Handler(fs.getName())); Mp3Handler", i);
  269             m_pContentM->append(a);
  270         }
  271 
  272         /*char a [100];
  273         string s;
  274         for (int i = 0; i < 1000; ++ i)
  275         {
  276             sprintf(a, "%d                 //Mp3Handler* pMp3Handler (new Mp3Handler(fs.getName())); Mp3Handler\n", i);
  277             s += a;
  278         }
  279         m_pContentM->append(s.c_str());*/
  280     }
  281     else
  282     {
  283         m_pContentM->setText("");
  284     }
  285 #endif
  286 }
  287 
  288 
  289 //========================================================================================================================================================
  290 //========================================================================================================================================================
  291 //========================================================================================================================================================
  292 
  293 #if 0
  294 
  295 #include <iostream>
  296 
  297 struct Base
  298 {
  299     ciobi_ser::SerHelper<Base> m_serHelper;
  300     Base(ciobi_ser::Univ* pUniv, int n1) : m_serHelper(*this, pUniv), m_n1(n1) {}
  301     //template <class T> Base(T& obj, ciobi_ser::Univ* pUniv, int n1) : m_serHelper(obj, pUniv), m_n1(n1) {}
  302     Base(ciobi_ser::ForSerOnly*) : m_serHelper(*this, 0) {}
  303     virtual ~Base()
  304     {
  305     }
  306 
  307     int m_n1;
  308 
  309     virtual void print(ostream& out) const
  310     {
  311         out << "Base: " << m_n1 << endl;
  312     }
  313 
  314     virtual void save(const ciobi_ser::Univ& univ)
  315     {
  316         //univ.saveCPE(m_vpMasterDirs);
  317         univ.save(m_n1);
  318         cout << "saved base: " << m_n1 << endl;
  319     }
  320 
  321     virtual void load(ciobi_ser::Univ& univ)
  322     {
  323         //univ.loadCPE(m_vpMasterDirs);
  324         univ.load(m_n1);
  325         cout << "loaded base: " << m_n1 << endl;
  326     }
  327 
  328     virtual const char* getClassName() const { return ciobi_ser::ClassName<Base>::szClassName; }
  329 };
  330 
  331 
  332 struct Der : public Base
  333 {
  334     //ciobi_ser::SerHelper<Der> m_serHelper;
  335     //Der(ciobi_ser::Univ* pUniv, int n1, int n2) : Base(pUniv, n1), m_serHelper(*this, pUniv), m_n2(n2) {}
  336     //Der(ciobi_ser::Univ* pUniv, int n1, int n2) : Base(*this, pUniv, n1), m_n2(n2) {}
  337     Der(ciobi_ser::Univ* pUniv, int n1, int n2) : Base(pUniv, n1), m_n2(n2) {}
  338     Der(ciobi_ser::ForSerOnly* p) : Base(p) {}
  339 
  340     int m_n2;
  341 
  342     /*override*/ void print(ostream& out) const
  343     {
  344         out << "Der: " << m_n1 << ", " << m_n2 << endl;
  345     }
  346 
  347     /*override*/ void save(const ciobi_ser::Univ& univ)
  348     {
  349         Base::save(univ);
  350         univ.save(m_n2);
  351         cout << "saved der: " << m_n1 << ", " << m_n2 << endl;
  352     }
  353 
  354     /*override*/ void load(ciobi_ser::Univ& univ)
  355     {
  356         Base::load(univ);
  357         univ.load(m_n2);
  358         cout << "loaded der: " << m_n1 << ", " << m_n2 << endl;
  359     }
  360 
  361     /*override*/ const char* getClassName() const { return ciobi_ser::ClassName<Der>::szClassName; }
  362 };
  363 
  364 
  365 template<> /*static*/ const char* ciobi_ser::ClassName<Base>::szClassName ("Base");
  366 template<> /*static*/ const char* ciobi_ser::ClassName<Der>::szClassName ("Der");
  367 
  368 
  369 // explicit instantiation
  370 template class ciobi_ser::SerHelper<Der>;
  371 
  372 
  373 ostream& operator<<(ostream& out, const Base& o)
  374 {
  375     o.print(out);
  376     return out;
  377 }
  378 
  379 
  380 
  381 //=================================================================================================================
  382 
  383 struct Container
  384 {
  385     ciobi_ser::SerHelper<Container> m_serHelper;
  386     Container(ciobi_ser::Univ* pUniv, int n) : m_serHelper(*this, pUniv)
  387     {
  388         int k (1);
  389         for (int i = 0; i < n; ++i, k *= 2)
  390         {
  391             Base* p (i % 2 ? new Base(pUniv, k) : new Der(pUniv, k, k + 1));
  392             //Base* p (new Base(pUniv, k));
  393             m_v.push_back(p);
  394         }
  395     }
  396 
  397     Container(ciobi_ser::ForSerOnly*) : m_serHelper(*this, 0) {}
  398     virtual ~Container()
  399     {
  400     }
  401 
  402     vector<Base*> m_v;
  403 
  404     void save(const ciobi_ser::Univ& univ)
  405     {
  406         //univ.saveCPE(m_vpMasterDirs);
  407         univ.saveCP(m_v);
  408         cout << "saved container: " << endl;
  409     }
  410 
  411     void load(ciobi_ser::Univ& univ)
  412     {
  413         //univ.loadCPE(m_vpMasterDirs);
  414         univ.loadCP(m_v);
  415         cout << "loaded container, size " << cSize(m_v) << endl;
  416         for (int i = 0; i < cSize(m_v); ++i)
  417         {
  418             cout << *m_v[i];
  419         }
  420     }
  421 
  422     const char* getClassName() const { return ciobi_ser::ClassName<Container>::szClassName; }
  423 };
  424 
  425 template<> /*static*/ const char* ciobi_ser::ClassName<Container>::szClassName ("Container");
  426 
  427 
  428 void tstVec01(bool bSave)
  429 {
  430     ciobi_ser::Univ univ;
  431     univ.setDestroyOption(ciobi_ser::Univ::DO_NOTHING); // DELETE_SORTED_OBJECTS
  432     const char* szFile ("savePolymVec.tser");
  433 
  434     if (bSave)
  435     {
  436         Container c (&univ, 4);
  437 
  438         ciobi_ser::SaveOptions so(ciobi_ser::SaveOptions::TEXT, 1, 1, ciobi_ser::SaveOptions::USE_OBJ_INFO, ciobi_ser::SaveOptions::DONT_USE_SEP, ciobi_ser::SaveOptions::USE_COMMENTS);
  439         univ.saveToFile(&c, szFile, "tst polym univ name", so);
  440         return;
  441     }
  442 
  443     Container* p;
  444     univ.loadFromFile(p, szFile);
  445 }
  446 
  447 //=================================================================================================================
  448 
  449 
  450 void tstBase01(bool bSave)
  451 {
  452     ciobi_ser::Univ univ;
  453     univ.setDestroyOption(ciobi_ser::Univ::DO_NOTHING); // DELETE_SORTED_OBJECTS
  454     const char* szFile ("saveBase01.tser");
  455 
  456     if (bSave)
  457     {
  458         Base b1 (&univ, 3);
  459 
  460         ciobi_ser::SaveOptions so(ciobi_ser::SaveOptions::TEXT, 1, 1/*, ciobi_ser::SaveOptions::DONT_USE_OBJ_INFO, ciobi_ser::SaveOptions::DONT_USE_SEP, ciobi_ser::SaveOptions::DONT_USE_COMMENTS*/);
  461 //cout << 1 << endl;
  462         univ.saveToFile(&b1, szFile, "tst base 01 univ name", so);
  463 //cout << 2 << endl;
  464         return;
  465     }
  466 
  467     Base* pb1;
  468     univ.loadFromFile(pb1, szFile);
  469 }
  470 
  471 
  472 void tstDer01(bool bSave)
  473 {
  474     ciobi_ser::Univ univ;
  475     univ.setDestroyOption(ciobi_ser::Univ::DO_NOTHING); // DELETE_SORTED_OBJECTS
  476     const char* szFile ("saveDer01.tser");
  477 
  478     if (bSave)
  479     {
  480         Der d (&univ, 4, 6);
  481 
  482         ciobi_ser::SaveOptions so(ciobi_ser::SaveOptions::TEXT, 1, 1);
  483         univ.saveToFile(&d, szFile, "tst der 01 univ name", so);
  484         return;
  485     }
  486 
  487     Der* p;
  488     univ.loadFromFile(p, szFile);
  489 }
  490 
  491 
  492 //=================================================================================================================
  493 //=================================================================================================================
  494 
  495 
  496 struct Emb
  497 {
  498     //ciobi_ser::SerHelper<Base> m_serHelper;
  499     Emb(int n1) : /*m_serHelper(*this, pUniv),*/ m_n1(n1) {}
  500     Emb(ciobi_ser::ForSerOnly*) /*m_serHelper(*this, 0)*/ {}
  501 
  502     int m_n1;
  503 
  504     void save(const ciobi_ser::Univ& univ)
  505     {
  506         univ.save(m_n1);
  507     }
  508 
  509     void load(ciobi_ser::Univ& univ)
  510     {
  511         univ.load(m_n1);
  512     }
  513 
  514     void print(ostream& out) const
  515     {
  516         out << "Emb: " << m_n1 << endl;
  517     }
  518 };
  519 
  520 ostream& operator<<(ostream& out, const Emb& emb)
  521 {
  522     emb.print(out);
  523     return out;
  524 }
  525 
  526 
  527 struct Encl
  528 {
  529     ciobi_ser::SerHelper<Encl> m_serHelper;
  530     Encl(ciobi_ser::Univ* pUniv, int n) : m_serHelper(*this, pUniv)
  531     {
  532         int k (1);
  533         for (int i = 0; i <= n; ++i)
  534         {
  535             Emb* p (new Emb(k));
  536             m_v.push_back(p);
  537             k *= 2;
  538         }
  539     }
  540 
  541     Encl(ciobi_ser::ForSerOnly*) : m_serHelper(*this, 0) {}
  542 
  543     vector<Emb*> m_v;
  544 
  545     void save(const ciobi_ser::Univ& univ)
  546     {
  547         univ.saveCPE(m_v);
  548         cout << "saved encl\n";
  549     }
  550 
  551     void load(ciobi_ser::Univ& univ)
  552     {
  553         univ.loadCPE(m_v);
  554         cout << "loaded encl:";
  555         int n (cSize(m_v));
  556         for (int i = 0; i < n; ++i)
  557         {
  558             cout << *m_v[i];
  559         }
  560         cout << endl;
  561     }
  562 
  563     const char* getClassName() const { return ciobi_ser::ClassName<Encl>::szClassName; }
  564 };
  565 
  566 template<> /*static*/ const char* ciobi_ser::ClassName<Encl>::szClassName ("Encl");
  567 
  568 
  569 
  570 void tstEmbVec01(bool bSave)
  571 {
  572     ciobi_ser::Univ univ;
  573     univ.setDestroyOption(ciobi_ser::Univ::DO_NOTHING); // DELETE_SORTED_OBJECTS
  574     const char* szFile ("saveEncl01.tser");
  575 
  576     if (bSave)
  577     {
  578         Encl e (&univ, 8);
  579 
  580         ciobi_ser::SaveOptions so(ciobi_ser::SaveOptions::TEXT, 1, 1);
  581         univ.saveToFile(&e, szFile, "tst encl univ name", so);
  582         return;
  583     }
  584 
  585     Encl* p;
  586     univ.loadFromFile(p, szFile);
  587 }
  588 
  589 
  590 #endif
  591 
  592 //========================================================================================================================================================
  593 //========================================================================================================================================================
  594 //========================================================================================================================================================
  595 
  596 #if 0
  597 
  598 #include <iostream>
  599 
  600 struct BoostTstBase
  601 {
  602     BoostTstBase(int n1) : m_n1(n1) {}
  603     virtual ~BoostTstBase()
  604     {
  605     }
  606 
  607     int m_n1;
  608 
  609     virtual void print(ostream& out) const
  610     {
  611         out << "BoostTstBase: " << m_n1 << endl;
  612     }
  613 
  614 protected:
  615     BoostTstBase() {}
  616 private:
  617     friend class boost::serialization::access;
  618 
  619     template<class Archive>
  620     void serialize(Archive& ar, const unsigned int /*nVersion*/)
  621     {
  622         ar & m_n1;
  623     }
  624 };
  625 
  626 
  627 struct BoostTstDer : public BoostTstBase
  628 {
  629     BoostTstDer(int n1, int n2) : BoostTstBase(n1), m_n2(n2) {}
  630 
  631     int m_n2;
  632 
  633     /*override*/ void print(ostream& out) const
  634     {
  635         out << "BoostTstDer: " << m_n1 << ", " << m_n2 << endl;
  636     }
  637 
  638 private:
  639     friend class boost::serialization::access;
  640     BoostTstDer() {}
  641 
  642     template<class Archive>
  643     void serialize(Archive& ar, const unsigned int /*nVersion*/)
  644     {
  645         ar & boost::serialization::base_object<BoostTstBase>(*this);
  646         ar & m_n2;
  647     }
  648 };
  649 
  650 
  651 
  652 
  653 ostream& operator<<(ostream& out, const BoostTstBase& o)
  654 {
  655     o.print(out);
  656     return out;
  657 }
  658 
  659 
  660 
  661 //=================================================================================================================
  662 
  663 struct BoostContainer
  664 {
  665     BoostContainer(int n)
  666     {
  667         int k (1);
  668         for (int i = 0; i < n; ++i, k *= 2)
  669         {
  670             BoostTstBase* p (i % 2 ? new BoostTstBase(k) : new BoostTstDer(k, k + 1));
  671             m_v.push_back(p);
  672         }
  673     }
  674 
  675     virtual ~BoostContainer()
  676     {
  677     }
  678 
  679     vector<BoostTstBase*> m_v;
  680 
  681     /*void save()
  682     {
  683         //univ.saveCPE(m_vpMasterDirs);
  684         univ.saveCP(m_v);
  685         cout << "saved container: " << endl;
  686     }
  687 
  688     void load()
  689     {
  690         //univ.loadCPE(m_vpMasterDirs);
  691         univ.loadCP(m_v);
  692     }*/
  693 private:
  694     friend class boost::serialization::access;
  695     BoostContainer() {}
  696 
  697     template<class Archive>
  698     void serialize(Archive& ar, const unsigned int /*nVersion*/)
  699     {
  700         ar & m_v;
  701     }
  702 };
  703 
  704 
  705 
  706 void tstBoostVec01(bool bSave)
  707 {
  708     const char* szFile ("savePolymVec.boost.ser");
  709 
  710     if (bSave)
  711     {
  712         BoostContainer* p (new BoostContainer(4));
  713 
  714         ofstream_utf8 out (szFile);
  715         //boost::archive::text_oarchive oar (out);
  716         boost::archive::binary_oarchive oar (out);
  717 
  718         oar.register_type<BoostTstDer>();
  719         oar.register_type<BoostTstBase>();
  720         oar.register_type<BoostContainer>();
  721 
  722         //BoostContainer* q (p);
  723         //BoostContainer* const q (p);
  724         //const BoostContainer* const q2 (p);
  725 
  726         //oar << const_cast<const BoostContainer const*>(p);
  727         //oar << q;
  728         oar << (BoostContainer* const)p;
  729         //oar << q;
  730         return;
  731     }
  732 
  733     BoostContainer* p;
  734     ifstream_utf8 in (szFile);
  735     //boost::archive::text_iarchive iar (in);
  736     boost::archive::binary_iarchive iar (in);
  737     iar.register_type<BoostTstDer>();
  738     iar.register_type<BoostTstBase>();
  739     iar.register_type<BoostContainer>();
  740 
  741     iar >> p;
  742 
  743     cout << "loaded container, size " << cSize(p->m_v) << endl;
  744     for (int i = 0; i < cSize(p->m_v); ++i)
  745     {
  746         cout << *p->m_v[i];
  747     }
  748 }
  749 
  750 //=================================================================================================================
  751 #if 0
  752 
  753 void tstBase01(bool bSave)
  754 {
  755     const char* szFile ("saveBase01.tser");
  756 
  757     if (bSave)
  758     {
  759         BoostTstBase b1 (&univ, 3);
  760 
  761         univ.saveToFile(&b1, szFile, "tst base 01 univ name", so);
  762 //cout << 2 << endl;
  763         return;
  764     }
  765 
  766     BoostTstBase* pb1;
  767     univ.loadFromFile(pb1, szFile);
  768 }
  769 
  770 
  771 void tstDer01(bool bSave)
  772 {
  773     const char* szFile ("saveDer01.tser");
  774 
  775     if (bSave)
  776     {
  777         BoostTstDer d (4, 6);
  778 
  779         univ.saveToFile(&d, szFile, "tst der 01 univ name", so);
  780         return;
  781     }
  782 
  783     BoostTstDer* p;
  784     univ.loadFromFile(p, szFile);
  785 }
  786 
  787 //=================================================================================================================
  788 
  789 
  790 
  791 
  792 //=================================================================================================================
  793 //=================================================================================================================
  794 
  795 
  796 struct Emb
  797 {
  798     Emb(int n1) : /*m_serHelper(*this, pUniv),*/ m_n1(n1) {}
  799 
  800     int m_n1;
  801 
  802     void save()
  803     {
  804         univ.save(m_n1);
  805     }
  806 
  807     void load()
  808     {
  809         univ.load(m_n1);
  810     }
  811 
  812     void print(ostream& out) const
  813     {
  814         out << "Emb: " << m_n1 << endl;
  815     }
  816 };
  817 
  818 ostream& operator<<(ostream& out, const Emb& emb)
  819 {
  820     emb.print(out);
  821     return out;
  822 }
  823 
  824 
  825 struct Encl
  826 {
  827     Encl(int n)
  828     {
  829         int k (1);
  830         for (int i = 0; i <= n; ++i)
  831         {
  832             Emb* p (new Emb(k));
  833             m_v.push_back(p);
  834             k *= 2;
  835         }
  836     }
  837 
  838     vector<Emb*> m_v;
  839 
  840     void save()
  841     {
  842         univ.saveCPE(m_v);
  843         cout << "saved encl\n";
  844     }
  845 
  846     void load()
  847     {
  848         univ.loadCPE(m_v);
  849         cout << "loaded encl:";
  850         int n (cSize(m_v));
  851         for (int i = 0; i < n; ++i)
  852         {
  853             cout << *m_v[i];
  854         }
  855         cout << endl;
  856     }
  857 };
  858 
  859 
  860 
  861 void tstEmbVec01(bool bSave)
  862 {
  863     const char* szFile ("saveEncl01.tser");
  864 
  865     if (bSave)
  866     {
  867         Encl e (&univ, 8);
  868 
  869         univ.saveToFile(&e, szFile, "tst encl univ name", so);
  870         return;
  871     }
  872 
  873     Encl* p;
  874     univ.loadFromFile(p, szFile);
  875 }
  876 #endif
  877 #endif
  878 
  879 //=================================================================================================================
  880 
  881 #if 0
  882 #include "fstream_unicode.h"
  883 
  884 // include headers that implement a archive in simple text format
  885 #include <boost/archive/text_oarchive.hpp>
  886 #include <boost/archive/text_iarchive.hpp>
  887 
  888 /////////////////////////////////////////////////////////////
  889 // gps coordinate
  890 //
  891 // illustrates serialization for a simple type
  892 //
  893 class gps_position
  894 {
  895 private:
  896     friend class boost::serialization::access;
  897     // When the class Archive corresponds to an output archive, the
  898     // & operator is defined similar to <<.  Likewise, when the class Archive
  899     // is a type of input archive the & operator is defined similar to >>.
  900     template<class Archive>
  901     void serialize(Archive& ar, const unsigned int version)
  902     {
  903         ar & degrees;
  904         ar & minutes;
  905         ar & seconds;
  906     }
  907     int degrees;
  908     int minutes;
  909     float seconds;
  910 public:
  911     gps_position(){};
  912     gps_position(int d, int m, float s) :
  913         degrees(d), minutes(m), seconds(s)
  914     {}
  915 };
  916 
  917 int tutorial() {
  918     // create and open a character archive for output
  919     ofstream_utf8 ofs("filename");
  920 
  921     // create class instance
  922     const gps_position g(35, 59, 24.567f);
  923 
  924     // save data to archive
  925     {
  926         boost::archive::text_oarchive oa(ofs);
  927         // write class instance to archive
  928         oa << g;
  929         // archive and stream closed when destructors are called
  930     }
  931 
  932     // ... some time later restore the class instance to its orginal state
  933     gps_position newg;
  934     {
  935         // create and open an archive for input
  936         ifstream_utf8 ifs("filename", std::ios::binary);
  937         boost::archive::text_iarchive ia(ifs);
  938         // read class state from archive
  939         ia >> newg;
  940         // archive and stream closed when destructors are called
  941     }
  942     return 0;
  943 }
  944 #endif
  945 
  946 #if 0
  947 void tstSer01()
  948 {
  949     //tstBase01(1 == argc);
  950     //tstDer01(1 == argc);
  951     //tstVec01(true);
  952     //tstVec01(false);
  953     //tstEmbVec01(1 == argc);
  954 
  955     tstBoostVec01(true);
  956     tstBoostVec01(false);
  957 
  958     //tutorial();
  959 }
  960 #endif
  961 
  962 /*struct TstSer
  963 {
  964     TstSer()
  965     {
  966         //tstBase01(1 == argc);
  967         //tstDer01(1 == argc);
  968         tstVec01(true);
  969         //tstVec01(false);
  970         //tstEmbVec01(1 == argc);
  971 
  972         ::exit(0);
  973     }
  974 };
  975 
  976 TstSer tstSer01;
  977 */
  978 
  979 
  980 
  981 
  982 // -lboost_serialization-mt-1_37
  983 
  984 //ttt2 if "use all notes" is checked, it keeps rescanning at startup
  985 
  986