tvg binary format might break the compatibility if any major features have been changed.
It's allowed to do it when the major version is upgraded.
In that case, still we need to support the backward compatibility,
we can provide multiple binary interpreters and choose the proper one
based on the current loading tvg binary format version.
Thus, you can add further interpreters if it's necessary in the future.
Our policy is to derive the TvgBinInterpreterBase class to make it running on
the interface.
for example, if the major version is upgraded 1.x, you can implement TvgBinInterpreter1.
source_file = [
'tvgTvgLoader.h',
+ 'tvgTvgCommon.h',
'tvgTvgLoader.cpp',
- 'tvgTvgLoadParser.h',
- 'tvgTvgLoadParser.cpp',
+ 'tvgTvgBinInterpreter.cpp',
]
subloader_dep += [declare_dependency(
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-
#include <memory.h>
-#include "tvgTvgLoadParser.h"
+#include "tvgTvgCommon.h"
/************************************************************************/
/* External Class Implementation */
/************************************************************************/
-unique_ptr<Scene> tvgLoadData(const char *ptr, const char* end)
+unique_ptr<Scene> TvgBinInterpreter::run(const char *ptr, const char* end)
{
auto scene = Scene::gen();
if (!scene) return nullptr;
* SOFTWARE.
*/
-#ifndef _TVG_TVG_LOAD_PARSER_H_
-#define _TVG_TVG_LOAD_PARSER_H_
+#ifndef _TVG_TVG_COMMON_H_
+#define _TVG_TVG_COMMON_H_
#include "tvgCommon.h"
#include "tvgBinaryDesc.h"
#define READ_UI32(dst, src) memcpy(dst, (src), sizeof(uint32_t))
#define READ_FLOAT(dst, src) memcpy(dst, (src), sizeof(float))
-unique_ptr<Scene> tvgLoadData(const char* ptr, const char* end);
-#endif //_TVG_TVG_LOAD_PARSER_H_
+/* Interface for Tvg Binary Interpreter */
+class TvgBinInterpreterBase
+{
+public:
+ virtual ~TvgBinInterpreterBase() {}
+
+ /* ptr: points the tvg binary body (after header)
+ end: end of the tvg binary data */
+ virtual unique_ptr<Scene> run(const char* ptr, const char* end) = 0;
+};
+
+
+/* Version 0 */
+class TvgBinInterpreter : public TvgBinInterpreterBase
+{
+public:
+ unique_ptr<Scene> run(const char* ptr, const char* end) override;
+};
+
+
+#endif //_TVG_TVG_COMMON_H_
\ No newline at end of file
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-
-#include <fstream>
#include <memory.h>
+#include <fstream>
#include "tvgLoader.h"
#include "tvgTvgLoader.h"
-#include "tvgTvgLoadParser.h"
/************************************************************************/
/* Internal Class Implementation */
/************************************************************************/
+
void TvgLoader::clear()
{
if (copy) free((char*)data);
ptr = data = nullptr;
size = 0;
copy = false;
+
+ if (interpreter) {
+ delete(interpreter);
+ interpreter = nullptr;
+ }
}
READ_FLOAT(&h, ptr);
ptr += SIZE(float);
+ //Decide the proper Tvg Binary Interpreter based on the current file version
+ if (this->version >= 0) interpreter = new TvgBinInterpreter;
+
return true;
}
void TvgLoader::run(unsigned tid)
{
if (root) root.reset();
- root = tvgLoadData(ptr, data + size);
+
+ root = interpreter->run(ptr, data + size);
+
if (!root) clear();
}
this->done();
if (root) return move(root);
return nullptr;
-}
+}
\ No newline at end of file
#define _TVG_TVG_LOADER_H_
#include "tvgTaskScheduler.h"
+#include "tvgTvgCommon.h"
+
class TvgLoader : public LoadModule, public Task
{
uint32_t size = 0;
uint16_t version = 0;
unique_ptr<Scene> root = nullptr;
+ TvgBinInterpreterBase* interpreter = nullptr;
bool copy = false;
~TvgLoader();