[Kst] branches/work/kst/portto4/kst/src/libkst
Peter Kümmel
syntheticpp at yahoo.com
Tue Apr 27 22:25:14 CEST 2010
SVN commit 1119852 by kuemmel:
remove circular include dependency (DataSources is needed by DataPrimitive, but DataSource needs DataVector & Co. which inherit from DataPrimitive)
M +27 -8 dataprimitive.cpp
M +6 -1 dataprimitive.h
M +24 -25 datascalar.cpp
M +24 -28 datastring.cpp
M +45 -46 datavector.cpp
--- branches/work/kst/portto4/kst/src/libkst/dataprimitive.cpp #1119851:1119852
@@ -22,24 +22,35 @@
namespace Kst {
-DataPrimitive::DataPrimitive()
+
+struct DataPrimitive::Private
{
- _file = 0L;
+ DataSourcePtr _file;
+};
+
+
+
+DataPrimitive::DataPrimitive() : d(*new Private)
+{
+ d._file = 0;
+ _field = QString::null;
}
DataPrimitive::~DataPrimitive() {
- _file = 0;
+ _field = QString::null;
+ d._file = 0;
+ delete &d;
}
/** return the name of the file */
QString DataPrimitive::filename() const {
QString rc;
- if (_file) {
- _file->readLock();
- rc = _file->fileName();
- _file->unlock();
+ if (d._file) {
+ d._file->readLock();
+ rc = d._file->fileName();
+ d._file->unlock();
}
return rc;
}
@@ -52,7 +63,15 @@
DataSourcePtr DataPrimitive::dataSource() const {
- return _file;
+ return d._file;
}
+DataSourcePtr& DataPrimitive::file() {
+ return d._file;
}
+
+DataSourcePtr& DataPrimitive::file() const {
+ return d._file;
+}
+
+}
--- branches/work/kst/portto4/kst/src/libkst/dataprimitive.h #1119851:1119852
@@ -55,11 +55,16 @@
protected:
/** file to read for rvectors */
- DataSource* _file;
+ DataSourcePtr& file();
+ DataSourcePtr& file() const;
/** For the scalar field in the data source */
QString _field;
+ private:
+ struct Private;
+ Private& d;
+
};
typedef SharedPtr<DataPrimitive> DataPrimitivePtr;
--- branches/work/kst/portto4/kst/src/libkst/datascalar.cpp #1119851:1119852
@@ -39,7 +39,6 @@
DataScalar::~DataScalar() {
- _file = 0;
}
@@ -56,10 +55,10 @@
/** return true if it has a valid file and field, or false otherwise */
bool DataScalar::isValid() const {
- if (_file) {
- _file->readLock();
- bool rc = _file->scalar().isValid(_field);
- _file->unlock();
+ if (file()) {
+ file()->readLock();
+ bool rc = file()->scalar().isValid(_field);
+ file()->unlock();
return rc;
}
return false;
@@ -69,7 +68,7 @@
Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
_field = in_field;
- _file = in_file;
+ file() = in_file;
}
void DataScalar::changeFile(DataSourcePtr in_file) {
@@ -78,17 +77,17 @@
if (!in_file) {
Debug::self()->log(i18n("Data file for scalar %1 was not opened.", Name()), Debug::Warning);
}
- _file = in_file;
+ file() = in_file;
}
/** Save data scalar information */
void DataScalar::save(QXmlStreamWriter &s) {
- if (_file) {
+ if (file()) {
s.writeStartElement("datascalar");
- _file->readLock();
- s.writeAttribute("file", _file->fileName());
- _file->unlock();
+ file()->readLock();
+ s.writeAttribute("file", file()->fileName());
+ file()->unlock();
s.writeAttribute("field", _field);
saveNameInfo(s, XNUM);
@@ -99,10 +98,10 @@
/** Update a data Scalar */
void DataScalar::internalUpdate() {
- if (_file) {
- _file->writeLock();
- _file->scalar().read(_field, Param(&_value));
- _file->unlock();
+ if (file()) {
+ file()->writeLock();
+ file()->scalar().read(_field, Param(&_value));
+ file()->unlock();
}
}
@@ -112,7 +111,7 @@
DataScalarPtr scalar = store()->createObject<DataScalar>();
scalar->writeLock();
- scalar->change(_file, _field);
+ scalar->change(file(), _field);
if (descriptiveNameIsManual()) {
scalar->setDescriptiveName(descriptiveName());
}
@@ -124,15 +123,15 @@
}
qint64 DataScalar::minInputSerial() const {
- if (_file) {
- return (_file->serial());
+ if (file()) {
+ return (file()->serial());
}
return LLONG_MAX;
}
qint64 DataScalar::minInputSerialOfLastChange() const {
- if (_file) {
- return (_file->serialOfLastChange());
+ if (file()) {
+ return (file()->serialOfLastChange());
}
return LLONG_MAX;
}
@@ -156,17 +155,17 @@
void DataScalar::reload() {
Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
- if (_file) {
- _file->writeLock();
- _file->reset();
- _file->unlock();
+ if (file()) {
+ file()->writeLock();
+ file()->reset();
+ file()->unlock();
reset();
registerChange();
}
}
void DataScalar::reset() {
- _file->scalar().read(_field, Param(&_value));
+ file()->scalar().read(_field, Param(&_value));
}
}
--- branches/work/kst/portto4/kst/src/libkst/datastring.cpp #1119851:1119852
@@ -32,15 +32,11 @@
DataString::DataString(ObjectStore *store)
: String(store), DataPrimitive() {
- _file = 0L;
- _field = QString::null;
-
setOrphan(true);
}
DataString::~DataString() {
- _file = 0;
}
@@ -57,10 +53,10 @@
/** return true if it has a valid file and field, or false otherwise */
bool DataString::isValid() const {
- if (_file) {
- _file->readLock();
- bool rc = _file->string().isValid(_field);
- _file->unlock();
+ if (file()) {
+ file()->readLock();
+ bool rc = file()->string().isValid(_field);
+ file()->unlock();
return rc;
}
return false;
@@ -70,7 +66,7 @@
Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
_field = in_field;
- _file = in_file;
+ file() = in_file;
}
void DataString::changeFile(DataSourcePtr in_file) {
@@ -79,17 +75,17 @@
if (!in_file) {
Debug::self()->log(i18n("Data file for string %1 was not opened.", Name()), Debug::Warning);
}
- _file = in_file;
+ file() = in_file;
}
/** Save data string information */
void DataString::save(QXmlStreamWriter &s) {
- if (_file) {
+ if (file()) {
s.writeStartElement("datastring");
- _file->readLock();
- s.writeAttribute("file", _file->fileName());
- _file->unlock();
+ file()->readLock();
+ s.writeAttribute("file", file()->fileName());
+ file()->unlock();
s.writeAttribute("field", _field);
saveNameInfo(s, XNUM);
@@ -100,23 +96,23 @@
/** Update a data String */
void DataString::internalUpdate() {
- if (_file) {
- _file->writeLock();
- _file->string().read(_field, Param(&_value));
- _file->unlock();
+ if (file()) {
+ file()->writeLock();
+ file()->string().read(_field, Param(&_value));
+ file()->unlock();
}
}
qint64 DataString::minInputSerial() const {
- if (_file) {
- return (_file->serial());
+ if (file()) {
+ return (file()->serial());
}
return LLONG_MAX;
}
qint64 DataString::minInputSerialOfLastChange() const {
- if (_file) {
- return (_file->serialOfLastChange());
+ if (file()) {
+ return (file()->serialOfLastChange());
}
return LLONG_MAX;
}
@@ -128,7 +124,7 @@
DataStringPtr string = store()->createObject<DataString>();
string->writeLock();
- string->change(_file, _field);
+ string->change(file(), _field);
if (descriptiveNameIsManual()) {
string->setDescriptiveName(descriptiveName());
}
@@ -159,17 +155,17 @@
void DataString::reload() {
Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
- if (_file) {
- _file->writeLock();
- _file->reset();
- _file->unlock();
+ if (file()) {
+ file()->writeLock();
+ file()->reset();
+ file()->unlock();
reset();
registerChange();
}
}
void DataString::reset() {
- _file->string().read(_field, Param(&_value));
+ file()->string().read(_field, Param(&_value));
}
}
--- branches/work/kst/portto4/kst/src/libkst/datavector.cpp #1119851:1119852
@@ -76,7 +76,6 @@
N_AveReadBuf = 0;
AveReadBuf = 0L;
- _file = 0L;
ReqF0 = 0;
ReqNF = -1;
Skip = 1;
@@ -93,10 +92,10 @@
/** return true if it has a valid file and field, or false otherwise */
bool DataVector::isValid() const {
- if (_file) {
- _file->readLock();
- bool rc = _file->vector().isValid(_field);
- _file->unlock();
+ if (file()) {
+ file()->readLock();
+ bool rc = file()->vector().isValid(_field);
+ file()->unlock();
return rc;
}
return false;
@@ -117,18 +116,18 @@
}
_dontUseSkipAccel = false;
- _file = in_file;
+ file() = in_file;
ReqF0 = in_f0;
ReqNF = in_n;
_field = in_field;
- if (_file) {
- _file->writeLock();
+ if (file()) {
+ file()->writeLock();
}
reset();
_resetFieldMetadata();
- if (_file) {
- _file->unlock();
+ if (file()) {
+ file()->unlock();
}
if (ReqNF <= 0 && ReqF0 < 0) {
@@ -137,15 +136,15 @@
}
qint64 DataVector::minInputSerial() const {
- if (_file) {
- return (_file->serial());
+ if (file()) {
+ return (file()->serial());
}
return LLONG_MAX;
}
qint64 DataVector::minInputSerialOfLastChange() const {
- if (_file) {
- return (_file->serialOfLastChange());
+ if (file()) {
+ return (file()->serialOfLastChange());
}
return LLONG_MAX;
}
@@ -157,13 +156,13 @@
if (!in_file) {
Debug::self()->log(i18n("Data file for vector %1 was not opened.", Name()), Debug::Warning);
}
- _file = in_file;
- if (_file) {
- _file->writeLock();
+ file() = in_file;
+ if (file()) {
+ file()->writeLock();
}
reset();
- if (_file) {
- _file->unlock();
+ if (file()) {
+ file()->unlock();
}
registerChange();
}
@@ -174,12 +173,12 @@
bool in_DoAve) {
Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
- if (_file) {
- _file->writeLock();
+ if (file()) {
+ file()->writeLock();
}
reset();
- if (_file) {
- _file->unlock();
+ if (file()) {
+ file()->unlock();
}
Skip = in_skip;
DoSkip = in_DoSkip;
@@ -211,7 +210,7 @@
DataVector::~DataVector() {
- _file = 0;
+ file() = 0;
if (AveReadBuf) {
free(AveReadBuf);
@@ -270,11 +269,11 @@
/** Save vector information */
void DataVector::save(QXmlStreamWriter &s) {
- if (_file) {
+ if (file()) {
s.writeStartElement("datavector");
- _file->readLock();
- s.writeAttribute("file", _file->fileName());
- _file->unlock();
+ file()->readLock();
+ s.writeAttribute("file", file()->fileName());
+ file()->unlock();
s.writeAttribute("field", _field);
s.writeAttribute("start", QString::number(ReqF0));
@@ -323,7 +322,7 @@
Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
_dontUseSkipAccel = false;
- if (_file) {
+ if (file()) {
SPF = opt(_field).samplesPerFrame;
}
F0 = NF = 0;
@@ -347,7 +346,7 @@
// if it looks like we have a new file, reset
const Optional op = opt(_field);
- if (_file && (SPF != op.samplesPerFrame || op.frameCount < NF)) {
+ if (file() && (SPF != op.samplesPerFrame || op.frameCount < NF)) {
reset();
}
@@ -389,8 +388,8 @@
int new_f0, new_nf;
bool start_past_eof = false;
- if (_file) {
- _file->writeLock();
+ if (file()) {
+ file()->writeLock();
} else {
return;
}
@@ -573,8 +572,8 @@
NumShifted = _size;
}
- if (_file) {
- _file->unlock();
+ if (file()) {
+ file()->unlock();
}
Vector::internalUpdate();
@@ -589,7 +588,7 @@
int DataVector::fileLength() const {
- if (_file) {
+ if (file()) {
int rc = opt(_field).frameCount;
return rc;
@@ -602,10 +601,10 @@
void DataVector::reload() {
Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
- if (_file) {
- _file->writeLock();
- _file->reset();
- _file->unlock();
+ if (file()) {
+ file()->writeLock();
+ file()->reset();
+ file()->unlock();
reset();
_resetFieldMetadata();
registerChange();
@@ -621,7 +620,7 @@
// Note: this does not necessarily preserve order if the
// datasource or field have been changed. If dynamic
// fieldScalars are ever wanted, this should be fixed.
- const QMap<QString, QString> meta_strings = _file->vector().metaStrings(_field);
+ const QMap<QString, QString> meta_strings = file()->vector().metaStrings(_field);
QStringList fieldStringKeys = _fieldStrings.keys();
@@ -661,7 +660,7 @@
// Note: this does not necessarily preseve order if the
// datasource or field have been changed. If dynamic
// fieldScalars are ever wanted, this should be fixed.
- const QMap<QString, double> meta_scalars = _file->vector().metaScalars(_field);
+ const QMap<QString, double> meta_scalars = file()->vector().metaScalars(_field);
QStringList fieldScalarKeys = _fieldScalars.keys();
@@ -702,7 +701,7 @@
DataVectorPtr vector = store()->createObject<DataVector>();
vector->writeLock();
- vector->change(_file, _field, ReqF0, ReqNF, Skip, DoSkip, DoAve);
+ vector->change(file(), _field, ReqF0, ReqNF, Skip, DoSkip, DoAve);
if (descriptiveNameIsManual()) {
vector->setDescriptiveName(descriptiveName());
}
@@ -754,14 +753,14 @@
int DataVector::readField(double *v, const QString& field, int s, int n, int skip, int *lastFrameRead)
{
const Param par = {v, s, n, skip, lastFrameRead};
- return _file->vector().read(field, par);
+ return file()->vector().read(field, par);
}
const DataVector::Optional DataVector::opt(const QString& field) const
{
- _file->readLock();
- const Optional op = _file->vector().optional(field);
- _file->unlock();
+ file()->readLock();
+ const Optional op = file()->vector().optional(field);
+ file()->unlock();
return op;
}
More information about the Kst
mailing list