<commit_before>/* Begin CVS Header
   $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/xml/CCopasiXML.cpp,v $
   $Revision: 1.71 $
   $Name:  $
   $Author: ssahle $ 
   $Date: 2005/10/26 18:23:39 $
   End CVS Header */

/**
 * CCopasiXML class.
 * This class implements a CCopasiXMLInterface to the COPASI XML specified in
 * http://www.copasi.org/schema/copasi.xsd
 *
 * Created for Copasi by <NAME> 2003
 * Copyright <NAME>
 */
#include <iostream>
#include "copasi.h"
#include <map>

#include "CCopasiXML.h"
#include "CCopasiXMLParser.h"
#include "CCopasiXMLVersion.h"

#include "CopasiDataModel/CCopasiDataModel.h"
#include "utilities/CCopasiVector.h"
#include "utilities/CSlider.h"
#include "model/CModel.h"
#include "model/CState.h"
#include "function/CFunctionDB.h"
#include "function/CEvaluationTree.h"
#include "report/CReportDefinitionVector.h"
#include "utilities/CCopasiTask.h"
#include "utilities/CCopasiMethod.h"
#include "utilities/CCopasiProblem.h"
#include "utilities/utility.h"
#include "plot/COutputDefinitionVector.h"
#include "plot/CPlotItem.h"

// class CCopasiTask;
// class CCopasiReport;

CCopasiXML::CCopasiXML():
    CCopasiXMLInterface()
{
  mVersion.setVersion(COPASI_XML_VERSION_MAJOR,
                      COPASI_XML_VERSION_MINOR,
                      COPASI_XML_VERSION_BUILD);
}

CCopasiXML::~CCopasiXML() {}

bool CCopasiXML::save(std::ostream & os)
{
  mpOstream = &os;
  bool success = true;

  *mpOstream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
  << std::endl;

  *mpOstream << "<!-- generated with COPASI "
  << CCopasiDataModel::Global->getVersion()->getVersion()
  << " (http://www.copasi.org) at "
  << UTCTimeStamp()
  << " UTC -->"
  << std::endl;

  CXMLAttributeList Attributes;
  Attributes.add("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
  Attributes.add("xsi:noNamespaceSchemaLocation",
                 "http://calvin.bioinformatics.vt.edu/copasi/schema/copasi.xsd");
  Attributes.add("versionMajor", mVersion.getVersionMajor());
  Attributes.add("versionMinor", mVersion.getVersionMinor());

  startSaveElement("COPASI", Attributes);

  if (haveModel() && !haveFunctionList())
    {
      if (!buildFunctionList()) success = false;
      if (!saveFunctionList()) success = false;
      if (!freeFunctionList()) success = false;
    }
  else
    if (!saveFunctionList()) success = false;

  if (!saveModel()) success = false;
  if (!saveTaskList()) success = false;
  if (!saveReportList()) success = false;
  if (!savePlotList()) success = false;
  if (!saveGUI()) success = false;
  if (!saveSBMLReference()) success = false;

  endSaveElement("COPASI");

  return success;
}

bool CCopasiXML::load(std::istream & is)
{
  mpIstream = &is;
  bool success = true;
  bool done = false;

  CCopasiXMLParser Parser(mVersion);

  Parser.setFunctionList(mpFunctionList);
  Parser.setModel(mpModel);
  Parser.setReportList(mpReportList);
  Parser.setTaskList(mpTaskList);
  Parser.setPlotList(mpPlotList);
  Parser.setGUI(mpGUI);

#define BUFFER_SIZE 0xfffe
  char * pBuffer = new char[BUFFER_SIZE + 1];<commit_msg>Assured that the locale for category LC_NUMERIC is set to "C" while writing XML.<commit_after>/* Begin CVS Header
   $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/xml/CCopasiXML.cpp,v $
   $Revision: 1.72 $
   $Name:  $
   $Author: shoops $ 
   $Date: 2005/10/26 18:47:30 $
   End CVS Header */

/**
 * CCopasiXML class.
 * This class implements a CCopasiXMLInterface to the COPASI XML specified in
 * http://www.copasi.org/schema/copasi.xsd
 *
 * Created for Copasi by <NAME> 2003
 * Copyright <NAME>
 */
#include <iostream>
#include "copasi.h"
#include <map>

#include "CCopasiXML.h"
#include "CCopasiXMLParser.h"
#include "CCopasiXMLVersion.h"

#include "CopasiDataModel/CCopasiDataModel.h"
#include "utilities/CCopasiVector.h"
#include "utilities/CSlider.h"
#include "model/CModel.h"
#include "model/CState.h"
#include "function/CFunctionDB.h"
#include "function/CEvaluationTree.h"
#include "report/CReportDefinitionVector.h"
#include "utilities/CCopasiTask.h"
#include "utilities/CCopasiMethod.h"
#include "utilities/CCopasiProblem.h"
#include "utilities/utility.h"
#include "plot/COutputDefinitionVector.h"
#include "plot/CPlotItem.h"

// class CCopasiTask;
// class CCopasiReport;

CCopasiXML::CCopasiXML():
    CCopasiXMLInterface()
{
  mVersion.setVersion(COPASI_XML_VERSION_MAJOR,
                      COPASI_XML_VERSION_MINOR,
                      COPASI_XML_VERSION_BUILD);
}

CCopasiXML::~CCopasiXML() {}

bool CCopasiXML::save(std::ostream & os)
{
  char * locale = strdup(setlocale(LC_NUMERIC, NULL));
  setlocale(LC_NUMERIC, "C");

  mpOstream = &os;
  bool success = true;

  *mpOstream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
  << std::endl;

  *mpOstream << "<!-- generated with COPASI "
  << CCopasiDataModel::Global->getVersion()->getVersion()
  << " (http://www.copasi.org) at "
  << UTCTimeStamp()
  << " UTC -->"
  << std::endl;

  CXMLAttributeList Attributes;
  Attributes.add("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
  Attributes.add("xsi:noNamespaceSchemaLocation",
                 "http://calvin.bioinformatics.vt.edu/copasi/schema/copasi.xsd");
  Attributes.add("versionMajor", mVersion.getVersionMajor());
  Attributes.add("versionMinor", mVersion.getVersionMinor());

  startSaveElement("COPASI", Attributes);

  if (haveModel() && !haveFunctionList())
    {
      if (!buildFunctionList()) success = false;
      if (!saveFunctionList()) success = false;
      if (!freeFunctionList()) success = false;
    }
  else
    if (!saveFunctionList()) success = false;

  if (!saveModel()) success = false;
  if (!saveTaskList()) success = false;
  if (!saveReportList()) success = false;
  if (!savePlotList()) success = false;
  if (!saveGUI()) success = false;
  if (!saveSBMLReference()) success = false;

  endSaveElement("COPASI");

  setlocale(LC_NUMERIC, locale);
  pdelete(locale);

  return success;
}

bool CCopasiXML::load(std::istream & is)
{
  mpIstream = &is;
  bool success = true;
  bool done = false;

  CCopasiXMLParser Parser(mVersion);

  Parser.setFunctionList(mpFunctionList);
  Parser.setModel(mpModel);
  Parser.setReportList(mpReportList);
  Parser.setTaskList(mpTaskList);
  Parser.setPlotList(mpPlotList);
  Parser.setGUI(mpGUI);

#define BUFFER_SIZE 0xfffe
  char * pBuffer = new char[BUFFER_SIZE + 1];
{'fraction_non_alphanumeric': 0.1511737089201878, 'fraction_numerical': 0.00970266040688576, 'mean_word_length': 4.352596314907872, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 2, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2194945', 'n_tokens_mistral': 2352, 'n_tokens_neox': 2231, 'n_words': 417}