src/util.h

Go to the documentation of this file.
00001 // Copyright (c) 2003 - 2004 Anselm R. Garbe <anselmg at t-online.de>
00002 // See ../LICENSE.txt for license details.
00003 //
00004 // $Id: util.h 7 2007-05-24 11:03:53Z eg1981 $
00005 
00006 #ifndef __UTIL_H
00007 #define __UTIL_H
00008 
00009 extern "C" {
00010 #include <X11/keysym.h>
00011 #include <X11/Xlib.h>
00012 #include <sys/stat.h>
00013 }
00014 
00015 #include <list>
00016 #include <string>
00017 #include <set>
00018 #include <map>
00019 
00020 #include "ncwm.h"
00021 
00022 class Action;
00023 class Rectangle;
00024 
00025 typedef map<string, string, less<string> > MSettings;
00026 typedef map<string, Action *, less<string> > MBindings;
00027 
00031 class Util
00032 {
00033 
00034 public:
00035 
00036     Util();
00037 
00038     ~Util();
00039 
00041     static string nthToken(string str, char delim, unsigned int n);
00042 
00044     static string lastToken(string str, char delim);
00045 
00046     static string lowerCase(string str);
00047 
00049     static string canonicalPath(string file);
00050 
00052     static string canonicalDir(string path);
00053 
00054     static bool containsWhitespaces(string str);
00055 
00057     static string truncate(string str, char c);
00058 
00060     static void swapChars(string *str, char from, char to,
00061                             unsigned int *swapCount = 0);
00062 
00063 
00065     static string shortenString(string str, unsigned int n);
00066 
00067     static string encodeEscapes(string str);
00068 
00069     static unsigned int numDigits(unsigned int number);
00070 
00071     static unsigned long modMaskForString(string modKeys);
00072     static string stringForModMask(unsigned long modMask);
00073 
00074     static string stringForButton(unsigned int button);
00075     static unsigned int buttonForString(string button);
00076 
00078     static char **arguments(string command);
00079 
00081     static string timestamp();
00082 
00083     static unsigned int strToUInt(string str);
00084 
00086     static void fitInto(Rectangle *client, Rectangle *host);
00087 
00089     static bool isPointWithinRect(unsigned int x, unsigned int y, Rectangle *rect,
00090                                   Rectangle *offset = 0);
00091 
00093     static Direction dirForString(string str);
00094 
00095     static bool exists(const char *path);
00096 
00097     static set<string> stringSplit(string s, string delimiter);
00098 
00100     static string trimL(string s);
00101 
00102     static Direction reverseDir(Direction dir);
00103 
00108     template <class L, class LTI, class T>
00109     static void destroy(L *l, LTI start, LTI end) {
00110         for (LTI it = start; it != end; it++) {
00111             T t = (T)*it;
00112             delete t;
00113         }
00114 
00115         l->erase(start, end);
00116     }
00117 
00121     template <class L, class LTI, class T>
00122     static bool contains(L *l, T *item) {
00123         for (LTI it = l->begin(); it != l->end(); it++) {
00124             if (item == *it) {
00125                 return true;
00126             }
00127         }
00128         return false;
00129     };
00130 
00131     static string get(MSettings *settings, string key);
00132     static void remove(MSettings *settings, string prefix);
00133 
00134     static Action *get(MBindings *bindings, string key);
00135     static void remove(MBindings *bindings, string prefix);
00136 
00137 private:
00138 
00140     static void fitIntoDirection(int horigin, int hw, int *corigin, int *cw);
00141 
00142 };
00143 
00144 #endif // __UTIL_H

Generated on Thu May 24 15:19:32 2007 for ncwm by  doxygen 1.5.1