首页 > cef > CEF-ID2NAME+NAME2ID模板转换
2017六月29

CEF-ID2NAME+NAME2ID模板转换

GPDef.h 

// --------------------------------------------------
// XML节点宏
/// <summary>
///		在此处加入XML结点定义,
///     eg:加入NODE(DMCODE),意为:
///     1.XmlId内定义了XML_DMCODE枚举 2.ID2NAME(XML_DMCODE)返回字符串L"DMCODE" 3.NAME2ID(L"DMCODE")返回枚举XML_DMCODE
/// </summary>
#define __foreach_id(NODE) \
	/*A*/\
	NODE(ADDR)\
	NODE(ALIAS)\
	/*B*/\
	NODE(BYTES)\
	NODE(BSHOWSCROLL)\
	NODE(BDISABLESCRIPTWARN)\
	NODE(BSHOW)\
	NODE(BSHOWCONTEXT)\
	NODE(BRESTORE)\
	NODE(BDIRECTFLYTCK)\
	NODE(BNEEDREFRESH)\
	NODE(BCREATENEW)\
	NODE(BSUBTAB)\
	/*C*/\
	NODE(COOKIE)\
	NODE(CONTEXT)\
	NODE(CLOCKSTR)\
	/*D*/\
	NODE(DMCODE)\
	/*E*/\
	NODE(EXTRA)\
	NODE(EID)\
	NODE(EIDDESC)\
	/*G*/\
	NODE(GAMEID)\
	NODE(GAMENAME)\
	NODE(GHISTORYSTR)\
	/*H*/\
	NODE(HWND)\
	/*I*/\
	NODE(ID)\
	NODE(ITEM)\
	NODE(ISUSECOOKIE)\
	NODE(ISGAME)\
	NODE(ISLOGINED)\
	NODE(ITEMSKIN)\
	NODE(ITEMSIZE)\
	/*J*/\
	NODE(JSON)\
	/*M*/\
	NODE(MSGID)\
	NODE(MPASSPORT)\
	/*N*/\
	NODE(NAME)\
	/*O*/\
	NODE(OPERATETYPE)\
	NODE(OPENLOGINWNDCONTEXT)\
	/*P*/\
	NODE(PID)\
	NODE(PASSPORT)\
	NODE(POPTYPE)\
	/*R*/\
	NODE(REFRESHKEY)\
	NODE(RECT)\
	NODE(REF)\
	NODE(REFDESC)\
	NODE(RSO)\
	NODE(RSODESC)\
	/*S*/\
	NODE(SERVERID)\
	NODE(SERVERNAME)\
	NODE(SESSIONID)\
	/*T*/\
	NODE(TIME)\
	NODE(TITLE)\
	NODE(TAGS)\
	NODE(TAGREF)\
	NODE(TASKNAME)\
	/*U*/\
	NODE(UID)\
	NODE(URL)\
	NODE(UPDATAINFOID)\
	/*W*/\
	NODE(WEBOPENTYPE)\
	/*X*/\
	NODE(XML)\


/// <summary>
///		
/// </summary>
enum XmlId
{
	XML_Unknown = 0,
#define defenum(name) XML_##name,
	__foreach_id(defenum)
#undef defenum
	XML_Max,// 最大化
};

wchar_t* ID2NAME(int id);
XmlId	 NAME2ID(LPCWSTR name);

GPDef.cpp

#include "GPBaseAfx.h"
#include "GPDef.h"

wchar_t* ID2NAME(int id)
{
	if (id<0||id>=XML_Max)
	{
		return L"";
	}
	switch (id)
	{
#define comparecase(tag) case XML_##tag: return L#tag;
		__foreach_id(comparecase)
#undef comparecase
	}
	return L"";
}

XmlId NAME2ID(LPCWSTR name)
{
	if (name == NULL)
		return XML_Unknown;
#define comparename(tag) else if (lstrcmpiW(name, L#tag) == 0) { return XML_##tag; }
	__foreach_id(comparename)
#undef comparename
		return XML_Unknown;
}

GPNameIdT.h

#pragma once

// ID to name示例,通过模板函数实现
template<XmlId id>
class XmlIdToName
{
public:
	static LPCWSTR Name() { return L"Unknown"; }
};

// 通过枚举工具定义所有特化模板类
#define defname(name) \
	template<> class XmlIdToName<XML_##name> \
{ \
public: \
	static LPCWSTR Name() { return L#name; } \
};
__foreach_id(defname)
#undef defname

// 通过ID获取名称
//#define Id2Name(id) XmlIdToName<id>::Name()

文章作者:hgy413
本文地址:https://hgy413.com/4109.html
版权所有 © 转载时必须以链接形式注明作者和原始出处!

18 Responses to “CEF-ID2NAME+NAME2ID模板转换”

  1. #1 canalizadores24h.pt 回复 | 引用 Post:2020-05-10 13:23

    Sweet blog! I found it while surfing around on Yahoo News.
    Do you have any suggestions on how to get listed in Yahoo News?
    I’ve been trying for a while but I never seem to get there!
    Thanks

  2. #2 caldeirasbaxi.pt 回复 | 引用 Post:2020-05-10 14:08

    Thankfulness to my father who stated to me on the topic of this web site, this web site is actually amazing.

  3. Simply wish to say your article is as astonishing.
    The clearness in your post is just cool and i can suppose you are an expert on this subject.
    Well with your permission let me to grab your RSS feed to keep updated
    with coming near near post. Thank you a million and please keep up the gratifying work.

  4. Good post however , I was wanting to know if you could write a litte more on this topic?
    I’d be very thankful if you could elaborate a
    little bit more. Many thanks!

  5. #5 google play codes 回复 | 引用 Post:2020-06-07 07:04

    Amazing issues here. I am very glad to look your article.
    Thanks a lot and I’m taking a look ahead to contact
    you. Will you kindly drop me a mail?

  6. #6 summoners war cheats 回复 | 引用 Post:2020-06-08 14:14

    This paragraph is truly a fastidious one it helps new net visitors, who are wishing for blogging.

  7. Have you ever thought about including a little bit
    more than just your articles? I mean, what you say is valuable and
    all. Nevertheless imagine if you added some great photos or video clips to give your posts more, “pop”!
    Your content is excellent but with pics and videos,
    this blog could certainly be one of the best in its field.
    Amazing blog!

  8. #8 you g 回复 | 引用 Post:2020-06-10 13:37

    My spouse and I stumbled over here by a different
    web address and thought I might as well check things out.

    I like what I see so i am just following you.
    Look forward to looking at your web page repeatedly.

  9. #9 g from 回复 | 引用 Post:2020-06-10 15:36

    These are in fact wonderful ideas in concerning blogging.
    You have touched some pleasant points here. Any way keep
    up wrinting.

  10. #10 g me 回复 | 引用 Post:2020-06-10 17:28

    What’s Taking place i am new to this, I stumbled upon this I have found It
    absolutely helpful and it has helped me out loads.
    I hope to contribute & help different customers like its helped me.
    Great job.

  11. #11 think g 回复 | 引用 Post:2020-06-12 00:08

    Thanks in support of sharing such a pleasant opinion, paragraph is nice, thats why i
    have read it fully

  12. #12 free steam codes 回复 | 引用 Post:2020-06-12 05:28

    Appreciation to my father who informed me on the topic of this blog,
    this web site is in fact amazing.

  13. #13 g like 回复 | 引用 Post:2020-06-12 11:36

    I love your blog.. very nice colors & theme.
    Did you design this website yourself or did you hire someone to do it for you?
    Plz answer back as I’m looking to create my own blog and
    would like to find out where u got this from.
    many thanks

  14. #14 http://web.xorg.cn 回复 | 引用 Post:2020-06-14 04:12

    I read this article fully concerning the comparison of most up-to-date and previous technologies, it’s remarkable article.

  15. #15 king of avalon hack 回复 | 引用 Post:2020-06-14 08:06

    First of all I want to say excellent blog! I
    had a quick question which I’d like to ask if you do not mind.
    I was interested to know how you center yourself
    and clear your head before writing. I’ve had a hard time clearing my mind in getting my
    ideas out. I truly do take pleasure in writing however it just seems like
    the first 10 to 15 minutes are usually lost just trying to figure out how to begin. Any ideas
    or hints? Thanks!

  16. #16 chaos-fun-gamer.de 回复 | 引用 Post:2020-06-14 12:42

    I loved as much as you will receive carried out right here.
    The sketch is attractive, your authored subject matter stylish.
    nonetheless, you command get bought an nervousness over that you wish be delivering the following.
    unwell unquestionably come more formerly again since exactly the same nearly very often inside case you shield this increase.

  17. I love your blog.. very nice colors & theme. Did you make this website yourself
    or did you hire someone to do it for you? Plz reply as I’m looking to construct
    my own blog and would like to find out where u got this from.

    appreciate it

  18. #18 g 回复 | 引用 Post:2020-06-15 23:33

    I love reading through a post that can make men and women think.
    Also, thank you for allowing me to comment!

发表评论