All file read operations should be done through FileLoader.
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / file-loader.cpp
index 9403781..b63b5c7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 // CLASS HEADER
 #include <dali/devel-api/adaptor-framework/file-loader.h>
 
-
+// EXTERNAL INCLUDES
 #include <iostream>
 #include <fstream>
 
+// INTERNAL INCLUDES
+#include <dali/internal/adaptor-framework/common/file-loader-impl.h>
+
 namespace Dali
 {
 
@@ -29,60 +32,17 @@ namespace FileLoader
 
 int ReadFile(const std::string& filename, Dali::Vector<char> & memblock, FileLoader::FileType fileType)
 {
-  std::streampos size;
-
-  return ReadFile( filename, size, memblock, fileType);
+  return Dali::Internal::Adaptor::ReadFile( filename, memblock, fileType );
 }
 
-int ReadFile(const std::string& filename, std::streampos& fileSize, Dali::Vector<char> & memblock, FileLoader::FileType fileType)
+int ReadFile(const std::string& filename, std::streampos& fileSize, Dali::Vector<char>& memblock, FileLoader::FileType fileType)
 {
-  int errorCode = 0;
-  std::ifstream * file;
-
-
-  if( fileType == BINARY )
-  {
-    file = new std::ifstream (filename.c_str(), std::ios::in|std::ios::binary|std::ios::ate);
-  }
-  else if( fileType == TEXT )
-  {
-    file = new std::ifstream (filename.c_str(), std::ios::in|std::ios::ate);
-  }
-  else
-  {
-    return errorCode;
-  }
-
-  if( file->is_open() )
-  {
-    fileSize = file->tellg();
-
-    memblock.Resize( fileSize );
-
-    file->seekg (0, std::ios::beg);
-    file->read( memblock.Begin(), fileSize );
-    file->close();
-
-    delete file;
-
-    errorCode = 1;
-  }
-
-  return errorCode;
+  return Dali::Internal::Adaptor::ReadFile( filename, fileSize, memblock, fileType );;
 }
 
-
 std::streampos GetFileSize(const std::string& filename)
 {
-  std::streampos size = 0;
-
-  std::ifstream file (filename.c_str(), std::ios::in|std::ios::binary|std::ios::ate);
-  if( file.is_open() )
-  {
-    size = file.tellg();
-    file.close();
-  }
-  return size;
+  return Dali::Internal::Adaptor::GetFileSize(filename);
 }
 
 } //FileLoader