2001-02-27 02:00:49 +03:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
Program: Insight Segmentation & Registration Toolkit
|
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2000 National Library of Medicine
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
See COPYRIGHT.txt for copyright details.
|
|
|
|
|
|
|
|
=========================================================================*/
|
2001-02-28 17:34:01 +03:00
|
|
|
#include "cmCableData.h"
|
2001-02-27 02:00:49 +03:00
|
|
|
#include "cmCacheManager.h"
|
|
|
|
|
2001-03-02 00:47:05 +03:00
|
|
|
#include "cmCablePackageCommand.h"
|
2001-02-27 02:00:49 +03:00
|
|
|
|
|
|
|
/**
|
2001-03-02 00:47:05 +03:00
|
|
|
* The cmCableData instance is owned by one cmCableCommand, which is given
|
|
|
|
* to this constructor.
|
|
|
|
*/
|
2001-03-02 20:27:41 +03:00
|
|
|
cmCableData::cmCableData(const cmCableCommand* owner,
|
|
|
|
const std::string& configurationFile):
|
2001-03-02 00:47:05 +03:00
|
|
|
m_Owner(owner),
|
|
|
|
m_Indentation(0),
|
|
|
|
m_Package(NULL),
|
|
|
|
m_PackageNamespaceDepth(0)
|
|
|
|
{
|
2001-03-02 20:27:41 +03:00
|
|
|
this->OpenOutputFile(configurationFile);
|
2001-03-02 00:47:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free all data that was stored here. Also close the output file.
|
2001-02-27 02:00:49 +03:00
|
|
|
*/
|
2001-02-28 17:34:01 +03:00
|
|
|
cmCableData::~cmCableData()
|
2001-02-27 02:00:49 +03:00
|
|
|
{
|
2001-03-02 00:47:05 +03:00
|
|
|
// End last package, if any.
|
|
|
|
this->EndPackage();
|
|
|
|
|
|
|
|
// Finish up the output file.
|
|
|
|
this->CloseOutputFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open the configuration output file with the given name. This
|
|
|
|
* writes the configuration header.
|
|
|
|
*/
|
|
|
|
void cmCableData::OpenOutputFile(const std::string& name)
|
|
|
|
{
|
|
|
|
m_OutputFile.open(name.c_str());
|
|
|
|
|
|
|
|
if(m_OutputFile)
|
2001-02-27 02:00:49 +03:00
|
|
|
{
|
2001-03-02 00:47:05 +03:00
|
|
|
this->WriteConfigurationHeader();
|
2001-02-27 02:00:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2001-03-02 00:47:05 +03:00
|
|
|
* Close the configuration output file. This writes the configuration
|
|
|
|
* footer.
|
2001-02-27 02:00:49 +03:00
|
|
|
*/
|
2001-03-02 00:47:05 +03:00
|
|
|
void cmCableData::CloseOutputFile()
|
2001-02-27 02:00:49 +03:00
|
|
|
{
|
2001-03-02 00:47:05 +03:00
|
|
|
if(m_OutputFile)
|
2001-02-27 02:00:49 +03:00
|
|
|
{
|
2001-03-02 00:47:05 +03:00
|
|
|
this->WriteConfigurationFooter();
|
|
|
|
m_OutputFile.close();
|
2001-02-27 02:00:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2001-03-02 00:47:05 +03:00
|
|
|
* Write a CABLE configuration file header.
|
2001-02-27 02:00:49 +03:00
|
|
|
*/
|
2001-03-02 00:47:05 +03:00
|
|
|
void cmCableData::WriteConfigurationHeader()
|
2001-02-27 02:00:49 +03:00
|
|
|
{
|
2001-03-02 00:47:05 +03:00
|
|
|
m_OutputFile << m_Indentation << "<?xml version=\"1.0\"?>" << std::endl
|
|
|
|
<< m_Indentation << "<CableConfiguration>" << std::endl;
|
|
|
|
this->Indent();
|
2001-02-27 02:00:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2001-03-02 00:47:05 +03:00
|
|
|
* Write a CABLE configuration file footer.
|
2001-02-27 02:00:49 +03:00
|
|
|
*/
|
2001-03-02 00:47:05 +03:00
|
|
|
void cmCableData::WriteConfigurationFooter()
|
2001-02-27 02:00:49 +03:00
|
|
|
{
|
2001-03-02 00:47:05 +03:00
|
|
|
this->Unindent();
|
|
|
|
m_OutputFile << m_Indentation << "</CableConfiguration>" << std::endl;
|
2001-02-27 02:00:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-02 00:47:05 +03:00
|
|
|
/**
|
|
|
|
* Print indentation spaces.
|
|
|
|
*/
|
2001-02-27 02:00:49 +03:00
|
|
|
void
|
2001-03-02 00:47:05 +03:00
|
|
|
cmCableData::Indentation
|
|
|
|
::Print(std::ostream& os) const
|
|
|
|
{
|
|
|
|
if(m_Indent <= 0)
|
|
|
|
{ return; }
|
|
|
|
|
|
|
|
// Use blocks of 8 spaces to speed up big indents.
|
|
|
|
unsigned int blockCount = m_Indent >> 3;
|
|
|
|
unsigned int singleCount = m_Indent & 7;
|
|
|
|
while(blockCount-- > 0)
|
|
|
|
{
|
|
|
|
os << " ";
|
|
|
|
}
|
|
|
|
while(singleCount-- > 0)
|
|
|
|
{
|
|
|
|
os << " ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a namespace with the given name.
|
|
|
|
*/
|
|
|
|
void cmCableData::OpenNamespace(const std::string& name)
|
2001-02-27 02:00:49 +03:00
|
|
|
{
|
2001-03-02 00:47:05 +03:00
|
|
|
m_NamespaceStack.push_back(name);
|
2001-02-27 02:00:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-02 00:47:05 +03:00
|
|
|
/**
|
|
|
|
* Close the current namespace, checking whether it has the given name.
|
|
|
|
*/
|
|
|
|
void cmCableData::CloseNamespace(const std::string& name)
|
2001-02-27 02:00:49 +03:00
|
|
|
{
|
2001-03-02 00:47:05 +03:00
|
|
|
if(m_NamespaceStack.empty())
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("Unbalanced close-namespace = ", name.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(m_NamespaceStack.back() != name)
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("Wrong name on close-namespace = ", name.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this closes the namespace where the current package was opened,
|
|
|
|
// the package must end as well.
|
|
|
|
if(m_Package && (m_PackageNamespaceDepth == m_NamespaceStack.size()))
|
|
|
|
{
|
|
|
|
this->EndPackage();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_NamespaceStack.pop_back();
|
2001-02-27 02:00:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-02 00:47:05 +03:00
|
|
|
/**
|
|
|
|
* Begin a new package definition. If there is a current one, it
|
|
|
|
* will be ended.
|
|
|
|
*/
|
|
|
|
void cmCableData::BeginPackage(cmCablePackageCommand* command)
|
2001-02-27 02:00:49 +03:00
|
|
|
{
|
2001-03-02 00:47:05 +03:00
|
|
|
// Close the current package, if any.
|
|
|
|
this->EndPackage();
|
|
|
|
|
|
|
|
// Open this package.
|
|
|
|
m_Package = command;
|
|
|
|
|
|
|
|
// Save the package's opening namespace depth for later verification
|
|
|
|
// on the end of the package.
|
|
|
|
m_PackageNamespaceDepth = m_NamespaceStack.size();
|
2001-02-27 02:00:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2001-03-02 00:47:05 +03:00
|
|
|
* End a package definition.
|
2001-02-27 02:00:49 +03:00
|
|
|
*/
|
2001-03-02 00:47:05 +03:00
|
|
|
void cmCableData::EndPackage()
|
2001-02-27 02:00:49 +03:00
|
|
|
{
|
2001-03-02 00:47:05 +03:00
|
|
|
// Make sure we have an open package.
|
|
|
|
if(!m_Package)
|
2001-02-27 02:00:49 +03:00
|
|
|
{
|
2001-03-02 00:47:05 +03:00
|
|
|
return;
|
2001-02-27 02:00:49 +03:00
|
|
|
}
|
|
|
|
|
2001-03-02 00:47:05 +03:00
|
|
|
// Make sure the namespace nesting depth matches the opening depth
|
|
|
|
// of the package.
|
|
|
|
if(m_PackageNamespaceDepth != m_NamespaceStack.size())
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("Package ended at different namespace depth than"
|
|
|
|
"it was created!", "");
|
|
|
|
}
|
|
|
|
// Write out the package's footer.
|
|
|
|
m_Package->WritePackageFooter();
|
2001-02-27 02:00:49 +03:00
|
|
|
|
2001-03-02 00:47:05 +03:00
|
|
|
// Done with the package.
|
|
|
|
m_Package = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Simplify indentation printing by allowing Indentation objects to be added
|
|
|
|
* to streams.
|
|
|
|
*/
|
|
|
|
std::ostream& operator<<(std::ostream& os,
|
|
|
|
const cmCableData::Indentation& indent)
|
|
|
|
{
|
|
|
|
indent.Print(os);
|
|
|
|
return os;
|
2001-02-27 02:00:49 +03:00
|
|
|
}
|
|
|
|
|