apply new tangram
[platform/core/location/maps-plugin-mapzen.git] / src / mapzen / tangram / platform.h
index 9bb8589..4f2c91b 100644 (file)
@@ -1,73 +1,85 @@
 #pragma once
 
+#include <functional>
 #include <string>
-#include <cstring>
 #include <vector>
-#include <algorithm>
-#include <functional>
-#include <cstdio>
 
-/* Print a formatted message to the console
- *
- * Uses printf syntax to write a string to stderr (or logcat, on Android)
- */
-void logMsg(const char* fmt, ...);
+namespace Tangram {
 
-/* Function type for a mapReady callback*/
+// Function type for a mapReady callback
 using MapReady = std::function<void(void*)>;
 
-/* Request that a new frame be rendered by the windowing system
- */
-void requestRender();
+// Function type for receiving data from a successful network request
+using UrlCallback = std::function<void(std::vector<char>&&)>;
+
+using FontSourceLoader = std::function<std::vector<char>()>;
+
+struct FontSourceHandle {
+    FontSourceHandle(std::string _path) : path(_path) {}
+    FontSourceHandle(FontSourceLoader _loader) : load(_loader) {}
 
-/* If called with 'true', the windowing system will re-draw frames continuously;
- * otherwise new frames will only be drawn when 'requestRender' is called.
- */
-void setContinuousRendering(bool _isContinuous);
+    std::string path;
+    FontSourceLoader load;
+};
 
-bool isContinuousRendering();
+// Print a formatted message to the console
+// Uses printf syntax to write a string to stderr (or logcat, on Android)
+void logMsg(const char* fmt, ...);
 
-/* get system path of a font file */
-std::string systemFontPath(const std::string& _name, const std::string& _weight, const std::string& _face);
+void initGLExtensions();
 
-/* Read a file as a string
- *
- * Opens the file at the _path and returns a string with its contents.
- * If the file cannot be found or read, the returned string is empty.
- */
-std::string stringFromFile(const char* _path);
+// Set the priority of the current thread. Priority is equivalent to pthread niceness
+void setCurrentThreadPriority(int priority);
 
-/* Read a file into memory
- *
- * Opens the file at _path then allocates and returns a pointer to memory
- * containing the contents of the file. The size of the memory in bytes is written to _size.
- * If the file cannot be read, nothing is allocated and nullptr is returned.
- */
-unsigned char* bytesFromFile(const char* _path, size_t& _size);
+class Platform {
 
-/* Function type for receiving data from a successful network request */
-using UrlCallback = std::function<void(std::vector<char>&&)>;
+public:
 
-/* Start retrieving data from a URL asynchronously
- *
- * When the request is finished, the callback @_callback will be
- * run with the data that was retrieved from the URL @_url
- */
-bool startUrlRequest(const std::string& _url, UrlCallback _callback);
+    Platform();
+    virtual ~Platform();
 
-/* Stop retrieving data from a URL that was previously requested
- */
-void cancelUrlRequest(const std::string& _url);
+    // Request that a new frame be rendered by the windowing system
+    virtual void requestRender() const = 0;
 
+    // If called with 'true', the windowing system will re-draw frames continuously;
+    // otherwise new frames will only be drawn when 'requestRender' is called.
+    virtual void setContinuousRendering(bool _isContinuous);
 
-/* Set the priority of the current thread. Priority is equivalent
- * to pthread niceness.
- */
-void setCurrentThreadPriority(int priority);
+    virtual bool isContinuousRendering() const;
 
-/* Get the font fallback ordered by importance, 0 being the first fallback
- * (e.g. the fallback more willing resolve the glyph codepoint)
- */
-std::string systemFontFallbackPath(int _importance, int _weightHint);
+    virtual std::string resolveAssetPath(const std::string& path) const;
 
-void initGLExtensions();
+    // Read a file as a string
+    // Opens the file at the _path and returns a string with its contents.
+    // If the file cannot be found or read, the returned string is empty.
+    virtual std::string stringFromFile(const char* _path) const;
+
+    // Read a file into memory
+    // Opens the file at _path then allocates and returns a pointer to memory
+    // containing the contents of the file. The size of the memory in bytes is written to _size.
+    // If the file cannot be read, nothing is allocated and nullptr is returned.
+    virtual std::vector<char> bytesFromFile(const char* _path) const;
+
+    // Start retrieving data from a URL asynchronously
+    // When the request is finished, the callback _callback will be
+    // run with the data that was retrieved from the URL _url
+    virtual bool startUrlRequest(const std::string& _url, UrlCallback _callback) = 0;
+
+    // Stop retrieving data from a URL that was previously requested
+    virtual void cancelUrlRequest(const std::string& _url) = 0;
+
+    virtual std::vector<char> systemFont(const std::string& _name, const std::string& _weight, const std::string& _face) const;
+
+    virtual std::vector<FontSourceHandle> systemFontFallbacksHandle() const;
+
+protected:
+
+    bool bytesFromFileSystem(const char* _path, std::function<char*(size_t)> _allocator) const;
+
+private:
+
+    bool m_continuousRendering;
+
+};
+
+} // namespace Tangram