/[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 3472 by persson, Sat Feb 16 19:56:56 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  // threads.h must be included first to be able to build with  # include GLIBMM_HEADER_FILE(glibmmconfig.h)
32  // G_DISABLE_DEPRECATED  #else
33  #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \  # include <glibmmconfig.h>
     (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2  
 #include <glibmm/threads.h>  
34  #endif  #endif
35    
36  #if !defined(WIN32)  #if !defined(WIN32)
# Line 41  Line 40 
40    
41  #include <sstream>  #include <sstream>
42  #include <map>  #include <map>
43    #include <sigc++/signal.h>
44    
45  #ifdef LIBGIG_HEADER_FILE  #ifdef LIBGIG_HEADER_FILE
46  # include LIBGIG_HEADER_FILE(gig.h)  # include LIBGIG_HEADER_FILE(gig.h)
# Line 51  Line 51 
51  #endif  #endif
52    
53  //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?
54  #if (HAVE_GETTEXT || defined(__APPLE__))  #ifdef GETTEXT_HEADER_FILE
55    # include GETTEXT_HEADER_FILE(libintl.h)
56    #elif (HAVE_GETTEXT || defined(__APPLE__))
57  # include <libintl.h>  # include <libintl.h>
58  # define _(String) gettext(String)  # define _(String) gettext(String)
59  #else  #else
# Line 116  gig::String gig_from_utf8(const Glib::us Line 118  gig::String gig_from_utf8(const Glib::us
118      return Glib::convert_with_fallback(utf8_string, GIG_STR_ENCODING, "UTF-8", "?");      return Glib::convert_with_fallback(utf8_string, GIG_STR_ENCODING, "UTF-8", "?");
119  }  }
120    
121    inline Glib::ustring ltrim(Glib::ustring s) {
122        s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
123        return s;
124    }
125    
126    inline Glib::ustring rtrim(Glib::ustring s) {
127        s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
128        return s;
129    }
130    
131    inline Glib::ustring trim(Glib::ustring s) {
132        return ltrim(rtrim(s));
133    }
134    
135  template<class T> inline std::string ToString(T o) {  template<class T> inline std::string ToString(T o) {
136      std::stringstream ss;      std::stringstream ss;
137      ss << o;      ss << o;
138      return ss.str();      return ss.str();
139  }  }
140    
141    inline static bool endsWith(const std::string& haystack, const std::string& needle, bool caseSensitive) {
142        if (haystack.size() < needle.size()) return false;
143        const std::string sub = haystack.substr(haystack.size() - needle.size(), needle.size());
144        return (caseSensitive) ? (sub == needle) : (!strcasecmp(sub.c_str(), needle.c_str()));
145    }
146    
147  inline int getDimensionIndex(gig::dimension_t type, gig::Region* rgn) {  inline int getDimensionIndex(gig::dimension_t type, gig::Region* rgn) {
148      for (uint i = 0; i < rgn->Dimensions; ++i)      for (uint i = 0; i < rgn->Dimensions; ++i)
149          if (rgn->pDimensionDefinitions[i].dimension == type)          if (rgn->pDimensionDefinitions[i].dimension == type)
# Line 205  inline DimensionCase dimensionCaseOf(gig Line 227  inline DimensionCase dimensionCaseOf(gig
227      return dimCase;      return dimCase;
228  }  }
229    
230  inline std::vector<gig::DimensionRegion*> dimensionRegionsMatching(const DimensionCase& dimCase, gig::Region* rgn) {  /**
231     * Checks whether the passed dimension zones are within the boundaries of the
232     * defined dimensions. This is especially relevant if there are dimensions
233     * defined with an amount not equal to a power of two, in that case there are
234     * unused dimensions regions which should be ignored.
235     */
236    inline bool isUsedCase(const DimensionCase& c, gig::Region* rgn) {
237        for (int d = 0; d < rgn->Dimensions; ++d) {
238            gig::dimension_t type = rgn->pDimensionDefinitions[d].dimension;
239            if (c.find(type) == c.end()) continue;
240            int zone = c.find(type)->second;
241            if (zone < 0 || zone >= rgn->pDimensionDefinitions[d].zones)
242                return false;
243        }
244        return true;
245    }
246    
247    inline std::vector<gig::DimensionRegion*> dimensionRegionsMatching(
248        const DimensionCase& dimCase, gig::Region* rgn, bool skipUnusedZones = false)
249    {
250      std::vector<gig::DimensionRegion*> v;      std::vector<gig::DimensionRegion*> v;
251      for (int idr = 0; idr < 256; ++idr) {      for (int idr = 0; idr < 256; ++idr) {
252          if (!rgn->pDimensionRegions[idr]) continue;          if (!rgn->pDimensionRegions[idr]) continue;
253          DimensionCase c = dimensionCaseOf(rgn->pDimensionRegions[idr]);          DimensionCase c = dimensionCaseOf(rgn->pDimensionRegions[idr]);
254          if (!dimCase.isViolating(c)) v.push_back(rgn->pDimensionRegions[idr]);          if (dimCase.isViolating(c)) continue;
255            if (skipUnusedZones && !isUsedCase(c, rgn)) continue;
256            v.push_back(rgn->pDimensionRegions[idr]);
257      }      }
258      return v;      return v;
259  }  }
# Line 224  inline gig::DimensionRegion* dimensionRe Line 267  inline gig::DimensionRegion* dimensionRe
267      return NULL;      return NULL;
268  }  }
269    
270    template<typename T_Message>
271    class SignalGuard {
272    public:
273        SignalGuard(sigc::signal<void, T_Message>& start, sigc::signal<void, T_Message>& end, T_Message message)
274            : m_end(end), m_message(message)
275        {
276            if (message) start.emit(message);
277        }
278    
279        virtual ~SignalGuard() {
280            if (m_message) m_end.emit(m_message);
281        }
282    protected:
283        sigc::signal<void, T_Message>& m_end;
284        T_Message m_message;
285    };
286    
287  #endif // GIGEDIT_GLOBAL_H  #endif // GIGEDIT_GLOBAL_H

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

  ViewVC Help
Powered by ViewVC