/[svn]/gigedit/trunk/src/gigedit/global.h
ViewVC logotype

Diff of /gigedit/trunk/src/gigedit/global.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3157 by schoenebeck, Mon May 8 17:30:10 2017 UTC revision 3462 by persson, Sun Feb 3 13:27:28 2019 UTC
# Line 1  Line 1 
1  /*                                                         -*- c++ -*-  /*                                                         -*- c++ -*-
2   * Copyright (C) 2007-2017 Andreas Persson   * Copyright (C) 2007-2019 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 25  Line 25 
25  #endif  #endif
26    
27  #include <cstring>  #include <cstring>
28    #include <algorithm>
29    
30  #include <glibmmconfig.h>  #ifdef GLIBMM_HEADER_FILE
31    # include GLIBMM_HEADER_FILE(glibmmconfig.h)
32    #else
33    # include <glibmmconfig.h>
34    #endif
35  // threads.h must be included first to be able to build with  // threads.h must be included first to be able to build with
36  // G_DISABLE_DEPRECATED  // G_DISABLE_DEPRECATED
37  #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \  #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \
# Line 41  Line 46 
46    
47  #include <sstream>  #include <sstream>
48  #include <map>  #include <map>
49    #include <sigc++/signal.h>
50    
51  #ifdef LIBGIG_HEADER_FILE  #ifdef LIBGIG_HEADER_FILE
52  # include LIBGIG_HEADER_FILE(gig.h)  # include LIBGIG_HEADER_FILE(gig.h)
# Line 51  Line 57 
57  #endif  #endif
58    
59  //FIXME: for some reason AC GETTEXT check fails on the Mac cross compiler?  //FIXME: for some reason AC GETTEXT check fails on the Mac cross compiler?
60  #if (HAVE_GETTEXT || defined(__APPLE__))  #ifdef GETTEXT_HEADER_FILE
61    # include GETTEXT_HEADER_FILE(libintl.h)
62    #elif (HAVE_GETTEXT || defined(__APPLE__))
63  # include <libintl.h>  # include <libintl.h>
64  # define _(String) gettext(String)  # define _(String) gettext(String)
65  #else  #else
# Line 116  gig::String gig_from_utf8(const Glib::us Line 124  gig::String gig_from_utf8(const Glib::us
124      return Glib::convert_with_fallback(utf8_string, GIG_STR_ENCODING, "UTF-8", "?");      return Glib::convert_with_fallback(utf8_string, GIG_STR_ENCODING, "UTF-8", "?");
125  }  }
126    
127    inline Glib::ustring ltrim(Glib::ustring s) {
128        s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
129        return s;
130    }
131    
132    inline Glib::ustring rtrim(Glib::ustring s) {
133        s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
134        return s;
135    }
136    
137    inline Glib::ustring trim(Glib::ustring s) {
138        return ltrim(rtrim(s));
139    }
140    
141  template<class T> inline std::string ToString(T o) {  template<class T> inline std::string ToString(T o) {
142      std::stringstream ss;      std::stringstream ss;
143      ss << o;      ss << o;
144      return ss.str();      return ss.str();
145  }  }
146    
147    inline static bool endsWith(const std::string& haystack, const std::string& needle, bool caseSensitive) {
148        if (haystack.size() < needle.size()) return false;
149        const std::string sub = haystack.substr(haystack.size() - needle.size(), needle.size());
150        return (caseSensitive) ? (sub == needle) : (!strcasecmp(sub.c_str(), needle.c_str()));
151    }
152    
153  inline int getDimensionIndex(gig::dimension_t type, gig::Region* rgn) {  inline int getDimensionIndex(gig::dimension_t type, gig::Region* rgn) {
154      for (uint i = 0; i < rgn->Dimensions; ++i)      for (uint i = 0; i < rgn->Dimensions; ++i)
155          if (rgn->pDimensionDefinitions[i].dimension == type)          if (rgn->pDimensionDefinitions[i].dimension == type)
# Line 205  inline DimensionCase dimensionCaseOf(gig Line 233  inline DimensionCase dimensionCaseOf(gig
233      return dimCase;      return dimCase;
234  }  }
235    
236  inline std::vector<gig::DimensionRegion*> dimensionRegionsMatching(const DimensionCase& dimCase, gig::Region* rgn) {  /**
237     * Checks whether the passed dimension zones are within the boundaries of the
238     * defined dimensions. This is especially relevant if there are dimensions
239     * defined with an amount not equal to a power of two, in that case there are
240     * unused dimensions regions which should be ignored.
241     */
242    inline bool isUsedCase(const DimensionCase& c, gig::Region* rgn) {
243        for (int d = 0; d < rgn->Dimensions; ++d) {
244            gig::dimension_t type = rgn->pDimensionDefinitions[d].dimension;
245            if (c.find(type) == c.end()) continue;
246            int zone = c.find(type)->second;
247            if (zone < 0 || zone >= rgn->pDimensionDefinitions[d].zones)
248                return false;
249        }
250        return true;
251    }
252    
253    inline std::vector<gig::DimensionRegion*> dimensionRegionsMatching(
254        const DimensionCase& dimCase, gig::Region* rgn, bool skipUnusedZones = false)
255    {
256      std::vector<gig::DimensionRegion*> v;      std::vector<gig::DimensionRegion*> v;
257      for (int idr = 0; idr < 256; ++idr) {      for (int idr = 0; idr < 256; ++idr) {
258          if (!rgn->pDimensionRegions[idr]) continue;          if (!rgn->pDimensionRegions[idr]) continue;
259          DimensionCase c = dimensionCaseOf(rgn->pDimensionRegions[idr]);          DimensionCase c = dimensionCaseOf(rgn->pDimensionRegions[idr]);
260          if (!dimCase.isViolating(c)) v.push_back(rgn->pDimensionRegions[idr]);          if (dimCase.isViolating(c)) continue;
261            if (skipUnusedZones && !isUsedCase(c, rgn)) continue;
262            v.push_back(rgn->pDimensionRegions[idr]);
263      }      }
264      return v;      return v;
265  }  }
# Line 224  inline gig::DimensionRegion* dimensionRe Line 273  inline gig::DimensionRegion* dimensionRe
273      return NULL;      return NULL;
274  }  }
275    
276    template<typename T_Message>
277    class SignalGuard {
278    public:
279        SignalGuard(sigc::signal<void, T_Message>& start, sigc::signal<void, T_Message>& end, T_Message message)
280            : m_end(end), m_message(message)
281        {
282            if (message) start.emit(message);
283        }
284    
285        virtual ~SignalGuard() {
286            if (m_message) m_end.emit(m_message);
287        }
288    protected:
289        sigc::signal<void, T_Message>& m_end;
290        T_Message m_message;
291    };
292    
293  #endif // GIGEDIT_GLOBAL_H  #endif // GIGEDIT_GLOBAL_H

Legend:
Removed from v.3157  
changed lines
  Added in v.3462

  ViewVC Help
Powered by ViewVC