DataControlFile.hh 4.21 KB
Newer Older
1
2
3
4
5
/***********************************************************************
 * Copyright 2011-2012 Computer Graphics Group RWTH Aachen University. *
 * All rights reserved.                                                *
 * Distributed under the terms of the MIT License (see LICENSE.TXT).   *
 **********************************************************************/
6
7
8

#ifndef ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILE_HH
#define ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILE_HH
9
#ifdef ACGL_INCLUDE_DEPRECATED_FUNCTIONALITY
10
11
12
13
14
15
16
17
18
19
20
/**
 * Basetemplate for file loading.
 *
 * TextureDataControlFile and GeometryDataControlFile are typedefs below
 *
 * To support another filetype, derive from those and implement load() and registerType() methods.
 * Also: add a call to the InitStaticFileTypes to register the file type globally.
 */

#include <ACGL/ACGL.hh>

21
#include <ACGL/Resource/SingleFileBasedCreator.hh>
22
23
24
25
26
27
28
29
#include <ACGL/Base/Settings.hh>
#include <ACGL/OpenGL/Data/TextureData.hh>
#include <ACGL/OpenGL/Data/GeometryData.hh>

namespace ACGL{
namespace OpenGL{

template<class DATA_FILE_TYPE>
30
class DataControlFile : public Resource::SingleFileBasedCreator<DATA_FILE_TYPE>
31
32
33
34
35
36
37
{
private:
    typedef ptr::shared_ptr< DATA_FILE_TYPE > SharedDATA_FILE_TYPE;
    // ========================================================================================================= \/
    // ============================================================================================ CONSTRUCTORS \/
    // ========================================================================================================= \/
public:
Robert Menzel's avatar
Robert Menzel committed
38
    DataControlFile(const std::string& _filename, const std::string& _resourcePath)
39
    :   Resource::SingleFileBasedCreator<DATA_FILE_TYPE>(_filename, _resourcePath)
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
    {}
    virtual ~DataControlFile(void) {}

    // ====================================================================================================== \/
    // ============================================================================================ INTERFACE \/
    // ====================================================================================================== \/
private:
    virtual bool load(SharedDATA_FILE_TYPE& texture) const = 0;

    // ====================================================================================================== \/
    // ============================================================================================= OVERRIDE \/
    // ====================================================================================================== \/
public:
    virtual SharedDATA_FILE_TYPE create(void)
    {
55
        Resource::SingleFileBasedCreator<DATA_FILE_TYPE>::updateFileModificationTime();
56
57
58
59
60
61
62
63
64

        SharedDATA_FILE_TYPE texture(new DATA_FILE_TYPE());

        if(load(texture))
            return texture;

        return SharedDATA_FILE_TYPE();
    }

Robert Menzel's avatar
Robert Menzel committed
65
    virtual bool update(SharedDATA_FILE_TYPE& _data)
66
    {
67
        if (Resource::SingleFileBasedCreator<DATA_FILE_TYPE>::fileIsUpToDate())
68
69
            return false;

Robert Menzel's avatar
Robert Menzel committed
70
        if(!load(_data))
71
72
            return false;

73
        Resource::SingleFileBasedCreator<DATA_FILE_TYPE>::updateFileModificationTime();
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
        return true;
    }

    // ==================================================================================================== \/
    // ============================================================================================ METHODS \/
    // ==================================================================================================== \/
public:
    static int_t getTypeID(void) { return sTypeID; }

    // =================================================================================================== \/
    // ============================================================================================ FIELDS \/
    // =================================================================================================== \/
protected:
    static int_t sTypeID;
};

typedef DataControlFile< TextureData > TextureDataControlFile;
ACGL_SMARTPOINTER_TYPEDEFS( TextureDataControlFile )

typedef DataControlFile< GeometryData > GeometryDataControlFile;
ACGL_SMARTPOINTER_TYPEDEFS( GeometryDataControlFile )

} // OpenGL
} // ACGL
98
#endif
99
#endif // ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILE_HH