clsUtil.h 3.7 KB
#pragma once
#include <cairo/cairo.h>
#include<string>
#include<vector>
#include "dmap_core.h"
using namespace std;
namespace DmapCore_30
{
	class clsCrSurf;
	class DataCollection;
	class Renderer;
	class Rect;
	class clsMalloc;

#define GetIndexP(index,to)  \
	int length = (int)to.size(); \
	if (index<0 || index >= length)return NULL; \
	to[index]->AddRef(); \
	return to[index];
	//Set一个指针时, 必须先AddRef, 由于传入的指针与被替换的指针有可能是同一个, 先Release 内存出错
#define SetIndexP(index,from,to)   \
	if (!from)return false; \
	int length = (int)to.size(); \
	if (index>length)return false; \
	from->AddRef(); \
	if (index < 0 || index == length)to.push_back(from); \
else { to[index]->Release(); to[index] = from; }\
	return true;
#define RemoveIndexP(index,to)  \
	int length = (int)to.size(); \
	if (index < 0 || index >= length)return false; \
	to[index]->Release(); \
	to.erase(to.begin() + index); \
	return true;
#define ClearP(to)  \
	int length = (int)to.size(); \
	for (int i = 0; i < length; i++)\
	{to[i]->Release(); }to.clear(); return true;


	class CORE_EXPORT  clsUtil
	{
	public:
		clsUtil();
		~clsUtil();
		static unsigned int RandomColor();
		static bool Exchange4(unsigned char * here);
		static bool Exchange8(unsigned char * here);
		static bool ToCairoColor(unsigned int Color, double& r, double & g, double& b);
		static bool ToCairoColor(unsigned int Color, double &r, double & g, double& b, double&a);
		static bool ToCairoColor(string color, double &r, double & g, double& b, double&a);
		static bool ReadHead(unsigned char* & here, int& not_big1, int & shapetype);
		static int ReadInt(unsigned char*& here, int  not_big1);
		static int Hex2int(char c);
		static int ReadByte(unsigned char*& here);
		static double ReadDouble(unsigned char*& here, int not_big);
		static bool DoSetLineType(int LineType, cairo_t* cr);
		static bool DoSetAntialias(int iAntialias, cairo_t* cr);
		static char * ConvertEnc(const char *encFrom,const char *encTo, const char * in, char *bufout, size_t lenout);
		static bool  ConvertEncUTF8_GB18030(const char *from, clsMalloc &m);
		static bool  ConvertEncGB18030_UTF8(const char* from, clsMalloc &m);

		static bool DrawStruct(clsCrSurf* pClsCS, DataCollection* data, int index, Renderer* pSimpleRenderer);

		static bool ZoomFunction(Rect* extent_from, Rect* extent_to, double& r, double & x_dis, double& y_dis);
		static bool PointInRect(double x, double y, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4); // 判断一个点是否在矩形内(该矩形可旋转)
		static bool PointInLines(double x, double y, double k1, double b1, double k2, double b2);  //采用 y = k * x + b; k1,b1等是直线系数
		static double StandardizationAngle(double dAngle);

		static string TryAddDoubleQuotation(string s);
		static string TryDeleteDoubleQuotation(string s);


		static void GetFiles(string path, string exd, vector<string> & files);
		static int  ParseStringTok(char * sz, char  toK, char ** szPtr, int maxPtr);

		static void ToJSONString(std::string &s);
		static void ToXMLString(std::string &s);
		static string CharReplace(string strsrc, string strfind, string strrep);

		static std::string fmt(char *, ...);
		static std::string fmt(const char*, ...);
		static void ValueString(string * s, bool* bValue);
		static void ValueString(string* s, double* dValue);
		static void ValueString(string* s, long* lValue);
		static void ValueString(string* s, string* sValue);
		static void EnumString(string* s, int* iEnum, string s1 = "", string s2 = "", string s3 = "", string s4 = "", string s5 = "", string s6 = "", string s7 = "", string s8 = "", string s9 = "", string s10 = "", string s11 = "", string s12 = "");
		static void ColorString(string* s, unsigned int* iColor);
	};

}