All classes are now either safe to copy or are marked noncopyable.
+#include <stdexcept>
#include "argumentstore.h"
+using namespace std;
+
namespace Msp {
namespace DataFile {
}
}
+ArgumentStore::ArgumentStore(const ArgumentStore &other):
+ info(other.info),
+ store(new char[info.args_size])
+{
+ copy_from(other.store);
+}
+
+ArgumentStore &ArgumentStore::operator=(const ArgumentStore &other)
+{
+ if(&other.info!=&info)
+ throw invalid_argument("ArgumentStore::operator=");
+
+ destroy();
+ copy_from(other.store);
+
+ return *this;
+}
+
ArgumentStore::~ArgumentStore()
+{
+ destroy();
+}
+
+void ArgumentStore::destroy()
{
for(unsigned i=0; i<info.key.signature.size(); ++i)
switch(info.key.signature[i])
delete[] store;
}
+void ArgumentStore::copy_from(const char *other)
+{
+ for(unsigned i=0; i<info.key.signature.size(); ++i)
+ switch(info.key.signature[i])
+ {
+ case StringType::signature:
+ new(store+info.arg_offsets[i]) StringType::Store(*reinterpret_cast<const StringType::Store *>(other+info.arg_offsets[i]));
+ break;
+ case SymbolType::signature:
+ new(store+info.arg_offsets[i]) SymbolType::Store(*reinterpret_cast<const SymbolType::Store *>(other+info.arg_offsets[i]));
+ break;
+ default:
+ copy(other+info.arg_offsets[i], other+(i+1<info.arg_offsets.size() ? info.arg_offsets[i+1] : info.args_size), store+info.arg_offsets[i]);
+ break;
+ }
+}
+
} // namespace DataFile
} // namespace Msp
public:
ArgumentStore(const StatementInfo &);
+ ArgumentStore(const ArgumentStore &);
+ ArgumentStore &operator=(const ArgumentStore &);
~ArgumentStore();
+private:
+ void destroy();
+ void copy_from(const char *);
+public:
const StatementInfo &get_info() const { return info; }
template<typename T>
#include <msp/core/attributes.h>
#include <msp/core/maputils.h>
+#include <msp/core/noncopyable.h>
#include <msp/core/refptr.h>
#include "collectionsource.h"
#include "loader.h"
between the collections, and are only deleted when all collections in the chain
have been destroyed.
*/
-class Collection
+class Collection: private NonCopyable
{
public:
/**
SourceList sources;
Collection *fallback;
- Collection(const Collection &);
- Collection &operator=(const Collection &);
public:
Collection();
virtual ~Collection();
#ifndef MSP_DATAFILE_INPUT_H_
#define MSP_DATAFILE_INPUT_H_
+#include <msp/core/noncopyable.h>
#include <msp/io/base.h>
namespace Msp {
namespace DataFile {
-class Input
+class Input: private NonCopyable
{
private:
IO::Base *in;
handle the actual adding of keywords.
*/
template<typename L, template<typename> class A>
-class LoadableTypeRegistry: public NonCopyable
+class LoadableTypeRegistry: private NonCopyable
{
private:
class TypeBase
See also classes ObjectLoader and CollectionObjectLoader in objectloader.h.
*/
-class Loader
+class Loader: private NonCopyable
{
protected:
typedef std::map<StatementKey, LoaderAction *> ActionMap;
#ifndef MSP_DATAFILE_OUTPUT_H_
#define MSP_DATAFILE_OUTPUT_H_
+#include <msp/core/noncopyable.h>
#include <msp/io/base.h>
namespace Msp {
namespace DataFile {
-class Output
+class Output: private NonCopyable
{
private:
IO::Base *out;
namespace Msp {
namespace DataFile {
+PackSource::PackSource(const PackSource &other):
+ packs(other.packs),
+ files(other.files),
+ objects(other.objects)
+{
+ translate_maps(other);
+}
+
+PackSource &PackSource::operator=(const PackSource &other)
+{
+ packs = list<Pack>(other.packs.begin(), other.packs.end());
+ files = other.files;
+ objects = other.objects;
+ translate_maps(other);
+ return *this;
+}
+
+void PackSource::translate_maps(const PackSource &other)
+{
+ for(list<Pack>::const_iterator i=packs.begin(), j=other.packs.begin(); (i!=packs.end() && j!=other.packs.end()); ++i, ++j)
+ i->translate_files(files, *j);
+ for(FileMap::const_iterator i=files.begin(), j=other.files.begin(); (i!=files.end() && j!=other.files.end()); ++i, ++j)
+ i->second->translate_objects(objects, *j->second);
+}
+
void PackSource::add_pack_file(const string &fn)
{
add_pack_file(fn, string());
base_offset(0)
{ }
+PackSource::Pack::Pack(const Pack &other):
+ filename(other.filename),
+ io(other.io),
+ base_offset(other.base_offset)
+{
+ for(list<File>::const_iterator i=other.files.begin(); i!=other.files.end(); ++i)
+ files.push_back(File(*i, *this));
+}
+
void PackSource::Pack::collect_files(FileMap &fm, const string &filter) const
{
if(filter.empty())
}
}
+void PackSource::Pack::translate_files(FileMap &fm, const Pack &source) const
+{
+ for(list<File>::const_iterator i=files.begin(), j=source.files.begin(); (i!=files.end() && j!=source.files.end()); ++i, ++j)
+ {
+ FileMap::iterator k = fm.find(i->get_filename());
+ if(k!=fm.end() && k->second==&*j)
+ k->second = &*i;
+ }
+}
+
PackSource::File::File(const Pack &p, const string &fn):
pack(p),
collection(false)
{ }
+PackSource::File::File(const File &other, const Pack &p):
+ pack(p),
+ filename(other.filename),
+ offset(other.offset),
+ length(other.length),
+ collection(other.collection)
+{
+ for(list<Object>::const_iterator i=other.objects.begin(); i!=other.objects.end(); ++i)
+ objects.push_back(Object(*i, *this));
+}
+
RefPtr<IO::Seekable> PackSource::File::open() const
{
if(pack.get_io())
objs[i->get_name()] = &*i;
}
+void PackSource::File::translate_objects(ObjectMap &objs, const File &source) const
+{
+ for(list<Object>::const_iterator i=objects.begin(), j=source.objects.begin(); (i!=objects.end() && j!=source.objects.end()); ++i, ++j)
+ {
+ ObjectMap::iterator k = objs.find(i->get_name());
+ if(k!=objs.end() && k->second==&*j)
+ k->second = &*i;
+ }
+}
+
PackSource::Object::Object(const File &f, const string &n, const string &k):
file(f),
keyword(k)
{ }
+PackSource::Object::Object(const Object &other, const File &f):
+ file(f),
+ name(other.name),
+ keyword(other.keyword)
+{ }
+
PackSource::Pack::Loader::Loader(Pack &p):
ObjectLoader<Pack>(p)
#ifndef MSP_DATAFILE_PACKSOURCE_H_
#define MSP_DATAFILE_PACKSOURCE_H_
+#include <msp/core/noncopyable.h>
#include <msp/core/refptr.h>
#include "collectionsource.h"
#include "objectloader.h"
public:
Pack(IO::Seekable *, const std::string &);
+ Pack(const Pack &);
const std::string &get_filename() const { return filename; }
IO::Seekable *get_io() const { return io; }
IO::SeekOffset get_base_offset() const { return base_offset; }
void collect_files(FileMap &, const std::string &) const;
+ void translate_files(FileMap &, const Pack &) const;
};
class File
public:
File(const Pack &, const std::string &);
+ File(const File &, const Pack &);
RefPtr<IO::Seekable> open() const;
const std::string &get_filename() const { return filename; }
bool is_collection() const { return collection; }
void collect_objects(ObjectMap &) const;
+ void translate_objects(ObjectMap &, const File &) const;
};
class Object
public:
Object(const File &, const std::string &, const std::string &);
+ Object(const Object &, const File &);
const File &get_file() const { return file; }
const std::string &get_name() const { return name; }
FileMap files;
ObjectMap objects;
+public:
+ PackSource() { }
+ PackSource(const PackSource &);
+ PackSource &operator=(const PackSource &);
+private:
+ void translate_maps(const PackSource &);
+
public:
/// Adds a pack file to load objects from. The index is read immediately.
void add_pack_file(const std::string &);
#define MSP_DATAFILE_PARSER_H_
#include <string>
+#include <msp/core/noncopyable.h>
#include "input.h"
namespace Msp {
formats. A Parser evaluates into a boolean value indicating whether more
statements may be read.
*/
-class Parser
+class Parser: private NonCopyable
{
private:
Input in;
#ifndef MSP_DATAFILE_PARSERMODE_H_
#define MSP_DATAFILE_PARSERMODE_H_
+#include <msp/core/noncopyable.h>
#include "statement.h"
namespace Msp {
/**
Base class for parse modes.
*/
-class ParserMode
+class ParserMode: private NonCopyable
{
protected:
Input ∈
#define MSP_DATAFILE_WRITER_H_
#include <map>
+#include <msp/core/noncopyable.h>
#include <msp/io/base.h>
#include "output.h"
/**
Frontend for writing data.
*/
-class Writer
+class Writer: private NonCopyable
{
private:
Output out;
#ifndef MSP_DATAFILE_WRITERMODE_H_
#define MSP_DATAFILE_WRITERMODE_H_
+#include <msp/core/noncopyable.h>
+
namespace Msp {
namespace DataFile {
class Output;
class Statement;
-class WriterMode
+class WriterMode: private NonCopyable
{
protected:
Output &out;