123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #ifndef HDF4CPP_HDFOBJECT_H
- #define HDF4CPP_HDFOBJECT_H
- #include <hdf4cpp/HdfDefines.h>
- #include <hdf4cpp/HdfException.h>
- #include <functional>
- #include <memory>
- #include <vector>
- namespace hdf4cpp {
- class HdfObject {
- protected:
-
- class HdfDestroyer {
- public:
- HdfDestroyer(const std::function<int32(int32)> &endFunction, int32 id)
- : endFunction(endFunction)
- , id(id) {
- }
- ~HdfDestroyer() {
- endFunction(id);
- }
- private:
- std::function<int32(int32)> endFunction;
- int32 id;
- };
-
-
-
-
- class HdfDestroyerChain {
- public:
- HdfDestroyerChain() {
- }
- HdfDestroyerChain(const HdfDestroyerChain &other)
- : chain(other.chain) {
- }
- void pushBack(HdfDestroyer *destroyer) {
- chain.push_back(std::shared_ptr<HdfDestroyer>(destroyer));
- }
- private:
- std::vector<std::shared_ptr<HdfDestroyer>> chain;
- };
- public:
-
- virtual Type getType() const {
- return type;
- }
-
- virtual ClassType getClassType() const {
- return classType;
- }
- protected:
- HdfObject(const Type &type, const ClassType &classType, const HdfDestroyerChain &chain = HdfDestroyerChain())
- : type(type)
- , classType(classType)
- , chain(chain) {
- }
- HdfObject(const HdfObject *object)
- : type(object->getType())
- , classType(object->getClassType())
- , chain(object->chain) {
- }
- virtual void setType(const Type &type) {
- this->type = type;
- }
- virtual void setClassType(const ClassType &classType) {
- this->classType = classType;
- }
-
- virtual void raiseException(const ExceptionType &exceptionType) const {
- throw HdfException(type, classType, exceptionType);
- }
-
- virtual void raiseException(const std::string &message) const {
- throw HdfException(type, classType, message);
- }
- private:
-
- Type type;
-
- ClassType classType;
- protected:
-
- HdfDestroyerChain chain;
- };
- }
- #endif
|