summaryrefslogtreecommitdiff
path: root/fluid/app
diff options
context:
space:
mode:
Diffstat (limited to 'fluid/app')
-rw-r--r--fluid/app/Image_Asset.cxx78
1 files changed, 63 insertions, 15 deletions
diff --git a/fluid/app/Image_Asset.cxx b/fluid/app/Image_Asset.cxx
index 7a05cd99b..09550fac0 100644
--- a/fluid/app/Image_Asset.cxx
+++ b/fluid/app/Image_Asset.cxx
@@ -38,16 +38,64 @@
#include <errno.h>
#include <stdlib.h>
#include <stdarg.h>
-#include <map>
+#include <string.h>
#include <string>
+/** Simple string-to-Image_Asset map entry */
+struct Image_Asset_Entry {
+ char *key;
+ Image_Asset *value;
+};
-/**
- \brief A map of all image assets.
- \todo This is a global variable, but should be associated
- with a project instead.
- */
-static std::map<std::string, Image_Asset*> image_asset_map;
+/** Simple string-to-Image_Asset map (linear search) */
+static struct {
+ Image_Asset_Entry *entries;
+ int count;
+ int capacity;
+
+ Image_Asset *find(const char *key) {
+ int i;
+ for (i = 0; i < count; i++) {
+ if (strcmp(entries[i].key, key) == 0)
+ return entries[i].value;
+ }
+ return 0;
+ }
+
+ void insert(const char *key, Image_Asset *value) {
+ // Check if already exists
+ int i;
+ for (i = 0; i < count; i++) {
+ if (strcmp(entries[i].key, key) == 0) {
+ entries[i].value = value;
+ return;
+ }
+ }
+ // Insert new
+ if (count >= capacity) {
+ capacity = capacity ? capacity * 2 : 16;
+ entries = (Image_Asset_Entry*)realloc(entries, capacity * sizeof(Image_Asset_Entry));
+ }
+ entries[count].key = strdup(key);
+ entries[count].value = value;
+ count++;
+ }
+
+ void erase(const char *key) {
+ int i;
+ for (i = 0; i < count; i++) {
+ if (strcmp(entries[i].key, key) == 0) {
+ free(entries[i].key);
+ // Move last entry to this position
+ if (i < count - 1) {
+ entries[i] = entries[count - 1];
+ }
+ count--;
+ return;
+ }
+ }
+ }
+} image_asset_map;
/**
@@ -392,12 +440,12 @@ void Image_Asset::write_inline(fld::io::Code_Writer& f, int inactive) {
\returns The image asset, or nullptr if it cannot be loaded.
*/
Image_Asset* Image_Asset::find(const char *iname) {
- if (!iname || !*iname) return nullptr;
+ if (!iname || !*iname) return 0;
// First search to see if it exists already. If it does, return it.
- auto result = image_asset_map.find(iname);
- if (result != image_asset_map.end())
- return result->second;
+ Image_Asset *result = image_asset_map.find(iname);
+ if (result)
+ return result;
// Check if a file by that name exists.
Fluid.proj.enter_project_dir();
@@ -408,7 +456,7 @@ Image_Asset* Image_Asset::find(const char *iname) {
else
fl_message("Can't open image file:\n%s\n%s",iname,strerror(errno));
Fluid.proj.leave_project_dir();
- return nullptr;
+ return 0;
}
fclose(f);
@@ -421,11 +469,11 @@ Image_Asset* Image_Asset::find(const char *iname) {
else
fl_message("Can't read image file:\n%s\nunrecognized image format",iname);
Fluid.proj.leave_project_dir();
- return nullptr;
+ return 0;
}
// Add the new asset to our image asset map and return it to the caller.
- image_asset_map[iname] = asset;
+ image_asset_map.insert(iname, asset);
return asset;
}
@@ -490,7 +538,7 @@ void Image_Asset::dec_ref() {
when the object is destroyed.
*/
Image_Asset::~Image_Asset() {
- image_asset_map.erase(filename_);
+ image_asset_map.erase(filename_.c_str());
if (image_) image_->release();
}