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 "cmCableDefineSetCommand.h"
|
2001-02-27 02:00:49 +03:00
|
|
|
#include "cmCacheManager.h"
|
|
|
|
|
2001-02-28 00:28:56 +03:00
|
|
|
#include "cmRegularExpression.h"
|
|
|
|
|
2001-02-27 02:00:49 +03:00
|
|
|
|
2001-02-28 17:34:01 +03:00
|
|
|
// cmCableDefineSetCommand
|
|
|
|
bool cmCableDefineSetCommand::Invoke(std::vector<std::string>& args)
|
2001-02-27 02:00:49 +03:00
|
|
|
{
|
|
|
|
if(args.size() < 2)
|
|
|
|
{
|
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-03-02 00:47:05 +03:00
|
|
|
// This command needs access to the Cable data.
|
|
|
|
this->SetupCableData();
|
|
|
|
|
2001-02-27 02:00:49 +03:00
|
|
|
std::vector<std::string>::const_iterator arg = args.begin();
|
|
|
|
|
|
|
|
// The first argument is the name of the set.
|
|
|
|
m_SetName = *arg++;
|
|
|
|
|
|
|
|
// The rest of the arguments are the elements to be placed in the set.
|
|
|
|
for(; arg != args.end(); ++arg)
|
|
|
|
{
|
2001-02-28 00:28:56 +03:00
|
|
|
m_Elements.push_back(Element(this->GenerateTag(*arg), *arg));
|
2001-02-27 02:00:49 +03:00
|
|
|
}
|
|
|
|
|
2001-03-02 00:47:05 +03:00
|
|
|
// Write this command's configuration output.
|
|
|
|
this->WriteConfiguration();
|
|
|
|
|
2001-02-27 02:00:49 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2001-02-28 17:34:01 +03:00
|
|
|
* Write the CABLE configuration code to define this Set.
|
2001-02-27 02:00:49 +03:00
|
|
|
*/
|
2001-03-02 00:47:05 +03:00
|
|
|
void cmCableDefineSetCommand::WriteConfiguration() const
|
2001-02-27 02:00:49 +03:00
|
|
|
{
|
2001-02-28 00:28:56 +03:00
|
|
|
cmRegularExpression needCdataBlock("[&<>]");
|
|
|
|
|
2001-03-02 00:47:05 +03:00
|
|
|
// Get the ouptut information from the cmCableData.
|
|
|
|
std::ostream& os = m_CableData->GetOutputStream();
|
|
|
|
cmCableData::Indentation indent = m_CableData->GetIndentation();
|
|
|
|
|
|
|
|
// Output the code.
|
|
|
|
os << indent << "<Set name=\"" << m_SetName.c_str() << "\">" << std::endl;
|
2001-02-27 02:00:49 +03:00
|
|
|
for(Elements::const_iterator e = m_Elements.begin();
|
|
|
|
e != m_Elements.end(); ++e)
|
|
|
|
{
|
2001-03-02 00:47:05 +03:00
|
|
|
os << indent << " <Element";
|
2001-02-28 00:28:56 +03:00
|
|
|
// Only output the tag if it is not the empty string.
|
|
|
|
if(e->first.length() > 0)
|
|
|
|
{
|
|
|
|
os << " tag=\"" << e->first.c_str() << "\"";
|
|
|
|
}
|
|
|
|
os << ">";
|
|
|
|
if(needCdataBlock.find(e->second.c_str()))
|
|
|
|
{
|
|
|
|
os << "<![CDATA[" << e->second.c_str() << "]]>";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
os << e->second.c_str();
|
|
|
|
}
|
|
|
|
os << "</Element>" << std::endl;
|
2001-02-27 02:00:49 +03:00
|
|
|
}
|
2001-03-02 00:47:05 +03:00
|
|
|
os << indent << "</Set>" << std::endl;
|
2001-02-27 02:00:49 +03:00
|
|
|
}
|
2001-02-28 00:28:56 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given the string representing a set element, automatically generate
|
2001-02-28 17:34:01 +03:00
|
|
|
* the CABLE element tag for it.
|
2001-02-28 00:28:56 +03:00
|
|
|
*
|
|
|
|
* **This function determines how the output language of all
|
2001-02-28 17:34:01 +03:00
|
|
|
* CABLE-generated wrappers will look!**
|
2001-02-28 00:28:56 +03:00
|
|
|
*/
|
|
|
|
std::string
|
2001-02-28 17:34:01 +03:00
|
|
|
cmCableDefineSetCommand::GenerateTag(const std::string& element) const
|
2001-02-28 00:28:56 +03:00
|
|
|
{
|
|
|
|
// Hold the regular expressions for matching against the element.
|
|
|
|
cmRegularExpression regex;
|
|
|
|
|
|
|
|
// If the element's code begins in a $, it is referring to a set name.
|
|
|
|
// The set's elements have their own tags, so we don't need one.
|
|
|
|
regex.compile("^[ \t]*\\$");
|
|
|
|
if(regex.find(element))
|
|
|
|
{ return ""; }
|
|
|
|
|
|
|
|
// Test for simple integer
|
|
|
|
regex.compile("^[ \t]*([0-9]*)[ \t]*$");
|
|
|
|
if(regex.find(element))
|
|
|
|
{
|
|
|
|
std::string tag = "_";
|
|
|
|
tag.append(regex.match(1));
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test for basic integer type
|
|
|
|
regex.compile("^[ \t]*(unsigned[ ]|signed[ ])?[ \t]*(char|short|int|long|long[ ]long)[ \t]*$");
|
|
|
|
if(regex.find(element))
|
|
|
|
{
|
|
|
|
std::string tag = "_";
|
|
|
|
if(regex.match(1) == "unsigned ")
|
|
|
|
{ tag.append("u"); }
|
|
|
|
if(regex.match(2) == "long long")
|
|
|
|
{ tag.append("llong"); }
|
|
|
|
else
|
|
|
|
{ tag.append(regex.match(2)); }
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test for basic floating-point type
|
|
|
|
regex.compile("^[ \t]*(long[ ])?[ \t]*(float|double)[ \t]*$");
|
|
|
|
if(regex.find(element))
|
|
|
|
{
|
|
|
|
std::string tag = "_";
|
|
|
|
if(regex.match(1) == "long ")
|
|
|
|
tag.append("l");
|
|
|
|
tag.append(regex.match(2));
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test for basic wide-character type
|
|
|
|
regex.compile("^[ \t]*(wchar_t)[ \t]*$");
|
|
|
|
if(regex.find(element))
|
|
|
|
{
|
|
|
|
return "_wchar";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test for plain type name (without template arguments).
|
|
|
|
regex.compile("^[ \t]*([A-Za-z_][A-Za-z0-9_]*)[ \t]*$");
|
|
|
|
if(regex.find(element))
|
|
|
|
{
|
|
|
|
// The tag is the same as the type.
|
|
|
|
return regex.match(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test for template class instance.
|
|
|
|
regex.compile("^[ \t]*([A-Za-z_][A-Za-z0-9_]*)<.*[ \t]*$");
|
|
|
|
if(regex.find(element))
|
|
|
|
{
|
|
|
|
// The tag is the type without arguments (the arguments may have
|
|
|
|
// their own tags).
|
|
|
|
return regex.match(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return "NO_AUTO_TAG";
|
|
|
|
}
|