Import Geant4 10.5.0 source tree

This commit is contained in:
Gabriele Cosmo
2018-12-07 15:15:39 +01:00
parent 6aa23be517
commit db49709b53
11370 changed files with 187480 additions and 160142 deletions
File diff suppressed because it is too large Load Diff
+102 -103
View File
@@ -1,103 +1,102 @@
// Copyright FreeHEP, 2005.
#include "cheprep/DefaultHepRep.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
* @version $Id: DefaultHepRep.cc 66373 2012-12-18 09:41:34Z gcosmo $
*/
namespace cheprep {
DefaultHepRep::DefaultHepRep() {
}
DefaultHepRep::~DefaultHepRep() {
for (vector<HepRepTypeTree*>::iterator i1 = typeTrees.begin(); i1 != typeTrees.end(); i1++) {
delete (*i1);
}
for (vector<HepRepInstanceTree*>::iterator i2 = instanceTrees.begin(); i2 != instanceTrees.end(); i2++) {
delete (*i2);
}
}
HepRep* DefaultHepRep::copy(HepRepSelectFilter*) {
cerr << "DefaultHepRep::copy(HepRepSelectFilter*) not implemented." << endl;
return NULL;
}
vector<string> DefaultHepRep::getLayerOrder() {
return layers;
}
void DefaultHepRep::addLayer(string layer) {
layers.push_back(layer);
}
void DefaultHepRep::addTypeTree(HepRepTypeTree* typeTree) {
// FIXME check if already exist
typeTrees.push_back(typeTree);
}
void DefaultHepRep::removeTypeTree(HepRepTypeTree*) {
cerr << "DefaultHepRep::removeTypeTree(HepRepTypeTree*) not implemented." << endl;
}
HepRepTypeTree* DefaultHepRep::getTypeTree(string, string) {
cerr << "DefaultHepRep::getTypeTree(string, string) not implemented." << endl;
return NULL;
}
vector<HepRepTypeTree*> DefaultHepRep::getTypeTreeList() {
return typeTrees;
}
void DefaultHepRep::addInstanceTree(HepRepInstanceTree* instanceTree) {
// FIXME check if already exist
instanceTrees.push_back(instanceTree);
}
void DefaultHepRep::overlayInstanceTree(HepRepInstanceTree *) {
cerr << "DefaultHepRep::overlayInstanceTree(HepRepInstanceTree * instanceTree) not implemented." << endl;
}
void DefaultHepRep::removeInstanceTree(HepRepInstanceTree*) {
cerr << "DefaultHepRep::removeInstanceTree(HepRepInstanceTree*) not implemented." << endl;
}
HepRepInstanceTree* DefaultHepRep::getInstanceTreeTop(string, string) {
cerr << "DefaultHepRep::getInstanceTreeTop(string, string) not implemented." << endl;
return NULL;
}
HepRepInstanceTree* DefaultHepRep::getInstances(string, string,
vector<string>) {
cerr << "DefaultHepRep::getInstances(string, string, vector<string>) not implemented." << endl;
return NULL;
}
HepRepInstanceTree* DefaultHepRep::getInstancesAfterAction(
string,
string,
vector<string>,
vector<HepRepAction*>,
bool,
bool,
bool,
vector<string>) {
cerr << "DefaultHepRep::getInstancesAfterAction(string, string, vector<string>, vector<HepRepAction*>, bool, bool, bool, vector<string>) not implemented." << endl;
return NULL;
}
string DefaultHepRep::checkForException() {
return NULL;
}
vector<HepRepInstanceTree*> DefaultHepRep::getInstanceTreeList() {
return instanceTrees;
}
} // cheprep
// Copyright FreeHEP, 2005.
#include "cheprep/DefaultHepRep.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
*/
namespace cheprep {
DefaultHepRep::DefaultHepRep() {
}
DefaultHepRep::~DefaultHepRep() {
for (vector<HepRepTypeTree*>::iterator i1 = typeTrees.begin(); i1 != typeTrees.end(); i1++) {
delete (*i1);
}
for (vector<HepRepInstanceTree*>::iterator i2 = instanceTrees.begin(); i2 != instanceTrees.end(); i2++) {
delete (*i2);
}
}
HepRep* DefaultHepRep::copy(HepRepSelectFilter*) {
cerr << "DefaultHepRep::copy(HepRepSelectFilter*) not implemented." << endl;
return NULL;
}
vector<string> DefaultHepRep::getLayerOrder() {
return layers;
}
void DefaultHepRep::addLayer(string layer) {
layers.push_back(layer);
}
void DefaultHepRep::addTypeTree(HepRepTypeTree* typeTree) {
// FIXME check if already exist
typeTrees.push_back(typeTree);
}
void DefaultHepRep::removeTypeTree(HepRepTypeTree*) {
cerr << "DefaultHepRep::removeTypeTree(HepRepTypeTree*) not implemented." << endl;
}
HepRepTypeTree* DefaultHepRep::getTypeTree(string, string) {
cerr << "DefaultHepRep::getTypeTree(string, string) not implemented." << endl;
return NULL;
}
vector<HepRepTypeTree*> DefaultHepRep::getTypeTreeList() {
return typeTrees;
}
void DefaultHepRep::addInstanceTree(HepRepInstanceTree* instanceTree) {
// FIXME check if already exist
instanceTrees.push_back(instanceTree);
}
void DefaultHepRep::overlayInstanceTree(HepRepInstanceTree *) {
cerr << "DefaultHepRep::overlayInstanceTree(HepRepInstanceTree * instanceTree) not implemented." << endl;
}
void DefaultHepRep::removeInstanceTree(HepRepInstanceTree*) {
cerr << "DefaultHepRep::removeInstanceTree(HepRepInstanceTree*) not implemented." << endl;
}
HepRepInstanceTree* DefaultHepRep::getInstanceTreeTop(string, string) {
cerr << "DefaultHepRep::getInstanceTreeTop(string, string) not implemented." << endl;
return NULL;
}
HepRepInstanceTree* DefaultHepRep::getInstances(string, string,
vector<string>) {
cerr << "DefaultHepRep::getInstances(string, string, vector<string>) not implemented." << endl;
return NULL;
}
HepRepInstanceTree* DefaultHepRep::getInstancesAfterAction(
string,
string,
vector<string>,
vector<HepRepAction*>,
bool,
bool,
bool,
vector<string>) {
cerr << "DefaultHepRep::getInstancesAfterAction(string, string, vector<string>, vector<HepRepAction*>, bool, bool, bool, vector<string>) not implemented." << endl;
return NULL;
}
string DefaultHepRep::checkForException() {
return NULL;
}
vector<HepRepInstanceTree*> DefaultHepRep::getInstanceTreeList() {
return instanceTrees;
}
} // cheprep
@@ -1,36 +1,35 @@
// Copyright FreeHEP, 2005.
#include <iostream>
#include "cheprep/DefaultHepRepAction.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
* @version $Id: DefaultHepRepAction.cc 66373 2012-12-18 09:41:34Z gcosmo $
*/
namespace cheprep {
DefaultHepRepAction::DefaultHepRepAction(string aName, string anExpression)
: name(aName), expression(anExpression) {
}
DefaultHepRepAction::~DefaultHepRepAction() {
}
string DefaultHepRepAction::getName() {
return name;
}
string DefaultHepRepAction::getExpression() {
return expression;
}
HepRepAction* DefaultHepRepAction::copy() {
return new DefaultHepRepAction(name, expression);
}
} // cheprep
// Copyright FreeHEP, 2005.
#include <iostream>
#include "cheprep/DefaultHepRepAction.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
*/
namespace cheprep {
DefaultHepRepAction::DefaultHepRepAction(string aName, string anExpression)
: name(aName), expression(anExpression) {
}
DefaultHepRepAction::~DefaultHepRepAction() {
}
string DefaultHepRepAction::getName() {
return name;
}
string DefaultHepRepAction::getExpression() {
return expression;
}
HepRepAction* DefaultHepRepAction::copy() {
return new DefaultHepRepAction(name, expression);
}
} // cheprep
@@ -1,52 +1,51 @@
// Copyright FreeHEP, 2005.
#include <iostream>
#include <cstring>
#include <cctype>
#include <algorithm>
#include "cheprep/DefaultHepRepAttDef.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
* @version $Id: DefaultHepRepAttDef.cc 66373 2012-12-18 09:41:34Z gcosmo $
*/
namespace cheprep {
DefaultHepRepAttDef::DefaultHepRepAttDef(string aName, string aDesc, string aCategory, string anExtra)
: name(aName), desc(aDesc), category(aCategory), extra(anExtra) {
}
DefaultHepRepAttDef::~DefaultHepRepAttDef() {
}
HepRepAttDef* DefaultHepRepAttDef::copy() {
return new DefaultHepRepAttDef(name, desc, category, extra);
}
string DefaultHepRepAttDef::getName() {
return name;
}
string DefaultHepRepAttDef::getLowerCaseName() {
string s = name;
transform(s.begin(), s.end(), s.begin(), (int(*)(int)) tolower);
return s;
}
string DefaultHepRepAttDef::getDescription() {
return desc;
}
string DefaultHepRepAttDef::getCategory() {
return category;
}
string DefaultHepRepAttDef::getExtra() {
return extra;
}
} // cheprep
// Copyright FreeHEP, 2005.
#include <iostream>
#include <cstring>
#include <cctype>
#include <algorithm>
#include "cheprep/DefaultHepRepAttDef.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
*/
namespace cheprep {
DefaultHepRepAttDef::DefaultHepRepAttDef(string aName, string aDesc, string aCategory, string anExtra)
: name(aName), desc(aDesc), category(aCategory), extra(anExtra) {
}
DefaultHepRepAttDef::~DefaultHepRepAttDef() {
}
HepRepAttDef* DefaultHepRepAttDef::copy() {
return new DefaultHepRepAttDef(name, desc, category, extra);
}
string DefaultHepRepAttDef::getName() {
return name;
}
string DefaultHepRepAttDef::getLowerCaseName() {
string s = name;
transform(s.begin(), s.end(), s.begin(), (int(*)(int)) tolower);
return s;
}
string DefaultHepRepAttDef::getDescription() {
return desc;
}
string DefaultHepRepAttDef::getCategory() {
return category;
}
string DefaultHepRepAttDef::getExtra() {
return extra;
}
} // cheprep
@@ -1,272 +1,271 @@
// Copyright FreeHEP, 2005.
#include "cheprep/config.h"
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include "HEPREP/HepRepConstants.h"
#include "cheprep/DefaultHepRepAttValue.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
* @version $Id: DefaultHepRepAttValue.cc 68043 2013-03-13 14:27:49Z gcosmo $
*/
namespace cheprep {
std::string DefaultHepRepAttValue::labelStrings[LABELSTRINGS_LEN];
DefaultHepRepAttValue::DefaultHepRepAttValue(string aName, string aValue, int aShowLabel)
: name(aName)
, type(HepRepConstants::TYPE_STRING)
, stringValue(aValue)
, longValue(0)
, doubleValue(0.)
, booleanValue(false)
, showLabelValue(aShowLabel)
{
init();
}
DefaultHepRepAttValue::DefaultHepRepAttValue(string aName, int64 aValue, int aShowLabel)
: name(aName)
, type(HepRepConstants::TYPE_LONG)
, longValue(aValue)
, doubleValue(0.)
, booleanValue(false)
, showLabelValue(aShowLabel)
{
init();
}
DefaultHepRepAttValue::DefaultHepRepAttValue(string aName, int aValue, int aShowLabel)
: name(aName)
, type(HepRepConstants::TYPE_INT)
, longValue(aValue)
, doubleValue(0.)
, booleanValue(false)
, showLabelValue(aShowLabel)
{
init();
}
DefaultHepRepAttValue::DefaultHepRepAttValue(string aName, double aValue, int aShowLabel)
: name(aName)
, type(HepRepConstants::TYPE_DOUBLE)
, longValue(0)
, doubleValue(aValue)
, booleanValue(false)
, showLabelValue(aShowLabel)
{
init();
}
DefaultHepRepAttValue::DefaultHepRepAttValue(string aName, bool aValue, int aShowLabel)
: name(aName)
, type(HepRepConstants::TYPE_BOOLEAN)
, longValue(0)
, doubleValue(0.)
, booleanValue(aValue)
, showLabelValue(aShowLabel)
{
init();
}
DefaultHepRepAttValue::DefaultHepRepAttValue(string aName, vector<double> aValue, int aShowLabel)
: name(aName)
, type(HepRepConstants::TYPE_COLOR)
, longValue(0)
, doubleValue(0.)
, booleanValue(false)
, colorValue(aValue)
, showLabelValue(aShowLabel)
{
init();
}
DefaultHepRepAttValue::~DefaultHepRepAttValue() {
}
void DefaultHepRepAttValue::init() {
labelStrings[0] = "NAME";
labelStrings[1] = "DESC";
labelStrings[2] = "VALUE";
labelStrings[3] = "EXTRA";
}
HepRepAttValue* DefaultHepRepAttValue::copy() {
// Coverity issues warnings here. It looks to me (JA) that "return" is
// missing on severeal lines.
switch(type) {
// case HepRepConstants::TYPE_COLOR: new DefaultHepRepAttValue(name, colorValue, showLabelValue);
// case HepRepConstants::TYPE_STRING: new DefaultHepRepAttValue(name, stringValue, showLabelValue);
// case HepRepConstants::TYPE_LONG: new DefaultHepRepAttValue(name, longValue, showLabelValue);
// case HepRepConstants::TYPE_INT: new DefaultHepRepAttValue(name, (int)longValue, showLabelValue);
// case HepRepConstants::TYPE_DOUBLE: new DefaultHepRepAttValue(name, doubleValue, showLabelValue);
// case HepRepConstants::TYPE_BOOLEAN: new DefaultHepRepAttValue(name, booleanValue, showLabelValue);
case HepRepConstants::TYPE_COLOR: return new DefaultHepRepAttValue(name, colorValue, showLabelValue);
case HepRepConstants::TYPE_STRING: return new DefaultHepRepAttValue(name, stringValue, showLabelValue);
case HepRepConstants::TYPE_LONG: return new DefaultHepRepAttValue(name, longValue, showLabelValue);
case HepRepConstants::TYPE_INT: return new DefaultHepRepAttValue(name, (int)longValue, showLabelValue);
case HepRepConstants::TYPE_DOUBLE: return new DefaultHepRepAttValue(name, doubleValue, showLabelValue);
case HepRepConstants::TYPE_BOOLEAN: return new DefaultHepRepAttValue(name, booleanValue, showLabelValue);
default: return new DefaultHepRepAttValue(name, "Unknown type stored in HepRepAttDef", showLabelValue);
}
}
string DefaultHepRepAttValue::getName() {
return name;
}
string DefaultHepRepAttValue::getLowerCaseName() {
string s = name;
transform(s.begin(), s.end(), s.begin(), (int(*)(int)) tolower);
return s;
}
int DefaultHepRepAttValue::getType() {
return type;
}
string DefaultHepRepAttValue::getTypeName() {
switch(type) {
case HepRepConstants::TYPE_COLOR: return("Color");
case HepRepConstants::TYPE_STRING: return("String");
case HepRepConstants::TYPE_LONG: return("long");
case HepRepConstants::TYPE_INT: return("int");
case HepRepConstants::TYPE_DOUBLE: return("double");
case HepRepConstants::TYPE_BOOLEAN: return("boolean");
default: return "Unknown type stored in HepRepAttDef";
}
}
int DefaultHepRepAttValue::showLabel() {
return showLabelValue;
}
string DefaultHepRepAttValue::getString() {
if (type != HepRepConstants::TYPE_STRING) cerr << "Trying to access AttValue '" << getName() << "' as 'string'" << endl;
return stringValue;
}
string DefaultHepRepAttValue::getLowerCaseString() {
if (type != HepRepConstants::TYPE_STRING) cerr << "Trying to access AttValue '" << getName() << "' as 'string'" << endl;
string s = stringValue;
transform(s.begin(), s.end(), s.begin(), (int(*)(int)) tolower);
return s;
}
int64 DefaultHepRepAttValue::getLong() {
if (type != HepRepConstants::TYPE_LONG) cerr << "Trying to access AttValue '" << getName() << "' as 'long'" << endl;
return longValue;
}
int DefaultHepRepAttValue::getInteger() {
if (type != HepRepConstants::TYPE_INT) cerr << "Trying to access AttValue '" << getName() << "' as 'int'" << endl;
return (int64)longValue;
}
double DefaultHepRepAttValue::getDouble() {
if (type != HepRepConstants::TYPE_DOUBLE) cerr << "Trying to access AttValue '" << getName() << "' as 'double'" << endl;
return doubleValue;
}
bool DefaultHepRepAttValue::getBoolean() {
if (type != HepRepConstants::TYPE_BOOLEAN) cerr << "Trying to access AttValue '" << getName() << "' as 'boolean'" << endl;
return booleanValue;
}
vector<double> DefaultHepRepAttValue::getColor() {
if (type != HepRepConstants::TYPE_COLOR) cerr << "Trying to access AttValue '" << getName() << "' as 'color'" << endl;
return colorValue;
}
string DefaultHepRepAttValue::getAsString() {
switch(type) {
case HepRepConstants::TYPE_COLOR: return getAsString(getColor());
case HepRepConstants::TYPE_STRING: return getString();
case HepRepConstants::TYPE_LONG: return getAsString(getLong());
case HepRepConstants::TYPE_INT: return getAsString(getInteger());
case HepRepConstants::TYPE_DOUBLE: return getAsString(getDouble());
case HepRepConstants::TYPE_BOOLEAN: return getAsString(getBoolean());
default: return "Unknown typecode";
}
}
string DefaultHepRepAttValue::getAsString(vector<double> c) {
char buffer[40];
sprintf(buffer, "%4.2f, %4.2f, %4.2f, %4.2f",
c[0],
c[1],
c[2],
(c.size() > 3) ? c[3] : 1.0);
return buffer;
}
string DefaultHepRepAttValue::getAsString(int i) {
char buffer[40];
sprintf(buffer, "%d", i);
return buffer;
}
string DefaultHepRepAttValue::getAsString(int64 i) {
char buffer[40];
sprintf(buffer, CHEPREP_INT64_FORMAT, i);
return buffer;
}
// NOTE: keep at %g rather than %lg for backward compatibility
string DefaultHepRepAttValue::getAsString(double d) {
char buffer[40];
sprintf(buffer, "%g", d);
return buffer;
}
string DefaultHepRepAttValue::getAsString(bool b) {
return b ? "true" : "false";
}
string DefaultHepRepAttValue::toShowLabel() {
return toShowLabel(showLabel());
}
string DefaultHepRepAttValue::toShowLabel(int showLabel) {
string label = "";
bool first = true;
if (showLabel == HepRepConstants::SHOW_NONE) {
label = "NONE";
} else {
for (int i=0; i<16; i++) {
if (((showLabel >> i) & 0x0001) == 0x0001) {
if (first) {
first = false;
} else {
label.append(", ");
}
if (i < LABELSTRINGS_LEN) {
label.append(labelStrings[i]);
} else {
char hex[20];
sprintf(hex, "%0x", 1 << i);
label.append(hex);
}
}
}
}
return label;
}
} // cheprep
// Copyright FreeHEP, 2005.
#include "cheprep/config.h"
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include "HEPREP/HepRepConstants.h"
#include "cheprep/DefaultHepRepAttValue.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
*/
namespace cheprep {
std::string DefaultHepRepAttValue::labelStrings[LABELSTRINGS_LEN];
DefaultHepRepAttValue::DefaultHepRepAttValue(string aName, string aValue, int aShowLabel)
: name(aName)
, type(HepRepConstants::TYPE_STRING)
, stringValue(aValue)
, longValue(0)
, doubleValue(0.)
, booleanValue(false)
, showLabelValue(aShowLabel)
{
init();
}
DefaultHepRepAttValue::DefaultHepRepAttValue(string aName, int64 aValue, int aShowLabel)
: name(aName)
, type(HepRepConstants::TYPE_LONG)
, longValue(aValue)
, doubleValue(0.)
, booleanValue(false)
, showLabelValue(aShowLabel)
{
init();
}
DefaultHepRepAttValue::DefaultHepRepAttValue(string aName, int aValue, int aShowLabel)
: name(aName)
, type(HepRepConstants::TYPE_INT)
, longValue(aValue)
, doubleValue(0.)
, booleanValue(false)
, showLabelValue(aShowLabel)
{
init();
}
DefaultHepRepAttValue::DefaultHepRepAttValue(string aName, double aValue, int aShowLabel)
: name(aName)
, type(HepRepConstants::TYPE_DOUBLE)
, longValue(0)
, doubleValue(aValue)
, booleanValue(false)
, showLabelValue(aShowLabel)
{
init();
}
DefaultHepRepAttValue::DefaultHepRepAttValue(string aName, bool aValue, int aShowLabel)
: name(aName)
, type(HepRepConstants::TYPE_BOOLEAN)
, longValue(0)
, doubleValue(0.)
, booleanValue(aValue)
, showLabelValue(aShowLabel)
{
init();
}
DefaultHepRepAttValue::DefaultHepRepAttValue(string aName, vector<double> aValue, int aShowLabel)
: name(aName)
, type(HepRepConstants::TYPE_COLOR)
, longValue(0)
, doubleValue(0.)
, booleanValue(false)
, colorValue(aValue)
, showLabelValue(aShowLabel)
{
init();
}
DefaultHepRepAttValue::~DefaultHepRepAttValue() {
}
void DefaultHepRepAttValue::init() {
labelStrings[0] = "NAME";
labelStrings[1] = "DESC";
labelStrings[2] = "VALUE";
labelStrings[3] = "EXTRA";
}
HepRepAttValue* DefaultHepRepAttValue::copy() {
// Coverity issues warnings here. It looks to me (JA) that "return" is
// missing on severeal lines.
switch(type) {
// case HepRepConstants::TYPE_COLOR: new DefaultHepRepAttValue(name, colorValue, showLabelValue);
// case HepRepConstants::TYPE_STRING: new DefaultHepRepAttValue(name, stringValue, showLabelValue);
// case HepRepConstants::TYPE_LONG: new DefaultHepRepAttValue(name, longValue, showLabelValue);
// case HepRepConstants::TYPE_INT: new DefaultHepRepAttValue(name, (int)longValue, showLabelValue);
// case HepRepConstants::TYPE_DOUBLE: new DefaultHepRepAttValue(name, doubleValue, showLabelValue);
// case HepRepConstants::TYPE_BOOLEAN: new DefaultHepRepAttValue(name, booleanValue, showLabelValue);
case HepRepConstants::TYPE_COLOR: return new DefaultHepRepAttValue(name, colorValue, showLabelValue);
case HepRepConstants::TYPE_STRING: return new DefaultHepRepAttValue(name, stringValue, showLabelValue);
case HepRepConstants::TYPE_LONG: return new DefaultHepRepAttValue(name, longValue, showLabelValue);
case HepRepConstants::TYPE_INT: return new DefaultHepRepAttValue(name, (int)longValue, showLabelValue);
case HepRepConstants::TYPE_DOUBLE: return new DefaultHepRepAttValue(name, doubleValue, showLabelValue);
case HepRepConstants::TYPE_BOOLEAN: return new DefaultHepRepAttValue(name, booleanValue, showLabelValue);
default: return new DefaultHepRepAttValue(name, "Unknown type stored in HepRepAttDef", showLabelValue);
}
}
string DefaultHepRepAttValue::getName() {
return name;
}
string DefaultHepRepAttValue::getLowerCaseName() {
string s = name;
transform(s.begin(), s.end(), s.begin(), (int(*)(int)) tolower);
return s;
}
int DefaultHepRepAttValue::getType() {
return type;
}
string DefaultHepRepAttValue::getTypeName() {
switch(type) {
case HepRepConstants::TYPE_COLOR: return("Color");
case HepRepConstants::TYPE_STRING: return("String");
case HepRepConstants::TYPE_LONG: return("long");
case HepRepConstants::TYPE_INT: return("int");
case HepRepConstants::TYPE_DOUBLE: return("double");
case HepRepConstants::TYPE_BOOLEAN: return("boolean");
default: return "Unknown type stored in HepRepAttDef";
}
}
int DefaultHepRepAttValue::showLabel() {
return showLabelValue;
}
string DefaultHepRepAttValue::getString() {
if (type != HepRepConstants::TYPE_STRING) cerr << "Trying to access AttValue '" << getName() << "' as 'string'" << endl;
return stringValue;
}
string DefaultHepRepAttValue::getLowerCaseString() {
if (type != HepRepConstants::TYPE_STRING) cerr << "Trying to access AttValue '" << getName() << "' as 'string'" << endl;
string s = stringValue;
transform(s.begin(), s.end(), s.begin(), (int(*)(int)) tolower);
return s;
}
int64 DefaultHepRepAttValue::getLong() {
if (type != HepRepConstants::TYPE_LONG) cerr << "Trying to access AttValue '" << getName() << "' as 'long'" << endl;
return longValue;
}
int DefaultHepRepAttValue::getInteger() {
if (type != HepRepConstants::TYPE_INT) cerr << "Trying to access AttValue '" << getName() << "' as 'int'" << endl;
return (int64)longValue;
}
double DefaultHepRepAttValue::getDouble() {
if (type != HepRepConstants::TYPE_DOUBLE) cerr << "Trying to access AttValue '" << getName() << "' as 'double'" << endl;
return doubleValue;
}
bool DefaultHepRepAttValue::getBoolean() {
if (type != HepRepConstants::TYPE_BOOLEAN) cerr << "Trying to access AttValue '" << getName() << "' as 'boolean'" << endl;
return booleanValue;
}
vector<double> DefaultHepRepAttValue::getColor() {
if (type != HepRepConstants::TYPE_COLOR) cerr << "Trying to access AttValue '" << getName() << "' as 'color'" << endl;
return colorValue;
}
string DefaultHepRepAttValue::getAsString() {
switch(type) {
case HepRepConstants::TYPE_COLOR: return getAsString(getColor());
case HepRepConstants::TYPE_STRING: return getString();
case HepRepConstants::TYPE_LONG: return getAsString(getLong());
case HepRepConstants::TYPE_INT: return getAsString(getInteger());
case HepRepConstants::TYPE_DOUBLE: return getAsString(getDouble());
case HepRepConstants::TYPE_BOOLEAN: return getAsString(getBoolean());
default: return "Unknown typecode";
}
}
string DefaultHepRepAttValue::getAsString(vector<double> c) {
char buffer[40];
sprintf(buffer, "%4.2f, %4.2f, %4.2f, %4.2f",
c[0],
c[1],
c[2],
(c.size() > 3) ? c[3] : 1.0);
return buffer;
}
string DefaultHepRepAttValue::getAsString(int i) {
char buffer[40];
sprintf(buffer, "%d", i);
return buffer;
}
string DefaultHepRepAttValue::getAsString(int64 i) {
char buffer[40];
sprintf(buffer, CHEPREP_INT64_FORMAT, i);
return buffer;
}
// NOTE: keep at %g rather than %lg for backward compatibility
string DefaultHepRepAttValue::getAsString(double d) {
char buffer[40];
sprintf(buffer, "%g", d);
return buffer;
}
string DefaultHepRepAttValue::getAsString(bool b) {
return b ? "true" : "false";
}
string DefaultHepRepAttValue::toShowLabel() {
return toShowLabel(showLabel());
}
string DefaultHepRepAttValue::toShowLabel(int showLabel) {
string label = "";
bool first = true;
if (showLabel == HepRepConstants::SHOW_NONE) {
label = "NONE";
} else {
for (int i=0; i<16; i++) {
if (((showLabel >> i) & 0x0001) == 0x0001) {
if (first) {
first = false;
} else {
label.append(", ");
}
if (i < LABELSTRINGS_LEN) {
label.append(labelStrings[i]);
} else {
char hex[20];
sprintf(hex, "%0x", 1 << i);
label.append(hex);
}
}
}
}
return label;
}
} // cheprep
@@ -1,96 +1,95 @@
// Copyright FreeHEP, 2005.
#include "cheprep/config.h"
#include <iostream>
#include <algorithm>
#include "cheprep/DefaultHepRepAttribute.h"
#include "cheprep/DefaultHepRepAttValue.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
* @version $Id: DefaultHepRepAttribute.cc 66373 2012-12-18 09:41:34Z gcosmo $
*/
namespace cheprep {
DefaultHepRepAttribute::DefaultHepRepAttribute() {
}
DefaultHepRepAttribute::~DefaultHepRepAttribute() {
for (map<string, HepRepAttValue*>::iterator i = attValues.begin(); i != attValues.end(); i++) {
delete (*i).second;
}
}
set<HepRepAttValue*> DefaultHepRepAttribute::getAttValuesFromNode() {
set<HepRepAttValue*> attSet;
for (map<string, HepRepAttValue*>::iterator i = attValues.begin(); i != attValues.end(); i++) {
if ((*i).first != "layer") attSet.insert((*i).second);
}
return attSet;
}
void DefaultHepRepAttribute::addAttValue(HepRepAttValue* hepRepAttValue) {
string lowerCaseName = hepRepAttValue->getLowerCaseName();
if (attValues[lowerCaseName] != NULL) delete attValues[lowerCaseName];
attValues[lowerCaseName] = hepRepAttValue;
}
void DefaultHepRepAttribute::addAttValue(string key, char *value, int showLabel) {
addAttValue(key, (std::string)value, showLabel);
}
void DefaultHepRepAttribute::addAttValue(string key, string value, int showLabel) {
addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
}
void DefaultHepRepAttribute::addAttValue(string key, int64 value, int showLabel) {
addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
}
void DefaultHepRepAttribute::addAttValue(string key, int value, int showLabel) {
addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
}
void DefaultHepRepAttribute::addAttValue(string key, double value, int showLabel) {
addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
}
void DefaultHepRepAttribute::addAttValue(string key, bool value, int showLabel) {
addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
}
void DefaultHepRepAttribute::addAttValue(string key, vector<double> value, int showLabel) {
addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
}
void DefaultHepRepAttribute::addAttValue(string key, double red, double green, double blue, double alpha, int showLabel) {
vector<double> color;
color.push_back(red);
color.push_back(green);
color.push_back(blue);
color.push_back(alpha);
addAttValue(new DefaultHepRepAttValue(key, color, showLabel));
}
HepRepAttValue* DefaultHepRepAttribute::getAttValueFromNode(string name) {
string s = name;
transform(s.begin(), s.end(), s.begin(), (int(*)(int)) tolower);
return (attValues.count(s) > 0) ? attValues[s] : NULL;
}
HepRepAttValue* DefaultHepRepAttribute::removeAttValue(string name) {
string s = name;
transform(s.begin(), s.end(), s.begin(), (int(*)(int)) tolower);
HepRepAttValue* attValue = attValues[s];
attValues.erase(s);
return attValue;
}
} // cheprep
// Copyright FreeHEP, 2005.
#include "cheprep/config.h"
#include <iostream>
#include <algorithm>
#include "cheprep/DefaultHepRepAttribute.h"
#include "cheprep/DefaultHepRepAttValue.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
*/
namespace cheprep {
DefaultHepRepAttribute::DefaultHepRepAttribute() {
}
DefaultHepRepAttribute::~DefaultHepRepAttribute() {
for (map<string, HepRepAttValue*>::iterator i = attValues.begin(); i != attValues.end(); i++) {
delete (*i).second;
}
}
set<HepRepAttValue*> DefaultHepRepAttribute::getAttValuesFromNode() {
set<HepRepAttValue*> attSet;
for (map<string, HepRepAttValue*>::iterator i = attValues.begin(); i != attValues.end(); i++) {
if ((*i).first != "layer") attSet.insert((*i).second);
}
return attSet;
}
void DefaultHepRepAttribute::addAttValue(HepRepAttValue* hepRepAttValue) {
string lowerCaseName = hepRepAttValue->getLowerCaseName();
if (attValues[lowerCaseName] != NULL) delete attValues[lowerCaseName];
attValues[lowerCaseName] = hepRepAttValue;
}
void DefaultHepRepAttribute::addAttValue(string key, char *value, int showLabel) {
addAttValue(key, (std::string)value, showLabel);
}
void DefaultHepRepAttribute::addAttValue(string key, string value, int showLabel) {
addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
}
void DefaultHepRepAttribute::addAttValue(string key, int64 value, int showLabel) {
addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
}
void DefaultHepRepAttribute::addAttValue(string key, int value, int showLabel) {
addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
}
void DefaultHepRepAttribute::addAttValue(string key, double value, int showLabel) {
addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
}
void DefaultHepRepAttribute::addAttValue(string key, bool value, int showLabel) {
addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
}
void DefaultHepRepAttribute::addAttValue(string key, vector<double> value, int showLabel) {
addAttValue(new DefaultHepRepAttValue(key, value, showLabel));
}
void DefaultHepRepAttribute::addAttValue(string key, double red, double green, double blue, double alpha, int showLabel) {
vector<double> color;
color.push_back(red);
color.push_back(green);
color.push_back(blue);
color.push_back(alpha);
addAttValue(new DefaultHepRepAttValue(key, color, showLabel));
}
HepRepAttValue* DefaultHepRepAttribute::getAttValueFromNode(string name) {
string s = name;
transform(s.begin(), s.end(), s.begin(), (int(*)(int)) tolower);
return (attValues.count(s) > 0) ? attValues[s] : NULL;
}
HepRepAttValue* DefaultHepRepAttribute::removeAttValue(string name) {
string s = name;
transform(s.begin(), s.end(), s.begin(), (int(*)(int)) tolower);
HepRepAttValue* attValue = attValues[s];
attValues.erase(s);
return attValue;
}
} // cheprep
@@ -1,53 +1,52 @@
// Copyright FreeHEP, 2005.
#include "cheprep/DefaultHepRepDefinition.h"
#include "cheprep/DefaultHepRepAttDef.h"
#include <iostream>
#include <algorithm>
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
* @version $Id: DefaultHepRepDefinition.cc 66373 2012-12-18 09:41:34Z gcosmo $
*/
namespace cheprep {
DefaultHepRepDefinition::DefaultHepRepDefinition()
: DefaultHepRepAttribute() {
}
DefaultHepRepDefinition::~DefaultHepRepDefinition() {
set<HepRepAttDef *> list = getAttDefsFromNode();
for (set<HepRepAttDef*>::iterator i1 = list.begin(); i1 != list.end(); i1++) {
delete (*i1);
}
}
set<HepRepAttDef *> DefaultHepRepDefinition::getAttDefsFromNode() {
set<HepRepAttDef*> attSet;
for (map<string, HepRepAttDef*>::iterator i = attDefs.begin(); i != attDefs.end(); i++) {
attSet.insert((*i).second);
}
return attSet;
}
void DefaultHepRepDefinition::addAttDef(HepRepAttDef* hepRepAttDef) {
string lowerCaseName = hepRepAttDef->getLowerCaseName();
if (attDefs[lowerCaseName] != NULL) delete attDefs[lowerCaseName];
attDefs[lowerCaseName] = hepRepAttDef;
}
void DefaultHepRepDefinition::addAttDef(string name, string desc, string type, string extra) {
addAttDef(new DefaultHepRepAttDef(name, desc, type, extra));
}
HepRepAttDef* DefaultHepRepDefinition::getAttDefFromNode(string name) {
string s = name;
transform(s.begin(), s.end(), s.begin(), (int(*)(int)) tolower);
return (attDefs.count(s) > 0) ? attDefs[s] : NULL;
}
} // cheprep
// Copyright FreeHEP, 2005.
#include "cheprep/DefaultHepRepDefinition.h"
#include "cheprep/DefaultHepRepAttDef.h"
#include <iostream>
#include <algorithm>
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
*/
namespace cheprep {
DefaultHepRepDefinition::DefaultHepRepDefinition()
: DefaultHepRepAttribute() {
}
DefaultHepRepDefinition::~DefaultHepRepDefinition() {
set<HepRepAttDef *> list = getAttDefsFromNode();
for (set<HepRepAttDef*>::iterator i1 = list.begin(); i1 != list.end(); i1++) {
delete (*i1);
}
}
set<HepRepAttDef *> DefaultHepRepDefinition::getAttDefsFromNode() {
set<HepRepAttDef*> attSet;
for (map<string, HepRepAttDef*>::iterator i = attDefs.begin(); i != attDefs.end(); i++) {
attSet.insert((*i).second);
}
return attSet;
}
void DefaultHepRepDefinition::addAttDef(HepRepAttDef* hepRepAttDef) {
string lowerCaseName = hepRepAttDef->getLowerCaseName();
if (attDefs[lowerCaseName] != NULL) delete attDefs[lowerCaseName];
attDefs[lowerCaseName] = hepRepAttDef;
}
void DefaultHepRepDefinition::addAttDef(string name, string desc, string type, string extra) {
addAttDef(new DefaultHepRepAttDef(name, desc, type, extra));
}
HepRepAttDef* DefaultHepRepDefinition::getAttDefFromNode(string name) {
string s = name;
transform(s.begin(), s.end(), s.begin(), (int(*)(int)) tolower);
return (attDefs.count(s) > 0) ? attDefs[s] : NULL;
}
} // cheprep
@@ -1,90 +1,89 @@
// Copyright FreeHEP, 2005.
#include <iostream>
#include <fstream>
#include "cheprep/DefaultHepRepFactory.h"
#include "cheprep/DefaultHepRepPoint.h"
#include "cheprep/DefaultHepRepInstance.h"
#include "cheprep/DefaultHepRepInstanceTree.h"
#include "cheprep/DefaultHepRepType.h"
#include "cheprep/DefaultHepRepTypeTree.h"
#include "cheprep/DefaultHepRep.h"
#include "cheprep/DefaultHepRepAction.h"
#include "cheprep/DefaultHepRepTreeID.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
* @version $Id: DefaultHepRepFactory.cc 66373 2012-12-18 09:41:34Z gcosmo $
*/
namespace cheprep {
DefaultHepRepFactory::DefaultHepRepFactory() {
}
DefaultHepRepFactory::~DefaultHepRepFactory() {
}
HepRepReader* DefaultHepRepFactory::createHepRepReader (istream*) {
cerr << "DefaultHepRepFactory::createHepRepReader not implemented" << endl;
return NULL;
}
HepRepReader* DefaultHepRepFactory::createHepRepReader (std::string) {
cerr << "DefaultHepRepFactory::createHepRepReader not implemented" << endl;
return NULL;
}
HepRepWriter* DefaultHepRepFactory::createHepRepWriter(ostream*, bool, bool) {
cerr << "DefaultHepRepFactory::createHepRepWriter not implemented" << endl;
return NULL;
}
HepRepPoint* DefaultHepRepFactory::createHepRepPoint (HepRepInstance* instance,
double x, double y, double z) {
return new DefaultHepRepPoint(instance, x, y, z);
}
HepRepInstance* DefaultHepRepFactory::createHepRepInstance (HepRepInstance* parent, HepRepType* type) {
return new DefaultHepRepInstance(parent, type);
}
HepRepInstance* DefaultHepRepFactory::createHepRepInstance (HepRepInstanceTree* parent, HepRepType* type) {
return new DefaultHepRepInstance(parent, type);
}
HepRepTreeID* DefaultHepRepFactory::createHepRepTreeID (string name, string version, string qualifier) {
return new DefaultHepRepTreeID(name, version, qualifier);
}
HepRepAction* DefaultHepRepFactory::createHepRepAction (string name, string expression) {
return new DefaultHepRepAction(name, expression);
}
HepRepInstanceTree* DefaultHepRepFactory::createHepRepInstanceTree (string name, string version,
HepRepTreeID* typeTreeID) {
return new DefaultHepRepInstanceTree(name, version, typeTreeID);
}
HepRepType* DefaultHepRepFactory::createHepRepType (HepRepType* parent, string name) {
return new DefaultHepRepType(parent, name);
}
HepRepType* DefaultHepRepFactory::createHepRepType (HepRepTypeTree* parent, string name) {
return new DefaultHepRepType(parent, name);
}
HepRepTypeTree* DefaultHepRepFactory::createHepRepTypeTree (HepRepTreeID* treeID) {
return new DefaultHepRepTypeTree(treeID);
}
HepRep* DefaultHepRepFactory::createHepRep () {
return new DefaultHepRep();
}
} // cheprep
// Copyright FreeHEP, 2005.
#include <iostream>
#include <fstream>
#include "cheprep/DefaultHepRepFactory.h"
#include "cheprep/DefaultHepRepPoint.h"
#include "cheprep/DefaultHepRepInstance.h"
#include "cheprep/DefaultHepRepInstanceTree.h"
#include "cheprep/DefaultHepRepType.h"
#include "cheprep/DefaultHepRepTypeTree.h"
#include "cheprep/DefaultHepRep.h"
#include "cheprep/DefaultHepRepAction.h"
#include "cheprep/DefaultHepRepTreeID.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
*/
namespace cheprep {
DefaultHepRepFactory::DefaultHepRepFactory() {
}
DefaultHepRepFactory::~DefaultHepRepFactory() {
}
HepRepReader* DefaultHepRepFactory::createHepRepReader (istream*) {
cerr << "DefaultHepRepFactory::createHepRepReader not implemented" << endl;
return NULL;
}
HepRepReader* DefaultHepRepFactory::createHepRepReader (std::string) {
cerr << "DefaultHepRepFactory::createHepRepReader not implemented" << endl;
return NULL;
}
HepRepWriter* DefaultHepRepFactory::createHepRepWriter(ostream*, bool, bool) {
cerr << "DefaultHepRepFactory::createHepRepWriter not implemented" << endl;
return NULL;
}
HepRepPoint* DefaultHepRepFactory::createHepRepPoint (HepRepInstance* instance,
double x, double y, double z) {
return new DefaultHepRepPoint(instance, x, y, z);
}
HepRepInstance* DefaultHepRepFactory::createHepRepInstance (HepRepInstance* parent, HepRepType* type) {
return new DefaultHepRepInstance(parent, type);
}
HepRepInstance* DefaultHepRepFactory::createHepRepInstance (HepRepInstanceTree* parent, HepRepType* type) {
return new DefaultHepRepInstance(parent, type);
}
HepRepTreeID* DefaultHepRepFactory::createHepRepTreeID (string name, string version, string qualifier) {
return new DefaultHepRepTreeID(name, version, qualifier);
}
HepRepAction* DefaultHepRepFactory::createHepRepAction (string name, string expression) {
return new DefaultHepRepAction(name, expression);
}
HepRepInstanceTree* DefaultHepRepFactory::createHepRepInstanceTree (string name, string version,
HepRepTreeID* typeTreeID) {
return new DefaultHepRepInstanceTree(name, version, typeTreeID);
}
HepRepType* DefaultHepRepFactory::createHepRepType (HepRepType* parent, string name) {
return new DefaultHepRepType(parent, name);
}
HepRepType* DefaultHepRepFactory::createHepRepType (HepRepTypeTree* parent, string name) {
return new DefaultHepRepType(parent, name);
}
HepRepTypeTree* DefaultHepRepFactory::createHepRepTypeTree (HepRepTreeID* treeID) {
return new DefaultHepRepTypeTree(treeID);
}
HepRep* DefaultHepRepFactory::createHepRep () {
return new DefaultHepRep();
}
} // cheprep
@@ -1,88 +1,87 @@
// Copyright FreeHEP, 2005.
#include <iostream>
#include "cheprep/DefaultHepRepInstance.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
* @version $Id: DefaultHepRepInstance.cc 66373 2012-12-18 09:41:34Z gcosmo $
*/
namespace cheprep {
DefaultHepRepInstance::DefaultHepRepInstance(HepRepInstance* instance, HepRepType* heprepType)
: DefaultHepRepAttribute(), parent(instance), type(heprepType) {
if (type == NULL) cerr << "HepRepInstance cannot be created without a HepRepType." << endl;
parent->addInstance(this);
}
DefaultHepRepInstance::DefaultHepRepInstance(HepRepInstanceTree* instanceTree, HepRepType* heprepType)
: DefaultHepRepAttribute(), parent(NULL), type(heprepType) {
if (type == NULL) cerr << "HepRepInstance cannot be created without a HepRepType." << endl;
instanceTree->addInstance(this);
}
DefaultHepRepInstance::~DefaultHepRepInstance() {
parent = NULL;
type = NULL;
for (vector<HepRepInstance*>::iterator i1 = instances.begin(); i1 != instances.end(); i1++) {
delete (*i1);
}
for (vector<HepRepPoint*>::iterator i2 = points.begin(); i2 != points.end(); i2++) {
delete (*i2);
}
}
void DefaultHepRepInstance::overlay(HepRepInstance *) {
cerr << "DefaultHepRepInstance::overlay(HepRepInstance * instance) not implemented." << endl;
}
HepRepInstance* DefaultHepRepInstance::copy(HepRepTypeTree*, HepRepInstance*, HepRepSelectFilter*) {
cerr << "DefaultHepRepInstance::copy(HepRepTypeTree*, HepRepInstance*, HepRepSelectFilter*) not implemented." << endl;
return NULL;
}
HepRepInstance* DefaultHepRepInstance::copy(HepRepTypeTree*, HepRepInstanceTree*, HepRepSelectFilter*) {
cerr << "DefaultHepRepInstance::copy(HepRepTypeTree*, HepRepInstanceTree*, HepRepSelectFilter*) not implemented." << endl;
return NULL;
}
HepRepType* DefaultHepRepInstance::getType() {
return type;
}
void DefaultHepRepInstance::addPoint(HepRepPoint* point) {
points.push_back(point);
}
vector<HepRepPoint*> DefaultHepRepInstance::getPoints() {
return points;
}
HepRepInstance* DefaultHepRepInstance::getSuperInstance() {
return parent;
}
void DefaultHepRepInstance::addInstance(HepRepInstance* instance) {
instances.push_back(instance);
}
void DefaultHepRepInstance::removeInstance(HepRepInstance*) {
cerr << "DefaultHepRepInstance::removeInstance(HepRepInstance*) not implemented." << endl;
}
vector<HepRepInstance*> DefaultHepRepInstance::getInstances() {
return instances;
}
HepRepAttValue* DefaultHepRepInstance::getAttValue(string name) {
HepRepAttValue* value = getAttValueFromNode(name);
return (value != NULL) ? value : type->getAttValue(name);
}
} // cheprep
// Copyright FreeHEP, 2005.
#include <iostream>
#include "cheprep/DefaultHepRepInstance.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
*/
namespace cheprep {
DefaultHepRepInstance::DefaultHepRepInstance(HepRepInstance* instance, HepRepType* heprepType)
: DefaultHepRepAttribute(), parent(instance), type(heprepType) {
if (type == NULL) cerr << "HepRepInstance cannot be created without a HepRepType." << endl;
parent->addInstance(this);
}
DefaultHepRepInstance::DefaultHepRepInstance(HepRepInstanceTree* instanceTree, HepRepType* heprepType)
: DefaultHepRepAttribute(), parent(NULL), type(heprepType) {
if (type == NULL) cerr << "HepRepInstance cannot be created without a HepRepType." << endl;
instanceTree->addInstance(this);
}
DefaultHepRepInstance::~DefaultHepRepInstance() {
parent = NULL;
type = NULL;
for (vector<HepRepInstance*>::iterator i1 = instances.begin(); i1 != instances.end(); i1++) {
delete (*i1);
}
for (vector<HepRepPoint*>::iterator i2 = points.begin(); i2 != points.end(); i2++) {
delete (*i2);
}
}
void DefaultHepRepInstance::overlay(HepRepInstance *) {
cerr << "DefaultHepRepInstance::overlay(HepRepInstance * instance) not implemented." << endl;
}
HepRepInstance* DefaultHepRepInstance::copy(HepRepTypeTree*, HepRepInstance*, HepRepSelectFilter*) {
cerr << "DefaultHepRepInstance::copy(HepRepTypeTree*, HepRepInstance*, HepRepSelectFilter*) not implemented." << endl;
return NULL;
}
HepRepInstance* DefaultHepRepInstance::copy(HepRepTypeTree*, HepRepInstanceTree*, HepRepSelectFilter*) {
cerr << "DefaultHepRepInstance::copy(HepRepTypeTree*, HepRepInstanceTree*, HepRepSelectFilter*) not implemented." << endl;
return NULL;
}
HepRepType* DefaultHepRepInstance::getType() {
return type;
}
void DefaultHepRepInstance::addPoint(HepRepPoint* point) {
points.push_back(point);
}
vector<HepRepPoint*> DefaultHepRepInstance::getPoints() {
return points;
}
HepRepInstance* DefaultHepRepInstance::getSuperInstance() {
return parent;
}
void DefaultHepRepInstance::addInstance(HepRepInstance* instance) {
instances.push_back(instance);
}
void DefaultHepRepInstance::removeInstance(HepRepInstance*) {
cerr << "DefaultHepRepInstance::removeInstance(HepRepInstance*) not implemented." << endl;
}
vector<HepRepInstance*> DefaultHepRepInstance::getInstances() {
return instances;
}
HepRepAttValue* DefaultHepRepInstance::getAttValue(string name) {
HepRepAttValue* value = getAttValueFromNode(name);
return (value != NULL) ? value : type->getAttValue(name);
}
} // cheprep
@@ -1,59 +1,58 @@
// Copyright FreeHEP, 2005.
#include "cheprep/DefaultHepRepInstanceTree.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
* @version $Id: DefaultHepRepInstanceTree.cc 66373 2012-12-18 09:41:34Z gcosmo $
*/
namespace cheprep {
DefaultHepRepInstanceTree::DefaultHepRepInstanceTree(string aName, string aVersion, HepRepTreeID* aTypeTree)
: DefaultHepRepTreeID(aName, aVersion), typeTree(aTypeTree) {
}
DefaultHepRepInstanceTree::~DefaultHepRepInstanceTree() {
for (vector<HepRepInstance*>::iterator i1 = instances.begin(); i1 != instances.end(); i1++) {
delete (*i1);
}
instances.clear();
}
void DefaultHepRepInstanceTree::overlay(HepRepInstanceTree *) {
cerr << "DefaultHepRepInstanceTree::overlay(HepRepInstanceTree * instanceTree) not implemented." << endl;
}
HepRepInstanceTree* DefaultHepRepInstanceTree::copy(HepRepTypeTree*, HepRepSelectFilter*) {
cerr << "DefaultHepRepInstanceTree::copy(HepRepTypeTree*, HepRepSelectFilter*) not implemented." << endl;
return NULL;
}
void DefaultHepRepInstanceTree::addInstance(HepRepInstance* instance) {
instances.push_back(instance);
}
void DefaultHepRepInstanceTree::removeInstance(HepRepInstance*) {
cerr << "DefaultHepRepInstanceTree::removeInstance(HepRepInstance*) not implemented." << endl;
}
vector<HepRepInstance*> DefaultHepRepInstanceTree::getInstances() {
return instances;
}
void DefaultHepRepInstanceTree::addInstanceTree(HepRepTreeID* treeID) {
instanceTrees.push_back(treeID);
}
HepRepTreeID* DefaultHepRepInstanceTree::getTypeTree() {
return typeTree;
}
vector<HepRepTreeID*> DefaultHepRepInstanceTree::getInstanceTreeList() {
return instanceTrees;
}
} // cheprep
// Copyright FreeHEP, 2005.
#include "cheprep/DefaultHepRepInstanceTree.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
*/
namespace cheprep {
DefaultHepRepInstanceTree::DefaultHepRepInstanceTree(string aName, string aVersion, HepRepTreeID* aTypeTree)
: DefaultHepRepTreeID(aName, aVersion), typeTree(aTypeTree) {
}
DefaultHepRepInstanceTree::~DefaultHepRepInstanceTree() {
for (vector<HepRepInstance*>::iterator i1 = instances.begin(); i1 != instances.end(); i1++) {
delete (*i1);
}
instances.clear();
}
void DefaultHepRepInstanceTree::overlay(HepRepInstanceTree *) {
cerr << "DefaultHepRepInstanceTree::overlay(HepRepInstanceTree * instanceTree) not implemented." << endl;
}
HepRepInstanceTree* DefaultHepRepInstanceTree::copy(HepRepTypeTree*, HepRepSelectFilter*) {
cerr << "DefaultHepRepInstanceTree::copy(HepRepTypeTree*, HepRepSelectFilter*) not implemented." << endl;
return NULL;
}
void DefaultHepRepInstanceTree::addInstance(HepRepInstance* instance) {
instances.push_back(instance);
}
void DefaultHepRepInstanceTree::removeInstance(HepRepInstance*) {
cerr << "DefaultHepRepInstanceTree::removeInstance(HepRepInstance*) not implemented." << endl;
}
vector<HepRepInstance*> DefaultHepRepInstanceTree::getInstances() {
return instances;
}
void DefaultHepRepInstanceTree::addInstanceTree(HepRepTreeID* treeID) {
instanceTrees.push_back(treeID);
}
HepRepTreeID* DefaultHepRepInstanceTree::getTypeTree() {
return typeTree;
}
vector<HepRepTreeID*> DefaultHepRepInstanceTree::getInstanceTreeList() {
return instanceTrees;
}
} // cheprep
@@ -1,124 +1,123 @@
// Copyright FreeHEP, 2005.
#include <string>
#include <iostream>
#include <cmath>
#include "cheprep/DefaultHepRepPoint.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
* @version $Id: DefaultHepRepPoint.cc 66373 2012-12-18 09:41:34Z gcosmo $
*/
namespace cheprep {
DefaultHepRepPoint::DefaultHepRepPoint(HepRepInstance* inst, double xx, double yy, double zz)
: DefaultHepRepAttribute(), instance(inst), x(xx), y(yy), z(zz) {
if (instance == NULL) {
cerr << "HepRepPoints cannot be created without a HepRepInstance." << endl;
} else {
instance->addPoint(this);
}
}
DefaultHepRepPoint::~DefaultHepRepPoint() {
}
HepRepInstance* DefaultHepRepPoint::getInstance() {
return instance;
}
HepRepAttValue* DefaultHepRepPoint::getAttValue(string lowerCaseName) {
HepRepAttValue* value = getAttValueFromNode(lowerCaseName);
return (value != NULL) ? value : instance->getAttValue(lowerCaseName);
}
HepRepPoint* DefaultHepRepPoint::copy(HepRepInstance* inst) {
return new DefaultHepRepPoint(inst, x, y, z);
}
double DefaultHepRepPoint::getX() {
return x;
}
double DefaultHepRepPoint::getY() {
return y;
}
double DefaultHepRepPoint::getZ() {
return z;
}
vector<double>* DefaultHepRepPoint::getXYZ(vector<double>* xyz) {
(*xyz)[0] = x;
(*xyz)[1] = y;
(*xyz)[2] = z;
return xyz;
}
double DefaultHepRepPoint::getRho() {
return sqrt(x*x + y*y);
}
double DefaultHepRepPoint::getPhi() {
return atan2(y, x);
}
double DefaultHepRepPoint::getTheta() {
return atan2(getRho(), z);
}
double DefaultHepRepPoint::getR() {
double r = getRho();
return sqrt(r*r + z*z);
}
double DefaultHepRepPoint::getEta() {
double ct = cos(getTheta());
return -0.5*log((1.-ct)/(1.+ct));
}
double DefaultHepRepPoint::getX(double xVertex, double, double) {
return x - xVertex;
}
double DefaultHepRepPoint::getY(double, double yVertex, double) {
return y - yVertex;
}
double DefaultHepRepPoint::getZ(double, double, double zVertex) {
return z - zVertex;
}
double DefaultHepRepPoint::getRho(double xVertex, double yVertex, double zVertex) {
double dx = getX(xVertex, yVertex, zVertex);
double dy = getY(xVertex, yVertex, zVertex);
return sqrt(dx*dx + dy*dy);
}
double DefaultHepRepPoint::getPhi(double xVertex, double yVertex, double zVertex) {
return atan2(getY(xVertex, yVertex, zVertex), getX(xVertex, yVertex, zVertex));
}
double DefaultHepRepPoint::getTheta(double xVertex, double yVertex, double zVertex) {
return atan2(getRho(xVertex, yVertex, zVertex), getZ(xVertex, yVertex, zVertex));
}
double DefaultHepRepPoint::getR(double xVertex, double yVertex, double zVertex) {
double dr = getRho(xVertex, yVertex, zVertex);
double dz = getZ(xVertex, yVertex, zVertex);
return sqrt(dr*dr + dz*dz);
}
double DefaultHepRepPoint::getEta(double xVertex, double yVertex, double zVertex) {
double ct = cos(getTheta(xVertex, yVertex, zVertex));
return -0.5*log((1.-ct)/(1.+ct));
}
} // cheprep
// Copyright FreeHEP, 2005.
#include <string>
#include <iostream>
#include <cmath>
#include "cheprep/DefaultHepRepPoint.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
*/
namespace cheprep {
DefaultHepRepPoint::DefaultHepRepPoint(HepRepInstance* inst, double xx, double yy, double zz)
: DefaultHepRepAttribute(), instance(inst), x(xx), y(yy), z(zz) {
if (instance == NULL) {
cerr << "HepRepPoints cannot be created without a HepRepInstance." << endl;
} else {
instance->addPoint(this);
}
}
DefaultHepRepPoint::~DefaultHepRepPoint() {
}
HepRepInstance* DefaultHepRepPoint::getInstance() {
return instance;
}
HepRepAttValue* DefaultHepRepPoint::getAttValue(string lowerCaseName) {
HepRepAttValue* value = getAttValueFromNode(lowerCaseName);
return (value != NULL) ? value : instance->getAttValue(lowerCaseName);
}
HepRepPoint* DefaultHepRepPoint::copy(HepRepInstance* inst) {
return new DefaultHepRepPoint(inst, x, y, z);
}
double DefaultHepRepPoint::getX() {
return x;
}
double DefaultHepRepPoint::getY() {
return y;
}
double DefaultHepRepPoint::getZ() {
return z;
}
vector<double>* DefaultHepRepPoint::getXYZ(vector<double>* xyz) {
(*xyz)[0] = x;
(*xyz)[1] = y;
(*xyz)[2] = z;
return xyz;
}
double DefaultHepRepPoint::getRho() {
return sqrt(x*x + y*y);
}
double DefaultHepRepPoint::getPhi() {
return atan2(y, x);
}
double DefaultHepRepPoint::getTheta() {
return atan2(getRho(), z);
}
double DefaultHepRepPoint::getR() {
double r = getRho();
return sqrt(r*r + z*z);
}
double DefaultHepRepPoint::getEta() {
double ct = cos(getTheta());
return -0.5*log((1.-ct)/(1.+ct));
}
double DefaultHepRepPoint::getX(double xVertex, double, double) {
return x - xVertex;
}
double DefaultHepRepPoint::getY(double, double yVertex, double) {
return y - yVertex;
}
double DefaultHepRepPoint::getZ(double, double, double zVertex) {
return z - zVertex;
}
double DefaultHepRepPoint::getRho(double xVertex, double yVertex, double zVertex) {
double dx = getX(xVertex, yVertex, zVertex);
double dy = getY(xVertex, yVertex, zVertex);
return sqrt(dx*dx + dy*dy);
}
double DefaultHepRepPoint::getPhi(double xVertex, double yVertex, double zVertex) {
return atan2(getY(xVertex, yVertex, zVertex), getX(xVertex, yVertex, zVertex));
}
double DefaultHepRepPoint::getTheta(double xVertex, double yVertex, double zVertex) {
return atan2(getRho(xVertex, yVertex, zVertex), getZ(xVertex, yVertex, zVertex));
}
double DefaultHepRepPoint::getR(double xVertex, double yVertex, double zVertex) {
double dr = getRho(xVertex, yVertex, zVertex);
double dz = getZ(xVertex, yVertex, zVertex);
return sqrt(dr*dr + dz*dz);
}
double DefaultHepRepPoint::getEta(double xVertex, double yVertex, double zVertex) {
double ct = cos(getTheta(xVertex, yVertex, zVertex));
return -0.5*log((1.-ct)/(1.+ct));
}
} // cheprep
@@ -1,39 +1,38 @@
// Copyright FreeHEP, 2005.
#include <iostream>
#include "cheprep/DefaultHepRepTreeID.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
* @version $Id: DefaultHepRepTreeID.cc 66373 2012-12-18 09:41:34Z gcosmo $
*/
namespace cheprep {
DefaultHepRepTreeID::DefaultHepRepTreeID(string aName, string aVersion, string aQualifier)
: name(aName), version(aVersion), qualifier(aQualifier) {
}
DefaultHepRepTreeID::~DefaultHepRepTreeID() {
}
string DefaultHepRepTreeID::getQualifier() {
return qualifier;
}
void DefaultHepRepTreeID::setQualifier(string qual) {
this->qualifier = qual;
}
string DefaultHepRepTreeID::getName() {
return name;
}
string DefaultHepRepTreeID::getVersion() {
return version;
}
} // cheprep
// Copyright FreeHEP, 2005.
#include <iostream>
#include "cheprep/DefaultHepRepTreeID.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
*/
namespace cheprep {
DefaultHepRepTreeID::DefaultHepRepTreeID(string aName, string aVersion, string aQualifier)
: name(aName), version(aVersion), qualifier(aQualifier) {
}
DefaultHepRepTreeID::~DefaultHepRepTreeID() {
}
string DefaultHepRepTreeID::getQualifier() {
return qualifier;
}
void DefaultHepRepTreeID::setQualifier(string qual) {
this->qualifier = qual;
}
string DefaultHepRepTreeID::getName() {
return name;
}
string DefaultHepRepTreeID::getVersion() {
return version;
}
} // cheprep
@@ -1,113 +1,112 @@
// Copyright FreeHEP, 2005.
#include "cheprep/DefaultHepRepType.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
* @version $Id: DefaultHepRepType.cc 66373 2012-12-18 09:41:34Z gcosmo $
*/
namespace cheprep {
DefaultHepRepType::DefaultHepRepType(HepRepType* parentType, string typeName)
: DefaultHepRepDefinition(), parent(parentType), name(typeName) {
this->description = "No Description";
this->infoURL = "No Info URL";
// HepRepTypes are sometimes used without a parent (top-level)
if (parent != NULL) {
parent->addType(this);
}
}
DefaultHepRepType::DefaultHepRepType(HepRepTypeTree* parentTypeTree, string typeName)
: DefaultHepRepDefinition(), parent(NULL), name(typeName) {
this->description = "No Description";
this->infoURL = "No Info URL";
parentTypeTree->addType(this);
}
DefaultHepRepType::~DefaultHepRepType() {
for (vector<HepRepType*>::iterator i1 = types.begin(); i1 != types.end(); i1++) {
delete (*i1);
}
}
HepRepType* DefaultHepRepType::getSuperType() {
return parent;
}
HepRepAttDef* DefaultHepRepType::getAttDef(string defName) {
HepRepAttDef* def = NULL;
HepRepType* type = this;
while ((def == NULL) && (type != NULL)) {
def = type->getAttDefFromNode(defName);
type = type->getSuperType();
}
if (def == NULL) {
cerr << "ERROR: No HepRepDefaults, trying to get definition for: " << defName << endl;
// FIXME, no HepRepDefaults
}
return def;
}
/**
* searched for a value with given name. Search up the type tree if needed.
*/
HepRepAttValue* DefaultHepRepType::getAttValue(string attName) {
HepRepAttValue* value = NULL;
HepRepType* type = this;
while ((value == NULL) && (type != NULL)) {
value = type->getAttValueFromNode(attName);
type = type->getSuperType();
}
if (value == NULL) {
cerr << "ERROR: No HepRepDefaults, trying to get value for: " << attName << endl;
// FIXME, no HepRepDefaults
}
return value;
}
HepRepType* DefaultHepRepType::copy(HepRepType*) {
cerr << "DefaultHepRepType::copy(HepRepType*) not implemented." << endl;
return NULL;
}
string DefaultHepRepType::getName() {
return name;
}
string DefaultHepRepType::getFullName() {
return (getSuperType() == NULL) ? getName() : getSuperType()->getFullName() + "/" + getName();
}
string DefaultHepRepType::getDescription() {
return description;
}
void DefaultHepRepType::setDescription(string desc) {
this->description = desc;
}
string DefaultHepRepType::getInfoURL() {
return infoURL;
}
void DefaultHepRepType::setInfoURL(string info) {
this->infoURL = info;
}
void DefaultHepRepType::addType(HepRepType* type) {
// FIXME should check if type already exists
types.push_back(type);
}
vector<HepRepType*> DefaultHepRepType::getTypeList() {
return types;
}
} // cheprep
// Copyright FreeHEP, 2005.
#include "cheprep/DefaultHepRepType.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
*/
namespace cheprep {
DefaultHepRepType::DefaultHepRepType(HepRepType* parentType, string typeName)
: DefaultHepRepDefinition(), parent(parentType), name(typeName) {
this->description = "No Description";
this->infoURL = "No Info URL";
// HepRepTypes are sometimes used without a parent (top-level)
if (parent != NULL) {
parent->addType(this);
}
}
DefaultHepRepType::DefaultHepRepType(HepRepTypeTree* parentTypeTree, string typeName)
: DefaultHepRepDefinition(), parent(NULL), name(typeName) {
this->description = "No Description";
this->infoURL = "No Info URL";
parentTypeTree->addType(this);
}
DefaultHepRepType::~DefaultHepRepType() {
for (vector<HepRepType*>::iterator i1 = types.begin(); i1 != types.end(); i1++) {
delete (*i1);
}
}
HepRepType* DefaultHepRepType::getSuperType() {
return parent;
}
HepRepAttDef* DefaultHepRepType::getAttDef(string defName) {
HepRepAttDef* def = NULL;
HepRepType* type = this;
while ((def == NULL) && (type != NULL)) {
def = type->getAttDefFromNode(defName);
type = type->getSuperType();
}
if (def == NULL) {
cerr << "ERROR: No HepRepDefaults, trying to get definition for: " << defName << endl;
// FIXME, no HepRepDefaults
}
return def;
}
/**
* searched for a value with given name. Search up the type tree if needed.
*/
HepRepAttValue* DefaultHepRepType::getAttValue(string attName) {
HepRepAttValue* value = NULL;
HepRepType* type = this;
while ((value == NULL) && (type != NULL)) {
value = type->getAttValueFromNode(attName);
type = type->getSuperType();
}
if (value == NULL) {
cerr << "ERROR: No HepRepDefaults, trying to get value for: " << attName << endl;
// FIXME, no HepRepDefaults
}
return value;
}
HepRepType* DefaultHepRepType::copy(HepRepType*) {
cerr << "DefaultHepRepType::copy(HepRepType*) not implemented." << endl;
return NULL;
}
string DefaultHepRepType::getName() {
return name;
}
string DefaultHepRepType::getFullName() {
return (getSuperType() == NULL) ? getName() : getSuperType()->getFullName() + "/" + getName();
}
string DefaultHepRepType::getDescription() {
return description;
}
void DefaultHepRepType::setDescription(string desc) {
this->description = desc;
}
string DefaultHepRepType::getInfoURL() {
return infoURL;
}
void DefaultHepRepType::setInfoURL(string info) {
this->infoURL = info;
}
void DefaultHepRepType::addType(HepRepType* type) {
// FIXME should check if type already exists
types.push_back(type);
}
vector<HepRepType*> DefaultHepRepType::getTypeList() {
return types;
}
} // cheprep
@@ -1,46 +1,45 @@
// Copyright FreeHEP, 2005.
#include <iostream>
#include "cheprep/DefaultHepRepTypeTree.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
* @version $Id: DefaultHepRepTypeTree.cc 66373 2012-12-18 09:41:34Z gcosmo $
*/
namespace cheprep {
DefaultHepRepTypeTree::DefaultHepRepTypeTree(HepRepTreeID* typeTree)
: DefaultHepRepTreeID(typeTree->getName(), typeTree->getVersion()) {
delete typeTree;
}
DefaultHepRepTypeTree::~DefaultHepRepTypeTree() {
for (vector<HepRepType*>::iterator i1 = types.begin(); i1 != types.end(); i1++) {
delete (*i1);
}
}
HepRepTypeTree* DefaultHepRepTypeTree::copy() {
cerr << "DefaultHepRepTypeTree::copy() not implemented." << endl;
return NULL;
}
void DefaultHepRepTypeTree::addType(HepRepType* type) {
// FIXME should check if type already exists
types.push_back(type);
}
vector<HepRepType*> DefaultHepRepTypeTree::getTypeList() {
return types;
}
HepRepType* DefaultHepRepTypeTree::getType(string /*typeName*/) {
cerr << "DefaultHepRepTypeTree::getType(string) not implemented." << endl;
return NULL;
}
} // cheprep
// Copyright FreeHEP, 2005.
#include <iostream>
#include "cheprep/DefaultHepRepTypeTree.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
*/
namespace cheprep {
DefaultHepRepTypeTree::DefaultHepRepTypeTree(HepRepTreeID* typeTree)
: DefaultHepRepTreeID(typeTree->getName(), typeTree->getVersion()) {
delete typeTree;
}
DefaultHepRepTypeTree::~DefaultHepRepTypeTree() {
for (vector<HepRepType*>::iterator i1 = types.begin(); i1 != types.end(); i1++) {
delete (*i1);
}
}
HepRepTypeTree* DefaultHepRepTypeTree::copy() {
cerr << "DefaultHepRepTypeTree::copy() not implemented." << endl;
return NULL;
}
void DefaultHepRepTypeTree::addType(HepRepType* type) {
// FIXME should check if type already exists
types.push_back(type);
}
vector<HepRepType*> DefaultHepRepTypeTree::getTypeList() {
return types;
}
HepRepType* DefaultHepRepTypeTree::getType(string /*typeName*/) {
cerr << "DefaultHepRepTypeTree::getType(string) not implemented." << endl;
return NULL;
}
} // cheprep
@@ -1,245 +1,244 @@
// Copyright FreeHEP, 2005.
#include "cheprep/DeflateOutputStreamBuffer.h"
/**
* @author Mark Donszelmann
* @version $Id: DeflateOutputStreamBuffer.cc 68043 2013-03-13 14:27:49Z gcosmo $
*/
namespace cheprep {
using namespace std;
unsigned long DeflateOutputStreamBuffer::crctable[] = {
0x00000000L, 0x77073096L, 0xEE0E612CL, 0x990951BAL,
0x076DC419L, 0x706AF48FL, 0xE963A535L, 0x9E6495A3L,
0x0EDB8832L, 0x79DCB8A4L, 0xE0D5E91EL, 0x97D2D988L,
0x09B64C2BL, 0x7EB17CBDL, 0xE7B82D07L, 0x90BF1D91L,
0x1DB71064L, 0x6AB020F2L, 0xF3B97148L, 0x84BE41DEL,
0x1ADAD47DL, 0x6DDDE4EBL, 0xF4D4B551L, 0x83D385C7L,
0x136C9856L, 0x646BA8C0L, 0xFD62F97AL, 0x8A65C9ECL,
0x14015C4FL, 0x63066CD9L, 0xFA0F3D63L, 0x8D080DF5L,
0x3B6E20C8L, 0x4C69105EL, 0xD56041E4L, 0xA2677172L,
0x3C03E4D1L, 0x4B04D447L, 0xD20D85FDL, 0xA50AB56BL,
0x35B5A8FAL, 0x42B2986CL, 0xDBBBC9D6L, 0xACBCF940L,
0x32D86CE3L, 0x45DF5C75L, 0xDCD60DCFL, 0xABD13D59L,
0x26D930ACL, 0x51DE003AL, 0xC8D75180L, 0xBFD06116L,
0x21B4F4B5L, 0x56B3C423L, 0xCFBA9599L, 0xB8BDA50FL,
0x2802B89EL, 0x5F058808L, 0xC60CD9B2L, 0xB10BE924L,
0x2F6F7C87L, 0x58684C11L, 0xC1611DABL, 0xB6662D3DL,
0x76DC4190L, 0x01DB7106L, 0x98D220BCL, 0xEFD5102AL,
0x71B18589L, 0x06B6B51FL, 0x9FBFE4A5L, 0xE8B8D433L,
0x7807C9A2L, 0x0F00F934L, 0x9609A88EL, 0xE10E9818L,
0x7F6A0DBBL, 0x086D3D2DL, 0x91646C97L, 0xE6635C01L,
0x6B6B51F4L, 0x1C6C6162L, 0x856530D8L, 0xF262004EL,
0x6C0695EDL, 0x1B01A57BL, 0x8208F4C1L, 0xF50FC457L,
0x65B0D9C6L, 0x12B7E950L, 0x8BBEB8EAL, 0xFCB9887CL,
0x62DD1DDFL, 0x15DA2D49L, 0x8CD37CF3L, 0xFBD44C65L,
0x4DB26158L, 0x3AB551CEL, 0xA3BC0074L, 0xD4BB30E2L,
0x4ADFA541L, 0x3DD895D7L, 0xA4D1C46DL, 0xD3D6F4FBL,
0x4369E96AL, 0x346ED9FCL, 0xAD678846L, 0xDA60B8D0L,
0x44042D73L, 0x33031DE5L, 0xAA0A4C5FL, 0xDD0D7CC9L,
0x5005713CL, 0x270241AAL, 0xBE0B1010L, 0xC90C2086L,
0x5768B525L, 0x206F85B3L, 0xB966D409L, 0xCE61E49FL,
0x5EDEF90EL, 0x29D9C998L, 0xB0D09822L, 0xC7D7A8B4L,
0x59B33D17L, 0x2EB40D81L, 0xB7BD5C3BL, 0xC0BA6CADL,
0xEDB88320L, 0x9ABFB3B6L, 0x03B6E20CL, 0x74B1D29AL,
0xEAD54739L, 0x9DD277AFL, 0x04DB2615L, 0x73DC1683L,
0xE3630B12L, 0x94643B84L, 0x0D6D6A3EL, 0x7A6A5AA8L,
0xE40ECF0BL, 0x9309FF9DL, 0x0A00AE27L, 0x7D079EB1L,
0xF00F9344L, 0x8708A3D2L, 0x1E01F268L, 0x6906C2FEL,
0xF762575DL, 0x806567CBL, 0x196C3671L, 0x6E6B06E7L,
0xFED41B76L, 0x89D32BE0L, 0x10DA7A5AL, 0x67DD4ACCL,
0xF9B9DF6FL, 0x8EBEEFF9L, 0x17B7BE43L, 0x60B08ED5L,
0xD6D6A3E8L, 0xA1D1937EL, 0x38D8C2C4L, 0x4FDFF252L,
0xD1BB67F1L, 0xA6BC5767L, 0x3FB506DDL, 0x48B2364BL,
0xD80D2BDAL, 0xAF0A1B4CL, 0x36034AF6L, 0x41047A60L,
0xDF60EFC3L, 0xA867DF55L, 0x316E8EEFL, 0x4669BE79L,
0xCB61B38CL, 0xBC66831AL, 0x256FD2A0L, 0x5268E236L,
0xCC0C7795L, 0xBB0B4703L, 0x220216B9L, 0x5505262FL,
0xC5BA3BBEL, 0xB2BD0B28L, 0x2BB45A92L, 0x5CB36A04L,
0xC2D7FFA7L, 0xB5D0CF31L, 0x2CD99E8BL, 0x5BDEAE1DL,
0x9B64C2B0L, 0xEC63F226L, 0x756AA39CL, 0x026D930AL,
0x9C0906A9L, 0xEB0E363FL, 0x72076785L, 0x05005713L,
0x95BF4A82L, 0xE2B87A14L, 0x7BB12BAEL, 0x0CB61B38L,
0x92D28E9BL, 0xE5D5BE0DL, 0x7CDCEFB7L, 0x0BDBDF21L,
0x86D3D2D4L, 0xF1D4E242L, 0x68DDB3F8L, 0x1FDA836EL,
0x81BE16CDL, 0xF6B9265BL, 0x6FB077E1L, 0x18B74777L,
0x88085AE6L, 0xFF0F6A70L, 0x66063BCAL, 0x11010B5CL,
0x8F659EFFL, 0xF862AE69L, 0x616BFFD3L, 0x166CCF45L,
0xA00AE278L, 0xD70DD2EEL, 0x4E048354L, 0x3903B3C2L,
0xA7672661L, 0xD06016F7L, 0x4969474DL, 0x3E6E77DBL,
0xAED16A4AL, 0xD9D65ADCL, 0x40DF0B66L, 0x37D83BF0L,
0xA9BCAE53L, 0xDEBB9EC5L, 0x47B2CF7FL, 0x30B5FFE9L,
0xBDBDF21CL, 0xCABAC28AL, 0x53B39330L, 0x24B4A3A6L,
0xBAD03605L, 0xCDD70693L, 0x54DE5729L, 0x23D967BFL,
0xB3667A2EL, 0xC4614AB8L, 0x5D681B02L, 0x2A6F2B94L,
0xB40BBE37L, 0xC30C8EA1L, 0x5A05DF1BL, 0x2D02EF8DL
};
DeflateOutputStreamBuffer::DeflateOutputStreamBuffer(streambuf *aBuffer)
: buffer(aBuffer)
, crc(0)
, size(0)
#ifndef CHEPREP_NO_ZLIB
, zStreamOpen(false)
, in(inSize)
, out(outSize)
#endif // CHEPREP_NO_ZLIB
{
#ifndef CHEPREP_NO_ZLIB
zStream.zalloc = Z_NULL;
zStream.zfree = Z_NULL;
zStream.opaque = Z_NULL;
zStream.msg = 0;
zStream.next_in = 0;
zStream.next_out = 0;
zStream.state = 0;
#endif // CHEPREP_NO_ZLIB
}
#ifndef CHEPREP_NO_ZLIB
void DeflateOutputStreamBuffer::init(bool compress) {
if (compress) {
if (zStreamOpen) return;
zStream.next_in = reinterpret_cast<unsigned char *>(&(in[0]));
zStream.avail_in = 0 ;
zStream.next_out = reinterpret_cast<unsigned char *>(&(out[0]));
zStream.avail_out = out.size();
if (deflateInit2(&zStream, 6, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY ) != Z_OK) {
cerr << "ERROR: deflateInit2 failed" << endl;
} else {
zStreamOpen = true;
setp(&(in[0]), &(in[0])+inSize);
}
}
#else
void DeflateOutputStreamBuffer::init(bool /*compress*/) {
#endif // CHEPREP_NO_ZLIB
crc = 0;
size = 0;
}
void DeflateOutputStreamBuffer::finish() {
#ifndef CHEPREP_NO_ZLIB
if (zStreamOpen) {
overflow() ;
zStream.next_out = reinterpret_cast<unsigned char *>(&(out[0]));
zStream.avail_out = outSize;
int err = Z_OK ;
while ( err == Z_OK ) {
if (zStream.avail_out == 0) {
flushOut();
}
err = deflate(&zStream, Z_FINISH);
}
flushOut() ;
if (err != Z_STREAM_END) {
cerr << "ERROR: deflation failed" << endl;
}
if (deflateEnd(&zStream) != Z_OK) {
cerr << "ERROR: deflateEnd failed" << endl;
}
zStreamOpen = false ;
}
#endif // CHEPREP_NO_ZLIB
}
DeflateOutputStreamBuffer::~DeflateOutputStreamBuffer() {
}
#ifndef CHEPREP_NO_ZLIB
#define DO1 crc = crctable[(crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
#endif // CHEPREP_NO_ZLIB
int DeflateOutputStreamBuffer::overflow(int c) {
#ifndef CHEPREP_NO_ZLIB
if (zStreamOpen) {
zStream.avail_in = pptr() - pbase() ;
zStream.next_in = reinterpret_cast<unsigned char *>(&(in[0]));
int len = zStream.avail_in;
unsigned char* buf = zStream.next_in;
crc = crc ^ 0xffffffffUL;
while (len >= 8) {
DO8;
len -= 8;
}
if (len) do {
DO1;
} while (--len);
crc = crc ^ 0xffffffffUL;
size += zStream.avail_in;
zStream.next_out = reinterpret_cast<unsigned char *>(&(out[0]));
zStream.avail_out = outSize ;
int err = Z_OK ;
while ((zStream.avail_in > 0 || zStream.avail_out == 0) && err == Z_OK) {
if (zStream.avail_out == 0 ) {
flushOut();
}
err = deflate(&zStream, Z_NO_FLUSH);
}
flushOut();
setp(&(in[0]), &(in[0]) + inSize);
if ((err != Z_OK) && (err != Z_STREAM_END)) {
cerr << "ERROR: deflation failed" << endl;
return EOF ;
}
if ( c != EOF ) {
*pptr() = c ;
pbump(1);
}
return 0 ;
} else {
#endif // CHEPREP_NO_ZLIB
crc = crc ^ 0xffffffffUL;
crc = crctable[(crc ^ c) & 0xff] ^ (crc >> 8);
crc = crc ^ 0xffffffffUL;
size++;
return buffer->sputc((char)c);
#ifndef CHEPREP_NO_ZLIB
}
#endif // CHEPREP_NO_ZLIB
}
#ifndef CHEPREP_NO_ZLIB
bool DeflateOutputStreamBuffer::flushOut() {
int deflatedCount = outSize - zStream.avail_out;
int byteCount = buffer->sputn(&(out[0]), deflatedCount);
zStream.next_out = reinterpret_cast<unsigned char *>(&(out[0]));
zStream.avail_out = outSize ;
return deflatedCount == byteCount ;
}
#endif // CHEPREP_NO_ZLIB
} // cheprep
// Copyright FreeHEP, 2005.
#include "cheprep/DeflateOutputStreamBuffer.h"
/**
* @author Mark Donszelmann
*/
namespace cheprep {
using namespace std;
unsigned long DeflateOutputStreamBuffer::crctable[] = {
0x00000000L, 0x77073096L, 0xEE0E612CL, 0x990951BAL,
0x076DC419L, 0x706AF48FL, 0xE963A535L, 0x9E6495A3L,
0x0EDB8832L, 0x79DCB8A4L, 0xE0D5E91EL, 0x97D2D988L,
0x09B64C2BL, 0x7EB17CBDL, 0xE7B82D07L, 0x90BF1D91L,
0x1DB71064L, 0x6AB020F2L, 0xF3B97148L, 0x84BE41DEL,
0x1ADAD47DL, 0x6DDDE4EBL, 0xF4D4B551L, 0x83D385C7L,
0x136C9856L, 0x646BA8C0L, 0xFD62F97AL, 0x8A65C9ECL,
0x14015C4FL, 0x63066CD9L, 0xFA0F3D63L, 0x8D080DF5L,
0x3B6E20C8L, 0x4C69105EL, 0xD56041E4L, 0xA2677172L,
0x3C03E4D1L, 0x4B04D447L, 0xD20D85FDL, 0xA50AB56BL,
0x35B5A8FAL, 0x42B2986CL, 0xDBBBC9D6L, 0xACBCF940L,
0x32D86CE3L, 0x45DF5C75L, 0xDCD60DCFL, 0xABD13D59L,
0x26D930ACL, 0x51DE003AL, 0xC8D75180L, 0xBFD06116L,
0x21B4F4B5L, 0x56B3C423L, 0xCFBA9599L, 0xB8BDA50FL,
0x2802B89EL, 0x5F058808L, 0xC60CD9B2L, 0xB10BE924L,
0x2F6F7C87L, 0x58684C11L, 0xC1611DABL, 0xB6662D3DL,
0x76DC4190L, 0x01DB7106L, 0x98D220BCL, 0xEFD5102AL,
0x71B18589L, 0x06B6B51FL, 0x9FBFE4A5L, 0xE8B8D433L,
0x7807C9A2L, 0x0F00F934L, 0x9609A88EL, 0xE10E9818L,
0x7F6A0DBBL, 0x086D3D2DL, 0x91646C97L, 0xE6635C01L,
0x6B6B51F4L, 0x1C6C6162L, 0x856530D8L, 0xF262004EL,
0x6C0695EDL, 0x1B01A57BL, 0x8208F4C1L, 0xF50FC457L,
0x65B0D9C6L, 0x12B7E950L, 0x8BBEB8EAL, 0xFCB9887CL,
0x62DD1DDFL, 0x15DA2D49L, 0x8CD37CF3L, 0xFBD44C65L,
0x4DB26158L, 0x3AB551CEL, 0xA3BC0074L, 0xD4BB30E2L,
0x4ADFA541L, 0x3DD895D7L, 0xA4D1C46DL, 0xD3D6F4FBL,
0x4369E96AL, 0x346ED9FCL, 0xAD678846L, 0xDA60B8D0L,
0x44042D73L, 0x33031DE5L, 0xAA0A4C5FL, 0xDD0D7CC9L,
0x5005713CL, 0x270241AAL, 0xBE0B1010L, 0xC90C2086L,
0x5768B525L, 0x206F85B3L, 0xB966D409L, 0xCE61E49FL,
0x5EDEF90EL, 0x29D9C998L, 0xB0D09822L, 0xC7D7A8B4L,
0x59B33D17L, 0x2EB40D81L, 0xB7BD5C3BL, 0xC0BA6CADL,
0xEDB88320L, 0x9ABFB3B6L, 0x03B6E20CL, 0x74B1D29AL,
0xEAD54739L, 0x9DD277AFL, 0x04DB2615L, 0x73DC1683L,
0xE3630B12L, 0x94643B84L, 0x0D6D6A3EL, 0x7A6A5AA8L,
0xE40ECF0BL, 0x9309FF9DL, 0x0A00AE27L, 0x7D079EB1L,
0xF00F9344L, 0x8708A3D2L, 0x1E01F268L, 0x6906C2FEL,
0xF762575DL, 0x806567CBL, 0x196C3671L, 0x6E6B06E7L,
0xFED41B76L, 0x89D32BE0L, 0x10DA7A5AL, 0x67DD4ACCL,
0xF9B9DF6FL, 0x8EBEEFF9L, 0x17B7BE43L, 0x60B08ED5L,
0xD6D6A3E8L, 0xA1D1937EL, 0x38D8C2C4L, 0x4FDFF252L,
0xD1BB67F1L, 0xA6BC5767L, 0x3FB506DDL, 0x48B2364BL,
0xD80D2BDAL, 0xAF0A1B4CL, 0x36034AF6L, 0x41047A60L,
0xDF60EFC3L, 0xA867DF55L, 0x316E8EEFL, 0x4669BE79L,
0xCB61B38CL, 0xBC66831AL, 0x256FD2A0L, 0x5268E236L,
0xCC0C7795L, 0xBB0B4703L, 0x220216B9L, 0x5505262FL,
0xC5BA3BBEL, 0xB2BD0B28L, 0x2BB45A92L, 0x5CB36A04L,
0xC2D7FFA7L, 0xB5D0CF31L, 0x2CD99E8BL, 0x5BDEAE1DL,
0x9B64C2B0L, 0xEC63F226L, 0x756AA39CL, 0x026D930AL,
0x9C0906A9L, 0xEB0E363FL, 0x72076785L, 0x05005713L,
0x95BF4A82L, 0xE2B87A14L, 0x7BB12BAEL, 0x0CB61B38L,
0x92D28E9BL, 0xE5D5BE0DL, 0x7CDCEFB7L, 0x0BDBDF21L,
0x86D3D2D4L, 0xF1D4E242L, 0x68DDB3F8L, 0x1FDA836EL,
0x81BE16CDL, 0xF6B9265BL, 0x6FB077E1L, 0x18B74777L,
0x88085AE6L, 0xFF0F6A70L, 0x66063BCAL, 0x11010B5CL,
0x8F659EFFL, 0xF862AE69L, 0x616BFFD3L, 0x166CCF45L,
0xA00AE278L, 0xD70DD2EEL, 0x4E048354L, 0x3903B3C2L,
0xA7672661L, 0xD06016F7L, 0x4969474DL, 0x3E6E77DBL,
0xAED16A4AL, 0xD9D65ADCL, 0x40DF0B66L, 0x37D83BF0L,
0xA9BCAE53L, 0xDEBB9EC5L, 0x47B2CF7FL, 0x30B5FFE9L,
0xBDBDF21CL, 0xCABAC28AL, 0x53B39330L, 0x24B4A3A6L,
0xBAD03605L, 0xCDD70693L, 0x54DE5729L, 0x23D967BFL,
0xB3667A2EL, 0xC4614AB8L, 0x5D681B02L, 0x2A6F2B94L,
0xB40BBE37L, 0xC30C8EA1L, 0x5A05DF1BL, 0x2D02EF8DL
};
DeflateOutputStreamBuffer::DeflateOutputStreamBuffer(streambuf *aBuffer)
: buffer(aBuffer)
, crc(0)
, size(0)
#ifndef CHEPREP_NO_ZLIB
, zStreamOpen(false)
, in(inSize)
, out(outSize)
#endif // CHEPREP_NO_ZLIB
{
#ifndef CHEPREP_NO_ZLIB
zStream.zalloc = Z_NULL;
zStream.zfree = Z_NULL;
zStream.opaque = Z_NULL;
zStream.msg = 0;
zStream.next_in = 0;
zStream.next_out = 0;
zStream.state = 0;
#endif // CHEPREP_NO_ZLIB
}
#ifndef CHEPREP_NO_ZLIB
void DeflateOutputStreamBuffer::init(bool compress) {
if (compress) {
if (zStreamOpen) return;
zStream.next_in = reinterpret_cast<unsigned char *>(&(in[0]));
zStream.avail_in = 0 ;
zStream.next_out = reinterpret_cast<unsigned char *>(&(out[0]));
zStream.avail_out = out.size();
if (deflateInit2(&zStream, 6, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY ) != Z_OK) {
cerr << "ERROR: deflateInit2 failed" << endl;
} else {
zStreamOpen = true;
setp(&(in[0]), &(in[0])+inSize);
}
}
#else
void DeflateOutputStreamBuffer::init(bool /*compress*/) {
#endif // CHEPREP_NO_ZLIB
crc = 0;
size = 0;
}
void DeflateOutputStreamBuffer::finish() {
#ifndef CHEPREP_NO_ZLIB
if (zStreamOpen) {
overflow() ;
zStream.next_out = reinterpret_cast<unsigned char *>(&(out[0]));
zStream.avail_out = outSize;
int err = Z_OK ;
while ( err == Z_OK ) {
if (zStream.avail_out == 0) {
flushOut();
}
err = deflate(&zStream, Z_FINISH);
}
flushOut() ;
if (err != Z_STREAM_END) {
cerr << "ERROR: deflation failed" << endl;
}
if (deflateEnd(&zStream) != Z_OK) {
cerr << "ERROR: deflateEnd failed" << endl;
}
zStreamOpen = false ;
}
#endif // CHEPREP_NO_ZLIB
}
DeflateOutputStreamBuffer::~DeflateOutputStreamBuffer() {
}
#ifndef CHEPREP_NO_ZLIB
#define DO1 crc = crctable[(crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
#endif // CHEPREP_NO_ZLIB
int DeflateOutputStreamBuffer::overflow(int c) {
#ifndef CHEPREP_NO_ZLIB
if (zStreamOpen) {
zStream.avail_in = pptr() - pbase() ;
zStream.next_in = reinterpret_cast<unsigned char *>(&(in[0]));
int len = zStream.avail_in;
unsigned char* buf = zStream.next_in;
crc = crc ^ 0xffffffffUL;
while (len >= 8) {
DO8;
len -= 8;
}
if (len) do {
DO1;
} while (--len);
crc = crc ^ 0xffffffffUL;
size += zStream.avail_in;
zStream.next_out = reinterpret_cast<unsigned char *>(&(out[0]));
zStream.avail_out = outSize ;
int err = Z_OK ;
while ((zStream.avail_in > 0 || zStream.avail_out == 0) && err == Z_OK) {
if (zStream.avail_out == 0 ) {
flushOut();
}
err = deflate(&zStream, Z_NO_FLUSH);
}
flushOut();
setp(&(in[0]), &(in[0]) + inSize);
if ((err != Z_OK) && (err != Z_STREAM_END)) {
cerr << "ERROR: deflation failed" << endl;
return EOF ;
}
if ( c != EOF ) {
*pptr() = c ;
pbump(1);
}
return 0 ;
} else {
#endif // CHEPREP_NO_ZLIB
crc = crc ^ 0xffffffffUL;
crc = crctable[(crc ^ c) & 0xff] ^ (crc >> 8);
crc = crc ^ 0xffffffffUL;
size++;
return buffer->sputc((char)c);
#ifndef CHEPREP_NO_ZLIB
}
#endif // CHEPREP_NO_ZLIB
}
#ifndef CHEPREP_NO_ZLIB
bool DeflateOutputStreamBuffer::flushOut() {
int deflatedCount = outSize - zStream.avail_out;
int byteCount = buffer->sputn(&(out[0]), deflatedCount);
zStream.next_out = reinterpret_cast<unsigned char *>(&(out[0]));
zStream.avail_out = outSize ;
return deflatedCount == byteCount ;
}
#endif // CHEPREP_NO_ZLIB
} // cheprep
@@ -23,7 +23,6 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4HepRep.cc 78838 2014-01-28 08:46:17Z gcosmo $
//
/**
@@ -23,7 +23,6 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4HepRepFile.cc 78838 2014-01-28 08:46:17Z gcosmo $
//
//
// Joseph Perl 1 October 2001
@@ -23,7 +23,6 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4HepRepFileSceneHandler.cc 101714 2016-11-22 08:53:13Z gcosmo $
//
//
// Joseph Perl 27th January 2002
@@ -23,7 +23,6 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4HepRepFileViewer.cc 66373 2012-12-18 09:41:34Z gcosmo $
#include "G4HepRepFileViewer.hh"
@@ -25,7 +25,6 @@
//
//--------------------------------------------------------------------------
// File and Version Information:
// $Id: G4HepRepFileXMLWriter.cc 66373 2012-12-18 09:41:34Z gcosmo $
//
// Description:
// Create a HepRep XML File (HepRep version 1).
@@ -23,7 +23,6 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4HepRepMessenger.cc 106384 2017-10-09 09:34:51Z gcosmo $
//
#include "G4HepRepMessenger.hh"
@@ -23,7 +23,6 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4HepRepSceneHandler.cc 104290 2017-05-23 13:24:52Z gcosmo $
//
/**
@@ -23,7 +23,6 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4HepRepViewer.cc 68043 2013-03-13 14:27:49Z gcosmo $
//
/**
@@ -1,39 +1,38 @@
// Copyright FreeHEP, 2005.
#include "cheprep/GZIPOutputStreamBuffer.h"
#include "cheprep/GZIPOutputStream.h"
/**
* @author Mark Donszelmann
* @version $Id: GZIPOutputStream.cc 66373 2012-12-18 09:41:34Z gcosmo $
*/
namespace cheprep {
using namespace std;
GZIPOutputStream::GZIPOutputStream(ostream &os)
: std::ostream(NULL) {
buffer = new GZIPOutputStreamBuffer(os.rdbuf());
init(buffer);
}
void GZIPOutputStream::setFilename(const string &filename) {
buffer->setFilename(filename);
}
void GZIPOutputStream::setComment(const string &comment) {
buffer->setComment(comment);
}
void GZIPOutputStream::close() {
buffer->close();
}
GZIPOutputStream::~GZIPOutputStream() {
delete buffer;
}
} // cheprep
// Copyright FreeHEP, 2005.
#include "cheprep/GZIPOutputStreamBuffer.h"
#include "cheprep/GZIPOutputStream.h"
/**
* @author Mark Donszelmann
*/
namespace cheprep {
using namespace std;
GZIPOutputStream::GZIPOutputStream(ostream &os)
: std::ostream(NULL) {
buffer = new GZIPOutputStreamBuffer(os.rdbuf());
init(buffer);
}
void GZIPOutputStream::setFilename(const string &filename) {
buffer->setFilename(filename);
}
void GZIPOutputStream::setComment(const string &comment) {
buffer->setComment(comment);
}
void GZIPOutputStream::close() {
buffer->close();
}
GZIPOutputStream::~GZIPOutputStream() {
delete buffer;
}
} // cheprep
@@ -1,78 +1,77 @@
// Copyright FreeHEP, 2005.
#include "cheprep/GZIPOutputStreamBuffer.h"
/**
* @author Mark Donszelmann
* @version $Id: GZIPOutputStreamBuffer.cc 66373 2012-12-18 09:41:34Z gcosmo $
*/
namespace cheprep {
using namespace std;
GZIPOutputStreamBuffer::GZIPOutputStreamBuffer( streambuf *aBuffer)
: DeflateOutputStreamBuffer(aBuffer),
open(false) {
init(true);
}
void GZIPOutputStreamBuffer::setFilename( const string &name ) {
filename = name ;
}
void GZIPOutputStreamBuffer::setComment( const string &c ) {
comment = c ;
}
void GZIPOutputStreamBuffer::close() {
if (!open) return;
finish();
writeTrailer();
open = false ;
}
GZIPOutputStreamBuffer::~GZIPOutputStreamBuffer() {
close() ;
}
int GZIPOutputStreamBuffer::overflow( int c ) {
if (!open) {
writeHeader();
open = true;
}
return DeflateOutputStreamBuffer::overflow( c ) ;
}
void GZIPOutputStreamBuffer::writeHeader() {
unsigned char flag = 0x00;
flag |= (filename == "") ? 0x00 : 0x08;
flag |= (comment == "") ? 0x00 : 0x10;
putUB(0x1f); // Magic #
putUB(0x8b); // Magic #
putUB(0x08); // Deflater.DEFLATED
putUB(flag); // FLG
putUI(0x00000000); // MTIME
putUB(0x00); // XFLG
putUB(0x00); // OS
if (filename != "") {
putS(filename); // Filename
putUB(0x00);
}
if (comment != "") {
putS(comment); // Comment
putUB(0x00);
}
}
void GZIPOutputStreamBuffer::writeTrailer() {
putUI(getCRC());
putUI(getSize());
}
} // cheprep
// Copyright FreeHEP, 2005.
#include "cheprep/GZIPOutputStreamBuffer.h"
/**
* @author Mark Donszelmann
*/
namespace cheprep {
using namespace std;
GZIPOutputStreamBuffer::GZIPOutputStreamBuffer( streambuf *aBuffer)
: DeflateOutputStreamBuffer(aBuffer),
open(false) {
init(true);
}
void GZIPOutputStreamBuffer::setFilename( const string &name ) {
filename = name ;
}
void GZIPOutputStreamBuffer::setComment( const string &c ) {
comment = c ;
}
void GZIPOutputStreamBuffer::close() {
if (!open) return;
finish();
writeTrailer();
open = false ;
}
GZIPOutputStreamBuffer::~GZIPOutputStreamBuffer() {
close() ;
}
int GZIPOutputStreamBuffer::overflow( int c ) {
if (!open) {
writeHeader();
open = true;
}
return DeflateOutputStreamBuffer::overflow( c ) ;
}
void GZIPOutputStreamBuffer::writeHeader() {
unsigned char flag = 0x00;
flag |= (filename == "") ? 0x00 : 0x08;
flag |= (comment == "") ? 0x00 : 0x10;
putUB(0x1f); // Magic #
putUB(0x8b); // Magic #
putUB(0x08); // Deflater.DEFLATED
putUB(flag); // FLG
putUI(0x00000000); // MTIME
putUB(0x00); // XFLG
putUB(0x00); // OS
if (filename != "") {
putS(filename); // Filename
putUB(0x00);
}
if (comment != "") {
putS(comment); // Comment
putUB(0x00);
}
}
void GZIPOutputStreamBuffer::writeTrailer() {
putUI(getCRC());
putUI(getSize());
}
} // cheprep
@@ -1,89 +1,88 @@
// Copyright FreeHEP, 2005.
#include <fstream>
#include "cheprep/IndentPrintWriter.h"
using namespace std;
/**
* @author Mark Donszelmann
* @version $Id: IndentPrintWriter.cc 66373 2012-12-18 09:41:34Z gcosmo $
*/
namespace cheprep {
IndentPrintWriter::IndentPrintWriter(ostream* outstream, int level)
: out(outstream),
closed(false),
indentLevel(level),
indented(false),
indentString(" ") {
}
IndentPrintWriter::~IndentPrintWriter() {
}
void IndentPrintWriter::close() {
if (!closed) {
out->flush();
closed = true;
}
}
IndentPrintWriter& IndentPrintWriter::operator<< (const std::string & s) {
if (!indented) doIndent();
*out << s;
return *this;
}
IndentPrintWriter& IndentPrintWriter::operator<< (ostream& (*)(ostream&)) {
*out << endl;
indented = false;
return *this;
}
void IndentPrintWriter::println(const string & s) {
*this << s << endl;
}
void IndentPrintWriter::print(const string & s) {
*this << s;
}
void IndentPrintWriter::println() {
*out << endl;
indented = false;
}
void IndentPrintWriter::doIndent() {
for (int i=0; i<indentLevel; i++) {
*out << indentString;
}
indented = true;
}
void IndentPrintWriter::indent() {
indentLevel++;
}
void IndentPrintWriter::outdent() {
indentLevel--;
}
int IndentPrintWriter::getIndent() const {
return indentLevel;
}
void IndentPrintWriter::setIndent(const int level) {
indentLevel = level;
}
string IndentPrintWriter::getIndentString() const {
return indentString;
}
void IndentPrintWriter::setIndentString(const string & anIndent) {
indentString = anIndent;
}
} // cheprep
// Copyright FreeHEP, 2005.
#include <fstream>
#include "cheprep/IndentPrintWriter.h"
using namespace std;
/**
* @author Mark Donszelmann
*/
namespace cheprep {
IndentPrintWriter::IndentPrintWriter(ostream* outstream, int level)
: out(outstream),
closed(false),
indentLevel(level),
indented(false),
indentString(" ") {
}
IndentPrintWriter::~IndentPrintWriter() {
}
void IndentPrintWriter::close() {
if (!closed) {
out->flush();
closed = true;
}
}
IndentPrintWriter& IndentPrintWriter::operator<< (const std::string & s) {
if (!indented) doIndent();
*out << s;
return *this;
}
IndentPrintWriter& IndentPrintWriter::operator<< (ostream& (*)(ostream&)) {
*out << endl;
indented = false;
return *this;
}
void IndentPrintWriter::println(const string & s) {
*this << s << endl;
}
void IndentPrintWriter::print(const string & s) {
*this << s;
}
void IndentPrintWriter::println() {
*out << endl;
indented = false;
}
void IndentPrintWriter::doIndent() {
for (int i=0; i<indentLevel; i++) {
*out << indentString;
}
indented = true;
}
void IndentPrintWriter::indent() {
indentLevel++;
}
void IndentPrintWriter::outdent() {
indentLevel--;
}
int IndentPrintWriter::getIndent() const {
return indentLevel;
}
void IndentPrintWriter::setIndent(const int level) {
indentLevel = level;
}
string IndentPrintWriter::getIndentString() const {
return indentString;
}
void IndentPrintWriter::setIndentString(const string & anIndent) {
indentString = anIndent;
}
} // cheprep
@@ -1,40 +1,39 @@
// Copyright FreeHEP, 2005.
#include <iostream>
#include <fstream>
#include "cheprep/XMLHepRepWriter.h"
#include "cheprep/XMLHepRepFactory.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
* @version $Id: XMLHepRepFactory.cc 66373 2012-12-18 09:41:34Z gcosmo $
*/
namespace cheprep {
XMLHepRepFactory::XMLHepRepFactory() {
}
XMLHepRepFactory::~XMLHepRepFactory() {
}
HepRepReader* XMLHepRepFactory::createHepRepReader (istream*) {
cerr << "XMLHepRepFactory::createHepRepReader not implemented" << endl;
return NULL;
}
HepRepReader* XMLHepRepFactory::createHepRepReader (std::string) {
cerr << "XMLHepRepFactory::createHepRepReader not implemented" << endl;
return NULL;
}
HepRepWriter* XMLHepRepFactory::createHepRepWriter(ostream* out, bool randomAccess, bool compress) {
return new XMLHepRepWriter(out, randomAccess, compress);
}
} // cheprep
// Copyright FreeHEP, 2005.
#include <iostream>
#include <fstream>
#include "cheprep/XMLHepRepWriter.h"
#include "cheprep/XMLHepRepFactory.h"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
*/
namespace cheprep {
XMLHepRepFactory::XMLHepRepFactory() {
}
XMLHepRepFactory::~XMLHepRepFactory() {
}
HepRepReader* XMLHepRepFactory::createHepRepReader (istream*) {
cerr << "XMLHepRepFactory::createHepRepReader not implemented" << endl;
return NULL;
}
HepRepReader* XMLHepRepFactory::createHepRepReader (std::string) {
cerr << "XMLHepRepFactory::createHepRepReader not implemented" << endl;
return NULL;
}
HepRepWriter* XMLHepRepFactory::createHepRepWriter(ostream* out, bool randomAccess, bool compress) {
return new XMLHepRepWriter(out, randomAccess, compress);
}
} // cheprep
+288 -289
View File
@@ -1,289 +1,288 @@
// Copyright FreeHEP, 2005.
#include "cheprep/XMLHepRepWriter.h"
#include "cheprep/XMLWriter.h"
#include "cheprep/BHepRepWriter.h"
#include "cheprep/DefaultHepRepInstance.h"
#include "cheprep/DefaultHepRepAttValue.h"
#define NAMESPACE "heprep"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
* @version $Id: XMLHepRepWriter.cc 68043 2013-03-13 14:27:49Z gcosmo $
*/
namespace cheprep {
XMLHepRepWriter::XMLHepRepWriter(ostream* os, bool randomAccess, bool useCompression)
: out(os),
compress(useCompression),
xml(0) {
this->nameSpace = NAMESPACE;
if (randomAccess) {
zip = new ZipOutputStream(*os);
out = zip;
gz = NULL;
} else {
zip = NULL;
if (useCompression) {
#ifndef CHEPREP_NO_ZLIB
gz = new GZIPOutputStream(*os);
out = gz;
#else
cerr << "WARNING: the .gz output stream you are creating will be a plain file," << endl;
cerr << "since compression support (ZLIB) was not compiled into the library." << endl;
cerr << "To add ZLIB support, you need to undefine CHEPREP_NO_ZLIB." << endl;
gz = NULL;
#endif
} else {
gz = NULL;
}
}
}
XMLHepRepWriter::~XMLHepRepWriter() {
delete gz;
delete zip;
}
bool XMLHepRepWriter::addProperty(std::string key, std::string value) {
properties[key] = value;
return true;
}
bool XMLHepRepWriter::close() {
if (zip != NULL) {
zip->putNextEntry("heprep.properties", true);
map<string, string>::iterator i = properties.begin();
while (i != properties.end()) {
*zip << (*i).first << "=" << (*i).second << endl;
i++;
}
zip->closeEntry();
zip->close();
}
if (gz != NULL) {
gz->close();
}
return true;
}
bool XMLHepRepWriter::write(HepRep* heprep, string name) {
if (zip != NULL) {
zip->putNextEntry(name, compress);
}
if (name.rfind(".bheprep") == name.length()-8) {
xml = new BHepRepWriter(*out);
} else {
xml = new XMLWriter(out, " ", NAMESPACE);
}
xml->openDoc();
xml->setAttribute("version", (string)"2.0");
xml->setAttribute("xmlns", (string)"http://java.freehep.org/schemas/heprep/2.0");
xml->setAttribute("xmlns", "xsi", "http://www.w3.org/2001/XMLSchema-instance");
xml->setAttribute("xsi", "schemaLocation", "http://java.freehep.org/schemas/heprep/2.0 http://java.freehep.org/schemas/heprep/2.0/HepRep.xsd");
xml->openTag(nameSpace, "heprep");
write(heprep->getLayerOrder());
vector<HepRepTypeTree*> typeTreeSet = heprep->getTypeTreeList();
for (vector<HepRepTypeTree*>::iterator i1=typeTreeSet.begin(); i1 != typeTreeSet.end(); i1++) {
write(*i1);
}
vector<HepRepInstanceTree*> instanceTreeSet = heprep->getInstanceTreeList();
for (vector<HepRepInstanceTree*>::iterator i2=instanceTreeSet.begin(); i2 != instanceTreeSet.end(); i2++) {
write(*i2);
}
xml->closeTag();
xml->closeDoc();
// xml->close();
delete xml;
if (zip != NULL) {
zip->closeEntry();
}
return true;
}
bool XMLHepRepWriter::write(vector<string> layers) {
string layerOrder = "";
bool comma = false;
for (vector<string>::iterator i=layers.begin(); i != layers.end(); i++) {
if (comma) {
layerOrder.append(", ");
}
layerOrder.append(*i);
comma = true;
}
xml->setAttribute("order", layerOrder);
xml->printTag(nameSpace, "layer");
return true;
}
bool XMLHepRepWriter::write(HepRepTypeTree* typeTree) {
xml->setAttribute("name", typeTree->getName());
xml->setAttribute("version", typeTree->getVersion());
xml->openTag(nameSpace, "typetree");
vector<HepRepType*> types = typeTree->getTypeList();
for (vector<HepRepType*>::iterator i=types.begin(); i != types.end(); i++) {
write(*i);
}
xml->closeTag();
return true;
}
bool XMLHepRepWriter::write(HepRepType* type) {
xml->setAttribute("name", type->getName());
xml->openTag(nameSpace, "type");
write((HepRepDefinition*)type);
write((HepRepAttribute*)type);
vector<HepRepType*> types = type->getTypeList();
for (vector<HepRepType*>::iterator i=types.begin(); i != types.end(); i++) {
write(*i);
}
xml->closeTag();
return true;
}
bool XMLHepRepWriter::write(HepRepTreeID* treeID) {
xml->setAttribute("qualifier", treeID->getQualifier());
xml->setAttribute("name", treeID->getName());
xml->setAttribute("version", treeID->getVersion());
xml->printTag(nameSpace, "treeid");
return true;
}
bool XMLHepRepWriter::write(HepRepAction* action) {
xml->setAttribute("name", action->getName());
xml->setAttribute("expression", action->getExpression());
xml->printTag(nameSpace, "action");
return true;
}
bool XMLHepRepWriter::write(HepRepInstanceTree* instanceTree) {
xml->setAttribute("name", instanceTree->getName());
xml->setAttribute("version", instanceTree->getVersion());
xml->setAttribute("typetreename", instanceTree->getTypeTree()->getName());
xml->setAttribute("typetreeversion", instanceTree->getTypeTree()->getVersion());
xml->openTag(nameSpace, "instancetree");
// refs
vector<HepRepTreeID*> instanceTreeSet = instanceTree->getInstanceTreeList();
for (vector<HepRepTreeID*>::iterator i1=instanceTreeSet.begin(); i1 != instanceTreeSet.end(); i1++) {
write(*i1);
}
// instances
vector<HepRepInstance*> instanceList = instanceTree->getInstances();
for (vector<HepRepInstance*>::iterator i2=instanceList.begin(); i2 != instanceList.end(); i2++) {
write(*i2);
}
xml->closeTag();
return true;
}
bool XMLHepRepWriter::write(HepRepInstance* instance) {
// FIXME FREEHEP-356
xml->setAttribute("type", instance->getType()->getFullName());
xml->openTag(nameSpace, "instance");
write((HepRepAttribute*)instance);
vector<HepRepPoint*> pointList = instance->getPoints();
for (vector<HepRepPoint*>::iterator i1=pointList.begin(); i1 != pointList.end(); i1++) {
write(*i1);
}
vector<HepRepInstance*> instanceList = instance->getInstances();
for (vector<HepRepInstance*>::iterator i2=instanceList.begin(); i2 != instanceList.end(); i2++) {
write(*i2);
}
xml->closeTag();
return true;
}
bool XMLHepRepWriter::write(HepRepPoint* point) {
xml->setAttribute("x", point->getX());
xml->setAttribute("y", point->getY());
xml->setAttribute("z", point->getZ());
if (point->getAttValuesFromNode().size() != 0) {
xml->openTag(nameSpace, "point");
write((HepRepAttribute*)point);
xml->closeTag();
} else {
xml->printTag(nameSpace, "point");
}
return true;
}
bool XMLHepRepWriter::write(HepRepAttribute* attribute) {
// BUG FIX. Do something special for layers, because these do not end
// up in the normal iteration.
HepRepAttValue* layerAtt = attribute->getAttValueFromNode("layer");
if (layerAtt != NULL) write(layerAtt);
set<HepRepAttValue*> attSet = attribute->getAttValuesFromNode();
for (set<HepRepAttValue*>::iterator i=attSet.begin(); i != attSet.end(); i++) {
write(*i);
}
return true;
}
bool XMLHepRepWriter::write(HepRepDefinition* definition) {
set<HepRepAttDef*> list = definition->getAttDefsFromNode();
for (set<HepRepAttDef*>::iterator i=list.begin(); i != list.end(); i++) {
write(*i);
}
return true;
}
bool XMLHepRepWriter::write(HepRepAttValue* attValue) {
string name = attValue->getName();
xml->setAttribute("name", name);
switch(attValue->getType()) {
default: xml->setAttribute("value", attValue->getAsString());
break;
case HepRepConstants::TYPE_STRING: xml->setAttribute("value", attValue->getString());
break;
case HepRepConstants::TYPE_LONG: xml->setAttribute("value", attValue->getLong());
break;
case HepRepConstants::TYPE_INT: xml->setAttribute("value", attValue->getInteger());
break;
case HepRepConstants::TYPE_DOUBLE: xml->setAttribute("value", attValue->getDouble());
break;
case HepRepConstants::TYPE_BOOLEAN: xml->setAttribute("value", attValue->getBoolean());
break;
case HepRepConstants::TYPE_COLOR: xml->setAttribute("value", attValue->getColor());
}
if (attValue->showLabel() != HepRepConstants::SHOW_NONE) {
xml->setAttribute("showlabel", attValue->showLabel());
}
xml->printTag(nameSpace, "attvalue");
return true;
}
bool XMLHepRepWriter::write(HepRepAttDef* attDef) {
xml->setAttribute("name", attDef->getName());
xml->setAttribute("desc", attDef->getDescription());
xml->setAttribute("category", attDef->getCategory());
xml->setAttribute("extra", attDef->getExtra());
xml->printTag(nameSpace, "attdef");
return true;
}
} // cheprep
// Copyright FreeHEP, 2005.
#include "cheprep/XMLHepRepWriter.h"
#include "cheprep/XMLWriter.h"
#include "cheprep/BHepRepWriter.h"
#include "cheprep/DefaultHepRepInstance.h"
#include "cheprep/DefaultHepRepAttValue.h"
#define NAMESPACE "heprep"
using namespace std;
using namespace HEPREP;
/**
* @author Mark Donszelmann
*/
namespace cheprep {
XMLHepRepWriter::XMLHepRepWriter(ostream* os, bool randomAccess, bool useCompression)
: out(os),
compress(useCompression),
xml(0) {
this->nameSpace = NAMESPACE;
if (randomAccess) {
zip = new ZipOutputStream(*os);
out = zip;
gz = NULL;
} else {
zip = NULL;
if (useCompression) {
#ifndef CHEPREP_NO_ZLIB
gz = new GZIPOutputStream(*os);
out = gz;
#else
cerr << "WARNING: the .gz output stream you are creating will be a plain file," << endl;
cerr << "since compression support (ZLIB) was not compiled into the library." << endl;
cerr << "To add ZLIB support, you need to undefine CHEPREP_NO_ZLIB." << endl;
gz = NULL;
#endif
} else {
gz = NULL;
}
}
}
XMLHepRepWriter::~XMLHepRepWriter() {
delete gz;
delete zip;
}
bool XMLHepRepWriter::addProperty(std::string key, std::string value) {
properties[key] = value;
return true;
}
bool XMLHepRepWriter::close() {
if (zip != NULL) {
zip->putNextEntry("heprep.properties", true);
map<string, string>::iterator i = properties.begin();
while (i != properties.end()) {
*zip << (*i).first << "=" << (*i).second << endl;
i++;
}
zip->closeEntry();
zip->close();
}
if (gz != NULL) {
gz->close();
}
return true;
}
bool XMLHepRepWriter::write(HepRep* heprep, string name) {
if (zip != NULL) {
zip->putNextEntry(name, compress);
}
if (name.rfind(".bheprep") == name.length()-8) {
xml = new BHepRepWriter(*out);
} else {
xml = new XMLWriter(out, " ", NAMESPACE);
}
xml->openDoc();
xml->setAttribute("version", (string)"2.0");
xml->setAttribute("xmlns", (string)"http://java.freehep.org/schemas/heprep/2.0");
xml->setAttribute("xmlns", "xsi", "http://www.w3.org/2001/XMLSchema-instance");
xml->setAttribute("xsi", "schemaLocation", "http://java.freehep.org/schemas/heprep/2.0 http://java.freehep.org/schemas/heprep/2.0/HepRep.xsd");
xml->openTag(nameSpace, "heprep");
write(heprep->getLayerOrder());
vector<HepRepTypeTree*> typeTreeSet = heprep->getTypeTreeList();
for (vector<HepRepTypeTree*>::iterator i1=typeTreeSet.begin(); i1 != typeTreeSet.end(); i1++) {
write(*i1);
}
vector<HepRepInstanceTree*> instanceTreeSet = heprep->getInstanceTreeList();
for (vector<HepRepInstanceTree*>::iterator i2=instanceTreeSet.begin(); i2 != instanceTreeSet.end(); i2++) {
write(*i2);
}
xml->closeTag();
xml->closeDoc();
// xml->close();
delete xml;
if (zip != NULL) {
zip->closeEntry();
}
return true;
}
bool XMLHepRepWriter::write(vector<string> layers) {
string layerOrder = "";
bool comma = false;
for (vector<string>::iterator i=layers.begin(); i != layers.end(); i++) {
if (comma) {
layerOrder.append(", ");
}
layerOrder.append(*i);
comma = true;
}
xml->setAttribute("order", layerOrder);
xml->printTag(nameSpace, "layer");
return true;
}
bool XMLHepRepWriter::write(HepRepTypeTree* typeTree) {
xml->setAttribute("name", typeTree->getName());
xml->setAttribute("version", typeTree->getVersion());
xml->openTag(nameSpace, "typetree");
vector<HepRepType*> types = typeTree->getTypeList();
for (vector<HepRepType*>::iterator i=types.begin(); i != types.end(); i++) {
write(*i);
}
xml->closeTag();
return true;
}
bool XMLHepRepWriter::write(HepRepType* type) {
xml->setAttribute("name", type->getName());
xml->openTag(nameSpace, "type");
write((HepRepDefinition*)type);
write((HepRepAttribute*)type);
vector<HepRepType*> types = type->getTypeList();
for (vector<HepRepType*>::iterator i=types.begin(); i != types.end(); i++) {
write(*i);
}
xml->closeTag();
return true;
}
bool XMLHepRepWriter::write(HepRepTreeID* treeID) {
xml->setAttribute("qualifier", treeID->getQualifier());
xml->setAttribute("name", treeID->getName());
xml->setAttribute("version", treeID->getVersion());
xml->printTag(nameSpace, "treeid");
return true;
}
bool XMLHepRepWriter::write(HepRepAction* action) {
xml->setAttribute("name", action->getName());
xml->setAttribute("expression", action->getExpression());
xml->printTag(nameSpace, "action");
return true;
}
bool XMLHepRepWriter::write(HepRepInstanceTree* instanceTree) {
xml->setAttribute("name", instanceTree->getName());
xml->setAttribute("version", instanceTree->getVersion());
xml->setAttribute("typetreename", instanceTree->getTypeTree()->getName());
xml->setAttribute("typetreeversion", instanceTree->getTypeTree()->getVersion());
xml->openTag(nameSpace, "instancetree");
// refs
vector<HepRepTreeID*> instanceTreeSet = instanceTree->getInstanceTreeList();
for (vector<HepRepTreeID*>::iterator i1=instanceTreeSet.begin(); i1 != instanceTreeSet.end(); i1++) {
write(*i1);
}
// instances
vector<HepRepInstance*> instanceList = instanceTree->getInstances();
for (vector<HepRepInstance*>::iterator i2=instanceList.begin(); i2 != instanceList.end(); i2++) {
write(*i2);
}
xml->closeTag();
return true;
}
bool XMLHepRepWriter::write(HepRepInstance* instance) {
// FIXME FREEHEP-356
xml->setAttribute("type", instance->getType()->getFullName());
xml->openTag(nameSpace, "instance");
write((HepRepAttribute*)instance);
vector<HepRepPoint*> pointList = instance->getPoints();
for (vector<HepRepPoint*>::iterator i1=pointList.begin(); i1 != pointList.end(); i1++) {
write(*i1);
}
vector<HepRepInstance*> instanceList = instance->getInstances();
for (vector<HepRepInstance*>::iterator i2=instanceList.begin(); i2 != instanceList.end(); i2++) {
write(*i2);
}
xml->closeTag();
return true;
}
bool XMLHepRepWriter::write(HepRepPoint* point) {
xml->setAttribute("x", point->getX());
xml->setAttribute("y", point->getY());
xml->setAttribute("z", point->getZ());
if (point->getAttValuesFromNode().size() != 0) {
xml->openTag(nameSpace, "point");
write((HepRepAttribute*)point);
xml->closeTag();
} else {
xml->printTag(nameSpace, "point");
}
return true;
}
bool XMLHepRepWriter::write(HepRepAttribute* attribute) {
// BUG FIX. Do something special for layers, because these do not end
// up in the normal iteration.
HepRepAttValue* layerAtt = attribute->getAttValueFromNode("layer");
if (layerAtt != NULL) write(layerAtt);
set<HepRepAttValue*> attSet = attribute->getAttValuesFromNode();
for (set<HepRepAttValue*>::iterator i=attSet.begin(); i != attSet.end(); i++) {
write(*i);
}
return true;
}
bool XMLHepRepWriter::write(HepRepDefinition* definition) {
set<HepRepAttDef*> list = definition->getAttDefsFromNode();
for (set<HepRepAttDef*>::iterator i=list.begin(); i != list.end(); i++) {
write(*i);
}
return true;
}
bool XMLHepRepWriter::write(HepRepAttValue* attValue) {
string name = attValue->getName();
xml->setAttribute("name", name);
switch(attValue->getType()) {
default: xml->setAttribute("value", attValue->getAsString());
break;
case HepRepConstants::TYPE_STRING: xml->setAttribute("value", attValue->getString());
break;
case HepRepConstants::TYPE_LONG: xml->setAttribute("value", attValue->getLong());
break;
case HepRepConstants::TYPE_INT: xml->setAttribute("value", attValue->getInteger());
break;
case HepRepConstants::TYPE_DOUBLE: xml->setAttribute("value", attValue->getDouble());
break;
case HepRepConstants::TYPE_BOOLEAN: xml->setAttribute("value", attValue->getBoolean());
break;
case HepRepConstants::TYPE_COLOR: xml->setAttribute("value", attValue->getColor());
}
if (attValue->showLabel() != HepRepConstants::SHOW_NONE) {
xml->setAttribute("showlabel", attValue->showLabel());
}
xml->printTag(nameSpace, "attvalue");
return true;
}
bool XMLHepRepWriter::write(HepRepAttDef* attDef) {
xml->setAttribute("name", attDef->getName());
xml->setAttribute("desc", attDef->getDescription());
xml->setAttribute("category", attDef->getCategory());
xml->setAttribute("extra", attDef->getExtra());
xml->printTag(nameSpace, "attdef");
return true;
}
} // cheprep
+285 -286
View File
@@ -1,286 +1,285 @@
// Copyright FreeHEP, 2005.
#include "cheprep/config.h"
#include <cstdio>
#include "cheprep/DefaultHepRepAttValue.h"
#include "cheprep/XMLWriter.h"
using namespace std;
/**
* @author Mark Donszelmann
* @version $Id: XMLWriter.cc 66373 2012-12-18 09:41:34Z gcosmo $
*/
namespace cheprep {
XMLWriter::XMLWriter(ostream* out, string indentString, string aDefaultNameSpace)
: AbstractXMLWriter(aDefaultNameSpace) {
writer = new IndentPrintWriter(out);
writer->setIndentString(indentString);
closed = false;
dtdName = "";
}
XMLWriter::~XMLWriter() {
writer->close();
delete writer;
}
void XMLWriter::close() {
closeDoc();
writer->close();
}
void XMLWriter::openDoc(string version, string encoding, bool standalone) {
string indentString = writer->getIndentString();
writer->setIndentString(indentString);
// if (!XMLCharacterProperties.validVersionNum(version)) throw new RuntimeException("Invalid version number: "+version);
*writer << "<?xml version=\"" << version.c_str() << "\" ";
if (encoding.compare("") != 0) {
// if (!XMLCharacterProperties.validEncName(encoding)) throw new RuntimeException("Invalid encoding name: "+encoding);
*writer << "encoding=\"" << encoding.c_str() << "\" ";
}
if (standalone) {
*writer << "standalone=\"yes\" ";
}
*writer << "?>";
*writer << endl;
writer->setIndentString(indentString);
}
void XMLWriter::referToDTD(string name, string pid, string ref) {
if (dtdName != "") {
cerr << "XMLWriter::ReferToDTD cannot be called twice" << endl;
}
dtdName = name;
*writer << "<!DOCTYPE " << name.c_str() << " PUBLIC \"" << pid.c_str() << "\" \"" << ref.c_str() << "\">" << endl;
}
void XMLWriter::referToDTD(string name, string system) {
if (dtdName != "") {
cerr << "XMLWriter::ReferToDTD cannot be called twice";
}
dtdName = name;
*writer << "<!DOCTYPE " << name.c_str() << " SYSTEM \"" << system.c_str() << "\">" << endl;
}
void XMLWriter::closeDoc(bool force) {
if (!closed) {
if (!openTags.empty()) {
if (!force) cerr << "Not all tags were closed before closing XML document:" << endl;
while (!openTags.empty()) {
if (force) {
closeTag();
} else {
cerr << " </" << openTags.top().c_str() << ">" << endl;
openTags.pop();
}
}
}
closed = true;
}
}
void XMLWriter::printComment(string comment) {
if (comment.find("--") != string::npos) {
cerr << "XMLWriter::printComment '--' sequence not allowed in comment" << endl;
}
*writer << "<!--" << normalizeText(comment).c_str() << "-->" << endl;
}
void XMLWriter::printPlain(string text) {
*writer << text.c_str();
}
void XMLWriter::print(string text) {
*writer << normalizeText(text).c_str();
}
void XMLWriter::println(string text) {
print(text);
*writer << endl;
}
void XMLWriter::openTag(string name) {
checkNameValid(name);
if (openTags.empty() && dtdName.compare("") && dtdName.compare(name)) {
cerr << "XMLWriter::openTag(), First tag: '" << name << "' not equal to DTD id: '" << dtdName << "'" << endl;
}
*writer << "<" << name.c_str();
printAttributes(name.length());
*writer << ">" << endl;
writer->indent();
openTags.push(name);
}
void XMLWriter::closeTag() {
if (openTags.empty()) {
writer->close();
cerr << "XMLWriter::closeTag(), No open tags" << endl;
}
string name = openTags.top();
openTags.pop();
writer->outdent();
*writer << "</" << name.c_str() << ">" << endl;
}
void XMLWriter::printTag(string name) {
checkNameValid(name);
*writer << "<" << name.c_str();
printAttributes(name.length());
*writer << "/>" << endl;
}
void XMLWriter::setAttribute(string name, char* value) {
setAttribute(name, (string)value);
}
void XMLWriter::setAttribute(string name, string value) {
attributes[name] = value;
// NOTE: never set type here
}
void XMLWriter::setAttribute(std::string name, std::vector<double> value) {
if (name == "value") setAttribute("type", (std::string)"Color");
setAttribute(name, DefaultHepRepAttValue::getAsString(value));
}
void XMLWriter::setAttribute(std::string name, int64 value) {
if (name == "value") setAttribute("type", (std::string)"long");
setAttribute(name, DefaultHepRepAttValue::getAsString(value));
}
void XMLWriter::setAttribute(std::string name, int value) {
if (name == "showlabel") {
string label = DefaultHepRepAttValue::toShowLabel(value);
setAttribute("showlabel", label);
} else {
if (name == "value") setAttribute("type", (std::string)"int");
setAttribute(name, DefaultHepRepAttValue::getAsString(value));
}
}
void XMLWriter::setAttribute(std::string name, bool value) {
if (name == "value") setAttribute("type", (std::string)"boolean");
setAttribute(name, DefaultHepRepAttValue::getAsString(value));
}
void XMLWriter::setAttribute(string name, double value) {
if (name == "value") setAttribute("type", (std::string)"double");
setAttribute(name, DefaultHepRepAttValue::getAsString(value));
}
void XMLWriter::printAttributes(int tagLength) {
int width = tagLength + 1;
bool extraIndent = false;
for (map<string,string>::iterator i = attributes.begin(); i != attributes.end(); i++) {
string key = i->first;
checkNameValid(key);
string value = normalize(i->second);
int length = key.length() + value.length() + 3;
if (width > 0 && width + length + 2*writer->getIndent() > 60) {
width = 0;
*writer << endl;
if (!extraIndent) {
writer->indent();
extraIndent = true;
}
} else {
width += length;
*writer << " ";
}
*writer << key.c_str() << "=\"" << value.c_str() << "\"";
}
attributes.clear();
if (extraIndent) writer->outdent();
}
string XMLWriter::normalize(string s) {
string str = "";
char buffer[20];
int len = s.length();
for (int i = 0; i < len; i++) {
char ch = s[i];
switch (ch) {
case '<': {
str.append("&lt;");
break;
}
case '>': {
str.append("&gt;");
break;
}
case '&': {
str.append("&amp;");
break;
}
case '"': {
str.append("&quot;");
break;
}
case '\r':
case '\n': {
sprintf(buffer, "&#%ud", ch);
str.append(buffer);
str.append(";");
break;
}
default: {
// if (ch > 0x00FF) {
// sprintf(buffer, "&#x%4.4x", ch);
// str.append(buffer);
// str.append(";");
// } else {
str.append(&ch, 1);
// }
}
}
}
return str;
}
string XMLWriter::normalizeText(string s) {
string str = "";
int len = s.length();
for (int i = 0; i < len; i++) {
char ch = s[i];
switch (ch) {
case '<': {
str.append("&lt;");
break;
}
case '>': {
str.append("&gt;");
break;
}
case '&': {
str.append("&amp;");
break;
}
default: {
// if (ch > 0x00FF) {
// sprintf(buffer, "&#x%4.4x", ch);
// str.append(buffer);
// str.append(";");
// } else {
str.append(&ch, 1);
// }
}
}
}
return str;
}
void XMLWriter::checkNameValid(string) {
// Could be added.
// if (!XMLCharacterProperties.validName(s)) throw new RuntimeException("Invalid name: "+s);
}
} // cheprep
// Copyright FreeHEP, 2005.
#include "cheprep/config.h"
#include <cstdio>
#include "cheprep/DefaultHepRepAttValue.h"
#include "cheprep/XMLWriter.h"
using namespace std;
/**
* @author Mark Donszelmann
*/
namespace cheprep {
XMLWriter::XMLWriter(ostream* out, string indentString, string aDefaultNameSpace)
: AbstractXMLWriter(aDefaultNameSpace) {
writer = new IndentPrintWriter(out);
writer->setIndentString(indentString);
closed = false;
dtdName = "";
}
XMLWriter::~XMLWriter() {
writer->close();
delete writer;
}
void XMLWriter::close() {
closeDoc();
writer->close();
}
void XMLWriter::openDoc(string version, string encoding, bool standalone) {
string indentString = writer->getIndentString();
writer->setIndentString(indentString);
// if (!XMLCharacterProperties.validVersionNum(version)) throw new RuntimeException("Invalid version number: "+version);
*writer << "<?xml version=\"" << version.c_str() << "\" ";
if (encoding.compare("") != 0) {
// if (!XMLCharacterProperties.validEncName(encoding)) throw new RuntimeException("Invalid encoding name: "+encoding);
*writer << "encoding=\"" << encoding.c_str() << "\" ";
}
if (standalone) {
*writer << "standalone=\"yes\" ";
}
*writer << "?>";
*writer << endl;
writer->setIndentString(indentString);
}
void XMLWriter::referToDTD(string name, string pid, string ref) {
if (dtdName != "") {
cerr << "XMLWriter::ReferToDTD cannot be called twice" << endl;
}
dtdName = name;
*writer << "<!DOCTYPE " << name.c_str() << " PUBLIC \"" << pid.c_str() << "\" \"" << ref.c_str() << "\">" << endl;
}
void XMLWriter::referToDTD(string name, string system) {
if (dtdName != "") {
cerr << "XMLWriter::ReferToDTD cannot be called twice";
}
dtdName = name;
*writer << "<!DOCTYPE " << name.c_str() << " SYSTEM \"" << system.c_str() << "\">" << endl;
}
void XMLWriter::closeDoc(bool force) {
if (!closed) {
if (!openTags.empty()) {
if (!force) cerr << "Not all tags were closed before closing XML document:" << endl;
while (!openTags.empty()) {
if (force) {
closeTag();
} else {
cerr << " </" << openTags.top().c_str() << ">" << endl;
openTags.pop();
}
}
}
closed = true;
}
}
void XMLWriter::printComment(string comment) {
if (comment.find("--") != string::npos) {
cerr << "XMLWriter::printComment '--' sequence not allowed in comment" << endl;
}
*writer << "<!--" << normalizeText(comment).c_str() << "-->" << endl;
}
void XMLWriter::printPlain(string text) {
*writer << text.c_str();
}
void XMLWriter::print(string text) {
*writer << normalizeText(text).c_str();
}
void XMLWriter::println(string text) {
print(text);
*writer << endl;
}
void XMLWriter::openTag(string name) {
checkNameValid(name);
if (openTags.empty() && dtdName.compare("") && dtdName.compare(name)) {
cerr << "XMLWriter::openTag(), First tag: '" << name << "' not equal to DTD id: '" << dtdName << "'" << endl;
}
*writer << "<" << name.c_str();
printAttributes(name.length());
*writer << ">" << endl;
writer->indent();
openTags.push(name);
}
void XMLWriter::closeTag() {
if (openTags.empty()) {
writer->close();
cerr << "XMLWriter::closeTag(), No open tags" << endl;
}
string name = openTags.top();
openTags.pop();
writer->outdent();
*writer << "</" << name.c_str() << ">" << endl;
}
void XMLWriter::printTag(string name) {
checkNameValid(name);
*writer << "<" << name.c_str();
printAttributes(name.length());
*writer << "/>" << endl;
}
void XMLWriter::setAttribute(string name, char* value) {
setAttribute(name, (string)value);
}
void XMLWriter::setAttribute(string name, string value) {
attributes[name] = value;
// NOTE: never set type here
}
void XMLWriter::setAttribute(std::string name, std::vector<double> value) {
if (name == "value") setAttribute("type", (std::string)"Color");
setAttribute(name, DefaultHepRepAttValue::getAsString(value));
}
void XMLWriter::setAttribute(std::string name, int64 value) {
if (name == "value") setAttribute("type", (std::string)"long");
setAttribute(name, DefaultHepRepAttValue::getAsString(value));
}
void XMLWriter::setAttribute(std::string name, int value) {
if (name == "showlabel") {
string label = DefaultHepRepAttValue::toShowLabel(value);
setAttribute("showlabel", label);
} else {
if (name == "value") setAttribute("type", (std::string)"int");
setAttribute(name, DefaultHepRepAttValue::getAsString(value));
}
}
void XMLWriter::setAttribute(std::string name, bool value) {
if (name == "value") setAttribute("type", (std::string)"boolean");
setAttribute(name, DefaultHepRepAttValue::getAsString(value));
}
void XMLWriter::setAttribute(string name, double value) {
if (name == "value") setAttribute("type", (std::string)"double");
setAttribute(name, DefaultHepRepAttValue::getAsString(value));
}
void XMLWriter::printAttributes(int tagLength) {
int width = tagLength + 1;
bool extraIndent = false;
for (map<string,string>::iterator i = attributes.begin(); i != attributes.end(); i++) {
string key = i->first;
checkNameValid(key);
string value = normalize(i->second);
int length = key.length() + value.length() + 3;
if (width > 0 && width + length + 2*writer->getIndent() > 60) {
width = 0;
*writer << endl;
if (!extraIndent) {
writer->indent();
extraIndent = true;
}
} else {
width += length;
*writer << " ";
}
*writer << key.c_str() << "=\"" << value.c_str() << "\"";
}
attributes.clear();
if (extraIndent) writer->outdent();
}
string XMLWriter::normalize(string s) {
string str = "";
char buffer[20];
int len = s.length();
for (int i = 0; i < len; i++) {
char ch = s[i];
switch (ch) {
case '<': {
str.append("&lt;");
break;
}
case '>': {
str.append("&gt;");
break;
}
case '&': {
str.append("&amp;");
break;
}
case '"': {
str.append("&quot;");
break;
}
case '\r':
case '\n': {
sprintf(buffer, "&#%ud", ch);
str.append(buffer);
str.append(";");
break;
}
default: {
// if (ch > 0x00FF) {
// sprintf(buffer, "&#x%4.4x", ch);
// str.append(buffer);
// str.append(";");
// } else {
str.append(&ch, 1);
// }
}
}
}
return str;
}
string XMLWriter::normalizeText(string s) {
string str = "";
int len = s.length();
for (int i = 0; i < len; i++) {
char ch = s[i];
switch (ch) {
case '<': {
str.append("&lt;");
break;
}
case '>': {
str.append("&gt;");
break;
}
case '&': {
str.append("&amp;");
break;
}
default: {
// if (ch > 0x00FF) {
// sprintf(buffer, "&#x%4.4x", ch);
// str.append(buffer);
// str.append(";");
// } else {
str.append(&ch, 1);
// }
}
}
}
return str;
}
void XMLWriter::checkNameValid(string) {
// Could be added.
// if (!XMLCharacterProperties.validName(s)) throw new RuntimeException("Invalid name: "+s);
}
} // cheprep
@@ -1,44 +1,43 @@
// Copyright FreeHEP, 2005.
#include <iostream>
#include <ctime>
#include <vector>
#include "cheprep/ZipOutputStreamBuffer.h"
#include "cheprep/ZipOutputStream.h"
/**
* @author Mark Donszelmann
* @version $Id: ZipOutputStream.cc 66373 2012-12-18 09:41:34Z gcosmo $
*/
namespace cheprep {
ZipOutputStream::ZipOutputStream(std::ostream& os) : std::ostream(0) {
buffer = new ZipOutputStreamBuffer(os.rdbuf());
init(buffer);
}
void ZipOutputStream::closeEntry() {
buffer->closeEntry();
}
void ZipOutputStream::close() {
buffer->close();
}
void ZipOutputStream::putNextEntry(const std::string& name, bool compress) {
buffer->putNextEntry(name, compress);
}
void ZipOutputStream::setComment(const std::string& comment ) {
buffer->setComment(comment);
}
ZipOutputStream::~ZipOutputStream() {
close();
delete buffer;
}
} // cheprep
// Copyright FreeHEP, 2005.
#include <iostream>
#include <ctime>
#include <vector>
#include "cheprep/ZipOutputStreamBuffer.h"
#include "cheprep/ZipOutputStream.h"
/**
* @author Mark Donszelmann
*/
namespace cheprep {
ZipOutputStream::ZipOutputStream(std::ostream& os) : std::ostream(0) {
buffer = new ZipOutputStreamBuffer(os.rdbuf());
init(buffer);
}
void ZipOutputStream::closeEntry() {
buffer->closeEntry();
}
void ZipOutputStream::close() {
buffer->close();
}
void ZipOutputStream::putNextEntry(const std::string& name, bool compress) {
buffer->putNextEntry(name, compress);
}
void ZipOutputStream::setComment(const std::string& comment ) {
buffer->setComment(comment);
}
ZipOutputStream::~ZipOutputStream() {
close();
delete buffer;
}
} // cheprep
@@ -1,144 +1,143 @@
// Copyright FreeHEP, 2005.
#include <iostream>
#include <ctime>
#include <vector>
#include "cheprep/ZipOutputStream.h"
#include "cheprep/ZipOutputStreamBuffer.h"
#include "cheprep/ZipEntry.h"
/**
* @author Mark Donszelmann
* @version $Id: ZipOutputStreamBuffer.cc 66373 2012-12-18 09:41:34Z gcosmo $
*/
namespace cheprep {
ZipOutputStreamBuffer::ZipOutputStreamBuffer(std::streambuf* aBuffer)
: DeflateOutputStreamBuffer(aBuffer),
comment("") {
closed = false;
entry = NULL;
entries = new std::vector<ZipEntry*>();
}
int ZipOutputStreamBuffer::overflow(int c) {
return DeflateOutputStreamBuffer::overflow(c);
}
void ZipOutputStreamBuffer::closeEntry() {
if (closed) return;
if (entry == NULL) return;
finish();
entry->crc = getCRC();
// NOTE: pos()::operator- is ambiguous on gcc 4.0, so convert to long first
entry->csize = (long)pos() - entry->data;
entry->size = getSize();
putUI(EXTSIG);
putUI(entry->crc); // crc
putUI(entry->csize); // compressed size
putUI(entry->size); // uncompressed size
entry = NULL;
}
void ZipOutputStreamBuffer::close() {
if (closed) return;
closeEntry();
long dirStart = pos();
for (std::vector<ZipEntry*>::iterator i=entries->begin(); i != entries->end(); i++) {
entry = *i;
putUI(CENSIG);
putUS(VERSIONMADE); // made by version
putUS(VERSIONEXTRACT); // extraction version
putUS(GENFLAG); // general purpose bit flag
putUS(entry->method); // compression method
putUS(entry->time); // time
putUS(entry->date); // date
putUI(entry->crc); // crc
putUI(entry->csize); // compressed size
putUI(entry->size); // uncompressed size
putUS(entry->name.length()); // file name length
putUS(0); // extra field length
putUS(0); // file comment length
putUS(0); // disk number start
putUS(0); // internal file attributes
putUI(0); // external file attributes
putUI(entry->offset); // relative offset of local file header
putS(entry->name); // file name
// delete entry
delete entry;
entry = NULL;
}
// NOTE: pos()::operator- is ambiguous on gcc 4.0, so convert to long first
long dirSize = (long)pos() - dirStart;
putUI(ENDSIG);
putUS(0); // number of this disk
putUS(0); // number of the disk with the start of central directory
putUS(entries->size()); // total number of entries in the central directory of this disk
putUS(entries->size()); // total number of entries in the central directory
putUI(dirSize); // size of the central directory
putUI(dirStart); // offset of the start of central directory with respect to the starting disk number
putUS(comment.length()); // .ZIP file comment length
putS(comment); // .ZIP file comment
delete entries;
entries = NULL;
closed = true;
}
void ZipOutputStreamBuffer::putNextEntry(const std::string& name, bool compress) {
if (closed) return;
closeEntry();
#ifdef CHEPREP_NO_ZLIB
compress = false;
#endif
init(compress);
entry = new ZipEntry();
entries->push_back(entry);
entry->name = name;
entry->method = compress ? 8 : 0;
time_t ltime;
time( &ltime );
struct tm *utc = gmtime( &ltime );
entry->date = (utc->tm_year - 80) << 9 | (utc->tm_mon + 1) << 5 | utc->tm_mday;
entry->time = utc->tm_hour << 11 | utc->tm_min << 5 | utc->tm_sec >> 1;
entry->offset = (long)pos();
putUI(LOCSIG); // signature
putUS(VERSIONEXTRACT); // extraction version
putUS(GENFLAG); // general purpose bit flag
putUS(entry->method); // compression method
putUS(entry->time); // time
putUS(entry->date); // date
putUI(0x00000000); // crc ATEND
putUI(0x00000000); // compressed size ATEND
putUI(0x00000000); // uncompressed size ATEND
putUS(entry->name.length()); // file name length
putUS(0); // extra field length
putS(entry->name); // file name
entry->data = (long)pos();
entry->crc = 0;
}
void ZipOutputStreamBuffer::setComment(const std::string& c) {
if (closed) return;
comment = c;
}
ZipOutputStreamBuffer::~ZipOutputStreamBuffer() {
close();
}
} // cheprep
// Copyright FreeHEP, 2005.
#include <iostream>
#include <ctime>
#include <vector>
#include "cheprep/ZipOutputStream.h"
#include "cheprep/ZipOutputStreamBuffer.h"
#include "cheprep/ZipEntry.h"
/**
* @author Mark Donszelmann
*/
namespace cheprep {
ZipOutputStreamBuffer::ZipOutputStreamBuffer(std::streambuf* aBuffer)
: DeflateOutputStreamBuffer(aBuffer),
comment("") {
closed = false;
entry = NULL;
entries = new std::vector<ZipEntry*>();
}
int ZipOutputStreamBuffer::overflow(int c) {
return DeflateOutputStreamBuffer::overflow(c);
}
void ZipOutputStreamBuffer::closeEntry() {
if (closed) return;
if (entry == NULL) return;
finish();
entry->crc = getCRC();
// NOTE: pos()::operator- is ambiguous on gcc 4.0, so convert to long first
entry->csize = (long)pos() - entry->data;
entry->size = getSize();
putUI(EXTSIG);
putUI(entry->crc); // crc
putUI(entry->csize); // compressed size
putUI(entry->size); // uncompressed size
entry = NULL;
}
void ZipOutputStreamBuffer::close() {
if (closed) return;
closeEntry();
long dirStart = pos();
for (std::vector<ZipEntry*>::iterator i=entries->begin(); i != entries->end(); i++) {
entry = *i;
putUI(CENSIG);
putUS(VERSIONMADE); // made by version
putUS(VERSIONEXTRACT); // extraction version
putUS(GENFLAG); // general purpose bit flag
putUS(entry->method); // compression method
putUS(entry->time); // time
putUS(entry->date); // date
putUI(entry->crc); // crc
putUI(entry->csize); // compressed size
putUI(entry->size); // uncompressed size
putUS(entry->name.length()); // file name length
putUS(0); // extra field length
putUS(0); // file comment length
putUS(0); // disk number start
putUS(0); // internal file attributes
putUI(0); // external file attributes
putUI(entry->offset); // relative offset of local file header
putS(entry->name); // file name
// delete entry
delete entry;
entry = NULL;
}
// NOTE: pos()::operator- is ambiguous on gcc 4.0, so convert to long first
long dirSize = (long)pos() - dirStart;
putUI(ENDSIG);
putUS(0); // number of this disk
putUS(0); // number of the disk with the start of central directory
putUS(entries->size()); // total number of entries in the central directory of this disk
putUS(entries->size()); // total number of entries in the central directory
putUI(dirSize); // size of the central directory
putUI(dirStart); // offset of the start of central directory with respect to the starting disk number
putUS(comment.length()); // .ZIP file comment length
putS(comment); // .ZIP file comment
delete entries;
entries = NULL;
closed = true;
}
void ZipOutputStreamBuffer::putNextEntry(const std::string& name, bool compress) {
if (closed) return;
closeEntry();
#ifdef CHEPREP_NO_ZLIB
compress = false;
#endif
init(compress);
entry = new ZipEntry();
entries->push_back(entry);
entry->name = name;
entry->method = compress ? 8 : 0;
time_t ltime;
time( &ltime );
struct tm *utc = gmtime( &ltime );
entry->date = (utc->tm_year - 80) << 9 | (utc->tm_mon + 1) << 5 | utc->tm_mday;
entry->time = utc->tm_hour << 11 | utc->tm_min << 5 | utc->tm_sec >> 1;
entry->offset = (long)pos();
putUI(LOCSIG); // signature
putUS(VERSIONEXTRACT); // extraction version
putUS(GENFLAG); // general purpose bit flag
putUS(entry->method); // compression method
putUS(entry->time); // time
putUS(entry->date); // date
putUI(0x00000000); // crc ATEND
putUI(0x00000000); // compressed size ATEND
putUI(0x00000000); // uncompressed size ATEND
putUS(entry->name.length()); // file name length
putUS(0); // extra field length
putS(entry->name); // file name
entry->data = (long)pos();
entry->crc = 0;
}
void ZipOutputStreamBuffer::setComment(const std::string& c) {
if (closed) return;
comment = c;
}
ZipOutputStreamBuffer::~ZipOutputStreamBuffer() {
close();
}
} // cheprep