PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/llmessagetemplateparser.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 80 lines | 43 code | 12 blank | 25 comment | 0 complexity | ab8e18a94f6aa6faf347167ceba45550 MD5 | raw file
 1/** 
 2 * @file llmessagetemplateparser.h
 3 * @brief Classes to parse message template.
 4 *
 5 * $LicenseInfo:firstyear=2000&license=viewerlgpl$
 6 * Second Life Viewer Source Code
 7 * Copyright (C) 2010, Linden Research, Inc.
 8 * 
 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation;
12 * version 2.1 of the License only.
13 * 
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Lesser General Public License for more details.
18 * 
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 * 
23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
24 * $/LicenseInfo$
25 */
26
27#ifndef LL_MESSAGETEMPLATEPARSER_H
28#define LL_MESSAGETEMPLATEPARSER_H
29
30#include <string>
31#include "llmessagetemplate.h"
32
33class LLTemplateTokenizer
34{
35public:
36	LLTemplateTokenizer(const std::string & contents);
37
38	U32 line() const;
39	bool atEOF() const;
40	std::string next();
41
42	bool want(const std::string & token);
43	bool wantEOF();
44private:
45	void inc();
46	void dec();
47	std::string get() const;
48	void error(std::string message = "generic") const;
49
50	struct positioned_token
51	{
52		std::string str;
53		U32 line;
54	};
55	
56	bool mStarted;
57	std::list<positioned_token> mTokens;
58	std::list<positioned_token>::const_iterator mCurrent;
59};
60
61class LLTemplateParser
62{
63public:
64	typedef std::list<LLMessageTemplate *>::const_iterator message_iterator;
65	
66	static LLMessageTemplate * parseMessage(LLTemplateTokenizer & tokens);
67	static LLMessageBlock * parseBlock(LLTemplateTokenizer & tokens);
68	static LLMessageVariable * parseVariable(LLTemplateTokenizer & tokens);
69
70	LLTemplateParser(LLTemplateTokenizer & tokens);
71	message_iterator getMessagesBegin() const;
72	message_iterator getMessagesEnd() const;
73	F32 getVersion() const;
74	
75private:
76	F32 mVersion;
77	std::list<LLMessageTemplate *> mMessages;
78};
79
80#endif