mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 17:54:00 +02:00
Create SimpleFormat
This commit is contained in:
parent
39d1a2be6f
commit
2178baf1a8
2 changed files with 82 additions and 0 deletions
35
libraries/hfm/src/hfm/HFMSimpleFormat.cpp
Normal file
35
libraries/hfm/src/hfm/HFMSimpleFormat.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
//
|
||||
// HFMSimpleFormat.cpp
|
||||
// libraries/hfm/src/hfm
|
||||
//
|
||||
// Created by Sabrina Shanman on 2018/11/30.
|
||||
// Copyright 2018 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "HFMSimpleFormat.h"
|
||||
|
||||
namespace hfm {
|
||||
template<typename T>
|
||||
std::shared_ptr<Serializer> SimpleFactory<T>::get() {
|
||||
return std::make_shared<T>();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
SimpleFormat<T>::SimpleFormat(const MIMEType& mimeType) : Format(),
|
||||
_mimeType(mimeType) {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void SimpleFormat<T>::registerFormat(FormatRegistry& registry) {
|
||||
_mimeTypeID = registry.registerMIMEType(_mimeType, std::make_shared<SimpleFactory<T>>());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void SimpleFormat<T>::unregisterFormat(FormatRegistry& registry) {
|
||||
registry.unregisterMIMEType(_mimeTypeID);
|
||||
_mimeTypeID = hfm::FormatRegistry::INVALID_MIME_TYPE_ID;
|
||||
}
|
||||
};
|
47
libraries/hfm/src/hfm/HFMSimpleFormat.h
Normal file
47
libraries/hfm/src/hfm/HFMSimpleFormat.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
//
|
||||
// HFMSimpleFormat.h
|
||||
// libraries/hfm/src/hfm
|
||||
//
|
||||
// Created by Sabrina Shanman on 2018/11/30.
|
||||
// Copyright 2018 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_HFMSimpleFormat_h
|
||||
#define hifi_HFMSimpleFormat_h
|
||||
|
||||
#include "HFMFormat.h"
|
||||
#include "HFMSerializer.h"
|
||||
|
||||
namespace hfm {
|
||||
template<typename T>
|
||||
class SimpleFactory : public Serializer::Factory {
|
||||
std::shared_ptr<Serializer> get() override {
|
||||
return std::make_shared<T>();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T> // T is an implementation of hfm::Serializer
|
||||
class SimpleFormat : public Format {
|
||||
public:
|
||||
SimpleFormat(const MIMEType& mimeType) : Format(),
|
||||
_mimeType(mimeType) {
|
||||
}
|
||||
|
||||
void registerFormat(FormatRegistry& registry) override {
|
||||
_mimeTypeID = registry.registerMIMEType(_mimeType, std::make_unique<SimpleFactory<T>>());
|
||||
}
|
||||
|
||||
void unregisterFormat(FormatRegistry& registry) override {
|
||||
registry.unregisterMIMEType(_mimeTypeID);
|
||||
_mimeTypeID = hfm::FormatRegistry::INVALID_MIME_TYPE_ID;
|
||||
}
|
||||
protected:
|
||||
MIMEType _mimeType;
|
||||
hfm::FormatRegistry::MIMETypeID _mimeTypeID;
|
||||
};
|
||||
};
|
||||
|
||||
#endif // hifi_HFMSimpleFormat_h
|
Loading…
Reference in a new issue