本文整理汇总了C++中TemplateMap类的典型用法代码示例。如果您正苦于以下问题:C++ TemplateMap类的具体用法?C++ TemplateMap怎么用?C++ TemplateMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TemplateMap类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: getTemplate
Template* TemplateMap::getTemplate(const char *proto, const char *text)
{
for (TemplateMap *ptr = mapList; ptr != NULL; ptr = ptr->next)
if (!mir_strcmp(ptr->name, proto))
return ptr->getTemplate(text);
return NULL;
}
开发者ID:kmdtukl,项目名称:miranda-ng,代码行数:8,代码来源:Template.cpp
示例2: getTemplate
Template* TemplateMap::getTemplate(const char *proto, const char *text) {
TemplateMap *ptr;
for (ptr=mapList; ptr!=NULL; ptr=ptr->next) {
if (!strcmp(ptr->name, proto)) {
return ptr->getTemplate(text);
}
}
return NULL;
}
开发者ID:BackupTheBerlios,项目名称:mgoodies-svn,代码行数:9,代码来源:Template.cpp
示例3: TemplateMap
TemplateMap* TemplateMap::add(const char *proto, const char *filename) {
TemplateMap *map;
for (map=mapList; map!=NULL; map=map->next) {
if (!strcmp(map->name, proto)) {
map->clear();
map->setFilename(filename);
return map;
}
}
map = new TemplateMap(proto);
map->setFilename(filename);
map->next = mapList;
mapList = map;
return map;
}
开发者ID:BackupTheBerlios,项目名称:mgoodies-svn,代码行数:15,代码来源:Template.cpp
示例4: applyTemplate
void applyTemplate(const char* dst, const char* src, const TemplateMap& tm) {
ifstream in(src);
setName(in, src);
beGood(in);
ofstream out(dst);
setName(out, dst);
beGood(out);
while(true) {
int c = in.get();
if(in.eof())
break;
if(c == '%') { // template argument start marker
int d = in.get();
if(d == '%') { //literal percent sign
out << '%';
} else {
// find the end
string tempName;
while(!in.eof()) {
if(d == '%') { //template argument end marker
break;
} else if(isspace(d)) {
printf("Broken template file (space in template).\n");
exit(1);
} else {
tempName += (char)d;
}
d = in.get();
}
// apply the template argument
TemplateMap::const_iterator itr = tm.find(tempName);
if(itr == tm.end()) {
printf("Missing template argument: %s\n", tempName.c_str());
exit(1);
}
out << itr->second;
}
} else {
out.put(c);
}
}
}
开发者ID:AliSayed,项目名称:MoSync,代码行数:43,代码来源:util.cpp
示例5: loadTemplateFile
bool TemplateMap::loadTemplateFile(const char *proto, const char *filename, bool onlyInfo) {
FILE* fh;
char lastTemplate[1024], tmp2[1024];
char pathstring[500];
TemplateMap *tmap = TemplateMap::add(proto, filename);
if (filename == NULL || strlen(filename) == 0) {
return false;
}
strcpy(pathstring, filename);
char* pathrun = pathstring + strlen(pathstring);
while ((*pathrun != '\\' && *pathrun != '/') && (pathrun > pathstring)) pathrun--;
pathrun++;
*pathrun = '\0';
fh = fopen(filename, "rt");
if (fh == NULL) {
return false;
}
char store[4096];
bool wasTemplate = false;
char *templateText = NULL;
int templateTextSize = 0;
while (fgets(store, sizeof(store), fh) != NULL) {
if (sscanf(store, "%s", tmp2) == EOF) continue;
//template start
if (!onlyInfo) {
if ( !strncmp(store, "<!--HTMLStart-->", 16) ||
!strncmp(store, "<!--MessageIn-->", 16) ||
!strncmp(store, "<!--MessageOut-->", 17) ||
!strncmp(store, "<!--hMessageIn-->", 17) ||
!strncmp(store, "<!--hMessageOut-->", 18) ||
!strncmp(store, "<!--File-->", 11) ||
!strncmp(store, "<!--hFile-->", 12) ||
!strncmp(store, "<!--URL-->", 10) ||
!strncmp(store, "<!--hURL-->", 11) ||
!strncmp(store, "<!--Status-->", 13) ||
!strncmp(store, "<!--hStatus-->", 14) ||
!strncmp(store, "<!--MessageInGroupStart-->", 26) ||
!strncmp(store, "<!--MessageInGroupInner-->", 26) ||
!strncmp(store, "<!--MessageInGroupEnd-->", 24) ||
!strncmp(store, "<!--hMessageInGroupStart-->", 27) ||
!strncmp(store, "<!--hMessageInGroupInner-->", 27) ||
!strncmp(store, "<!--hMessageInGroupEnd-->", 25) ||
!strncmp(store, "<!--MessageOutGroupStart-->", 27) ||
!strncmp(store, "<!--MessageOutGroupInner-->", 27) ||
!strncmp(store, "<!--MessageOutGroupEnd-->", 25) ||
!strncmp(store, "<!--hMessageOutGroupStart-->", 28) ||
!strncmp(store, "<!--hMessageOutGroupInner-->", 28) ||
!strncmp(store, "<!--hMessageOutGroupEnd-->", 26)
) {
if (wasTemplate) {
tmap->addTemplate(lastTemplate, templateText);
//debugView->writef("1. %s<br>%s", lastTemplate, templateText);
}
if (templateText!=NULL) {
free (templateText);
}
templateText = NULL;
templateTextSize = 0;
wasTemplate = true;
sscanf(store, "<!--%[^-]", lastTemplate);
} else if (wasTemplate) {
Utils::appendText(&templateText, &templateTextSize, "%s", store);
}
}
}
if (wasTemplate) {
tmap->addTemplate(lastTemplate, templateText);
//debugView->writef("2. %s<br>%s", lastTemplate, templateText);
}
fclose(fh);
static const char *groupTemplates[] = {"MessageInGroupStart", "MessageInGroupInner",
"hMessageInGroupStart", "hMessageInGroupInner",
"MessageOutGroupStart", "MessageOutGroupInner",
"hMessageOutGroupStart", "hMessageOutGroupInner"};
tmap->grouping = true;
for (int i=0; i<8; i++) {
if (tmap->getTemplate(groupTemplates[i])== NULL) {
tmap->grouping = false;
break;
}
}
return true;
}
开发者ID:BackupTheBerlios,项目名称:mgoodies-svn,代码行数:85,代码来源:Template.cpp
示例6: fopen
TemplateMap* TemplateMap::loadTemplateFile(const char *id, const char *filename, bool onlyInfo) {
FILE* fh;
char lastTemplate[1024], tmp2[1024];
unsigned int i=0;
TemplateMap *tmap;
if (filename == NULL || strlen(filename) == 0) {
return NULL;
}
fh = fopen(filename, "rt");
if (fh == NULL) {
return NULL;
}
if (!onlyInfo) {
tmap = TemplateMap::add(id, filename);
} else {
tmap = new TemplateMap(id);
}
char store[4096];
bool wasTemplate = false;
char *templateText = NULL;
int templateTextSize = 0;
while (fgets(store, sizeof(store), fh) != NULL) {
if (sscanf(store, "%s", tmp2) == EOF) continue;
//template start
bool bFound = false;
for (unsigned i = 0; i < sizeof(templateNames) / sizeof (templateNames[0]); i++) {
if (!strncmp(store, templateNames[i].tokenString, templateNames[i].tokenLen)) {
bFound = true;
break;
}
}
if (bFound) {
if (wasTemplate) {
tmap->addTemplate(lastTemplate, templateText);
}
if (templateText!=NULL) {
free (templateText);
}
templateText = NULL;
templateTextSize = 0;
wasTemplate = true;
sscanf(store, "<!--%[^-]", lastTemplate);
} else if (wasTemplate) {
Utils::appendText(&templateText, &templateTextSize, "%s", store);
}
}
if (wasTemplate) {
tmap->addTemplate(lastTemplate, templateText);
}
fclose(fh);
static const char *groupTemplates[] = {"MessageInGroupStart", "MessageInGroupInner",
"hMessageInGroupStart", "hMessageInGroupInner",
"MessageOutGroupStart", "MessageOutGroupInner",
"hMessageOutGroupStart", "hMessageOutGroupInner"};
tmap->grouping = true;
for (i = 0; i<SIZEOF(groupTemplates); i++) {
if (tmap->getTemplate(groupTemplates[i])== NULL) {
tmap->grouping = false;
break;
}
}
static const char *rtlTemplates[] = {"MessageInRTL", "MessageOutRTL"}; //"HTMLStartRTL",
tmap->rtl = true;
for (i=0; i<SIZEOF(rtlTemplates); i++) {
if (tmap->getTemplate(rtlTemplates[i])== NULL) {
tmap->rtl = false;
break;
}
}
return tmap;
}
开发者ID:BackupTheBerlios,项目名称:mgoodies-svn,代码行数:71,代码来源:Template.cpp
示例7: getRealContact
void TemplateHTMLBuilder::appendEventTemplate(IEView *view, IEVIEWEVENT *event, ProtocolSettings* protoSettings) {
DBVARIANT dbv;
CONTACTINFO ci;
HANDLE hRealContact;
char *szRealProto = NULL;
char tempBase[1024];
char *szBase=NULL;
char tempStr[1024];
char *szNoAvatar=NULL;
char szCID[32];
char *szName = NULL;
char *szNameIn = NULL;
char *szNameOut = NULL;
char *szUIN = NULL;
char *szUINIn = NULL;
char *szUINOut = NULL;
char *szNickIn = NULL;
char *szNickOut = NULL;
char *szStatusMsg = NULL;
char *szAvatar = NULL;
char *szAvatarIn = NULL;
char *szAvatarOut = NULL;
char *szText = NULL;
char *szProto = NULL;
char *szFileDesc = NULL;
const char *tmpltName[2];
bool isGrouping = false;
// DWORD today = (DWORD)time(NULL);
// today = today - today % 86400;
if (protoSettings == NULL) {
return;
}
hRealContact = getRealContact(event->hContact);
szRealProto = getProto(hRealContact);
szProto = getProto(event->pszProto, event->hContact);
tempBase[0]='\0';
TemplateMap *tmpm = getTemplateMap(protoSettings);
if (tmpm!=NULL) {
strcpy(tempBase, "file://");
strcat(tempBase, tmpm->getFilename());
char* pathrun = tempBase + strlen(tempBase);
while ((*pathrun != '\\' && *pathrun != '/') && (pathrun > tempBase)) pathrun--;
pathrun++;
*pathrun = '\0';
isGrouping = tmpm->isGrouping();
}
szBase = Utils::UTF8Encode(tempBase);
if (event->hContact != NULL) {
getUINs(event->hContact, szUINIn, szUINOut);
}
if (event->hContact != NULL) {
szNameOut = getEncodedContactName(NULL, szProto, szRealProto);
szNameIn = getEncodedContactName(event->hContact, szProto, szRealProto);
} else {
szNameOut = Utils::dupString(" ");
szNameIn = Utils::dupString(" ");
}
sprintf(tempStr, "%snoavatar.jpg", tempBase);
szNoAvatar = Utils::UTF8Encode(tempStr);
if(event->hContact != NULL) {
szAvatarIn = getAvatar(event->hContact, szRealProto);
}
if (szAvatarIn == NULL) {
szAvatarIn = Utils::dupString(szNoAvatar);
}
szAvatarOut = getAvatar(NULL, szRealProto);
if (szAvatarOut == NULL) {
szAvatarOut = Utils::dupString(szNoAvatar);
}
if(event->hContact != NULL) {
if (!DBGetContactSetting(event->hContact, "CList", "StatusMsg",&dbv)) {
if (strlen(dbv.pszVal) > 0) {
szStatusMsg = Utils::UTF8Encode(dbv.pszVal);
}
DBFreeVariant(&dbv);
}
}
ZeroMemory(&ci, sizeof(ci));
ci.cbSize = sizeof(ci);
ci.hContact = event->hContact;
ci.szProto = szProto;
ci.dwFlag = CNF_NICK | CNF_TCHAR;
if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) & ci)) {
szNickIn = encodeUTF8(event->hContact, szRealProto, ci.pszVal, ENF_NAMESMILEYS, true);
}
ZeroMemory(&ci, sizeof(ci));
ci.cbSize = sizeof(ci);
ci.hContact = NULL;
ci.szProto = szProto;
ci.dwFlag = CNF_NICK | CNF_TCHAR;
if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) & ci)) {
szNickOut = encodeUTF8(event->hContact, szRealProto, ci.pszVal, ENF_NAMESMILEYS, true);
}
IEVIEWEVENTDATA* eventData = event->eventData;
for (int eventIdx = 0; eventData!=NULL && (eventIdx < event->count || event->count==-1); eventData = eventData->next, eventIdx++) {
int outputSize;
char *output;
//.........这里部分代码省略.........
开发者ID:TonyAlloa,项目名称:miranda-dev,代码行数:101,代码来源:TemplateHTMLBuilder.cpp
示例8: strcpy
void TemplateHTMLBuilder::buildHead(IEView *view, IEVIEWEVENT *event) {
DBVARIANT dbv;
CONTACTINFO ci;
char szBase[1024];
char szNoAvatar[1024];
char *szProto = NULL;
char *szNameIn = NULL;
char *szNameOut = NULL;
char *szAvatarIn = NULL;
char *szAvatarOut = NULL;
int outputSize;
char *output;
output = NULL;
szProto = Utils::dupString((char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) event->hContact, 0));
szBase[0]='\0';
TemplateMap *tmpm = (event->dwFlags & IEEF_RTL) ? TemplateMap::getTemplateMap("default_rtl") : TemplateMap::getTemplateMap("default");
if (tmpm!=NULL) {
strcpy(szBase, tmpm->getFilename());
char* pathrun = szBase + strlen(szBase);
while ((*pathrun != '\\' && *pathrun != '/') && (pathrun > szBase)) pathrun--;
pathrun++;
*pathrun = '\0';
}
sprintf(szNoAvatar, "%snoavatar.jpg", szBase);
if (Options::getTemplatesFlags() & Options::LOG_SHOW_NICKNAMES) {
ZeroMemory(&ci, sizeof(ci));
ci.cbSize = sizeof(ci);
ci.hContact = NULL;
ci.szProto = szProto;
ci.dwFlag = CNF_DISPLAY;
if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) & ci)) {
szNameOut = encodeUTF8(ci.pszVal, NULL, false);
}
szNameIn = encodeUTF8((char *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM) event->hContact, 0), NULL, false);
} else {
szNameOut = Utils::dupString(" ");
szNameIn = Utils::dupString(" ");
}
if (!DBGetContactSetting(event->hContact, "ContactPhoto", "File",&dbv)) {
if (strlen(dbv.pszVal) > 0) {
szAvatarIn = Utils::dupString(dbv.pszVal);
Utils::convertPath(szAvatarIn);
}
DBFreeVariant(&dbv);
}
if (szAvatarIn == NULL) {
szAvatarIn = Utils::dupString(szNoAvatar);
}
if (!DBGetContactSetting(NULL, "ContactPhoto", "File",&dbv)) {
if (strlen(dbv.pszVal) > 0) {
szAvatarOut = Utils::dupString(dbv.pszVal);
Utils::convertPath(szAvatarOut);
}
DBFreeVariant(&dbv);
}
if (szAvatarOut == NULL) {
szAvatarOut = Utils::dupString(szNoAvatar);
}
Template *tmplt = (event->dwFlags & IEEF_RTL) ? TemplateMap::getTemplate("default_rtl", "HTMLStart") : TemplateMap::getTemplate("default", "HTMLStart");
if (tmplt!=NULL) {
for (Token *token = tmplt->getTokens();token!=NULL;token=token->getNext()) {
const char *tokenVal;
tokenVal = NULL;
switch (token->getType()) {
case Token::PLAIN:
tokenVal = token->getText();
break;
case Token::BASE:
tokenVal = szBase;
break;
case Token::NAMEIN:
tokenVal = szNameIn;
break;
case Token::NAMEOUT:
tokenVal = szNameOut;
break;
case Token::AVATARIN:
tokenVal = szAvatarIn;
break;
case Token::AVATAROUT:
tokenVal = szAvatarOut;
break;
case Token::PROTO:
tokenVal = szProto;
break;
}
if (tokenVal != NULL) {
Utils::appendText(&output, &outputSize, "%s", tokenVal);
}
}
}
if (output != NULL) {
view->write(output);
free(output);
}
if (szProto!=NULL) delete szProto;
if (szAvatarIn!=NULL) delete szAvatarIn;
if (szAvatarOut!=NULL) delete szAvatarOut;
if (szNameIn!=NULL) delete szNameIn;
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:mgoodies-svn,代码行数:101,代码来源:TemplateHTMLBuilder.cpp
示例9: getRealContact
void TemplateHTMLBuilder::appendEventTemplate(IEView *view, IEVIEWEVENT *event, ProtocolSettings* protoSettings)
{
DBVARIANT dbv;
CONTACTINFO ci;
char *szRealProto = NULL;
char tempBase[1024];
char *szBase=NULL;
char tempStr[1024];
char *szNoAvatar=NULL;
char szCID[32];
char *szName = NULL;
char *szNameIn = NULL;
char *szNameOut = NULL;
char *szUIN = NULL;
char *szUINIn = NULL;
char *szUINOut = NULL;
char *szNickIn = NULL;
char *szNickOut = NULL;
char *szStatusMsg = NULL;
char *szAvatar = NULL;
char *szAvatarIn = NULL;
char *szAvatarOut = NULL;
char *szText = NULL;
char *szProto = NULL;
char *szFileDesc = NULL;
const char *tmpltName[2];
bool isGrouping = false;
if (protoSettings == NULL)
return;
MCONTACT hRealContact = getRealContact(event->hContact);
szRealProto = getProto(hRealContact);
szProto = getProto(event->pszProto, event->hContact);
tempBase[0]='\0';
TemplateMap *tmpm = getTemplateMap(protoSettings);
if (tmpm!=NULL) {
strcpy(tempBase, "file://");
strcat(tempBase, tmpm->getFilename());
char* pathrun = tempBase + strlen(tempBase);
while ((*pathrun != '\\' && *pathrun != '/') && (pathrun > tempBase)) pathrun--;
pathrun++;
*pathrun = '\0';
isGrouping = tmpm->isGrouping();
}
szBase = mir_utf8encode(tempBase);
if (event->hContact != NULL)
getUINs(event->hContact, szUINIn, szUINOut);
if (event->hContact != NULL) {
szNameOut = getEncodedContactName(NULL, szProto, szRealProto);
szNameIn = getEncodedContactName(event->hContact, szProto, szRealProto);
}
else {
szNameOut = mir_strdup(" ");
szNameIn = mir_strdup(" ");
}
TCHAR szNoAvatarPath[MAX_PATH];
mir_sntprintf(szNoAvatarPath, SIZEOF(szNoAvatarPath), _T("%s"), _A2T(protoSettings->getSRMMTemplateFilename()));
TCHAR *szNoAvatarPathTmp = _tcsrchr(szNoAvatarPath, '\\');
if (szNoAvatarPathTmp != NULL)
*szNoAvatarPathTmp = 0;
_tcscat(szNoAvatarPath, _T("\\noavatar.png"));
if (_taccess(szNoAvatarPath, 0) == -1)
mir_snprintf(tempStr, SIZEOF(tempStr), "%snoavatar.jpg", tempBase);
else
mir_snprintf(tempStr, SIZEOF(tempStr), "%snoavatar.png", tempBase);
szNoAvatar = mir_utf8encode(tempStr);
if(event->hContact != NULL)
szAvatarIn = getAvatar(event->hContact, szRealProto);
if (szAvatarIn == NULL)
szAvatarIn = mir_strdup(szNoAvatar);
szAvatarOut = getAvatar(NULL, szRealProto);
if (szAvatarOut == NULL)
szAvatarOut = mir_strdup(szNoAvatar);
if(event->hContact != NULL) {
if (!db_get(event->hContact, "CList", "StatusMsg",&dbv)) {
if (strlen(dbv.pszVal) > 0)
szStatusMsg = mir_utf8encode(dbv.pszVal);
db_free(&dbv);
}
}
ZeroMemory(&ci, sizeof(ci));
ci.cbSize = sizeof(ci);
ci.hContact = event->hContact;
ci.szProto = szProto;
ci.dwFlag = CNF_NICK | CNF_TCHAR;
if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) & ci))
szNickIn = encodeUTF8(event->hContact, szRealProto, ci.pszVal, ENF_NAMESMILEYS, true);
ZeroMemory(&ci, sizeof(ci));
ci.cbSize = sizeof(ci);
ci.hContact = NULL;
ci.szProto = szProto;
ci.dwFlag = CNF_NICK | CNF_TCHAR;
if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) & ci))
szNickOut = encodeUTF8(event->hContact, szRealProto, ci.pszVal, ENF_NAMESMILEYS, true);
//.........这里部分代码省略.........
开发者ID:0xmono,项目名称:miranda-ng,代码行数:101,代码来源:TemplateHTMLBuilder.cpp
示例10: fopen
TemplateMap* TemplateMap::loadTemplateFile(const char *id, const char *filename, bool onlyInfo)
{
char lastTemplate[1024], tmp2[1024];
unsigned int i = 0;
if (filename == NULL || mir_strlen(filename) == 0)
return NULL;
FILE *fh = fopen(filename, "rt");
if (fh == NULL)
return NULL;
TemplateMap *tmap;
if (!onlyInfo)
tmap = TemplateMap::add(id, filename);
else
tmap = new TemplateMap(id);
char store[4096];
bool wasTemplate = false;
CMStringA templateText;
while (fgets(store, sizeof(store), fh) != NULL) {
if (sscanf(store, "%s", tmp2) == EOF) continue;
//template start
bool bFound = false;
for (unsigned i = 0; i < _countof(templateNames); i++) {
if (!strncmp(store, templateNames[i].tokenString, templateNames[i].tokenLen)) {
bFound = true;
break;
}
}
if (bFound) {
if (wasTemplate)
tmap->addTemplate(lastTemplate, templateText);
templateText.Empty();
wasTemplate = true;
sscanf(store, "<!--%[^-]", lastTemplate);
}
else if (wasTemplate)
templateText.Append(store);
}
if (wasTemplate)
tmap->addTemplate(lastTemplate, templateText);
templateText.Empty();
fclose(fh);
static const char *groupTemplates[] = { "MessageInGroupStart", "MessageInGroupInner",
"hMessageInGroupStart", "hMessageInGroupInner",
"MessageOutGroupStart", "MessageOutGroupInner",
"hMessageOutGroupStart", "hMessageOutGroupInner" };
tmap->grouping = true;
for (i = 0; i < _countof(groupTemplates); i++) {
if (tmap->getTemplate(groupTemplates[i]) == NULL) {
tmap->grouping = false;
break;
}
}
static const char *rtlTemplates[] = { "MessageInRTL", "MessageOutRTL" }; //"HTMLStartRTL",
tmap->rtl = true;
for (i = 0; i < _countof(rtlTemplates); i++) {
if (tmap->getTemplate(rtlTemplates[i]) == NULL) {
tmap->rtl = false;
break;
}
}
return tmap;
}
开发者ID:kmdtukl,项目名称:miranda-ng,代码行数:67,代码来源:Template.cpp
注:本文中的TemplateMap类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论