PageRenderTime 15ms CodeModel.GetById 11ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmath/llcalcparser.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 63 lines | 30 code | 7 blank | 26 comment | 6 complexity | aa5cfbb077bdfe44667301d33a523839 MD5 | raw file
 1/*
 2 *  LLCalcParser.cpp
 3 *  Copyright 2008 Aimee Walton.
 4 * $LicenseInfo:firstyear=2008&license=viewerlgpl$
 5 * Second Life Viewer Source Code
 6 * Copyright (C) 2008, Linden Research, Inc.
 7 * 
 8 * This library is free software; you can redistribute it and/or
 9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation;
11 * version 2.1 of the License only.
12 * 
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * Lesser General Public License for more details.
17 * 
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 * 
22 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
23 * $/LicenseInfo$
24 *
25 */
26
27#include "linden_common.h"
28
29#include "llcalcparser.h"
30using namespace boost::spirit::classic;
31
32F32 LLCalcParser::lookup(const std::string::iterator& start, const std::string::iterator& end) const
33{
34	LLCalc::calc_map_t::iterator iter;
35
36	std::string name(start, end);
37	
38	if (mConstants)
39	{
40		iter = mConstants->find(name);
41		if (iter != mConstants->end())
42		{
43			return (*iter).second;
44		}
45	}
46	else
47	{
48		// This should never happen!
49		throw_(end, std::string("Missing constants table"));
50	}
51	
52	if (mVariables)
53	{
54		iter = mVariables->find(name);
55		if (iter != mVariables->end())
56		{
57			return (*iter).second;
58		}
59	}
60	
61	throw_(end, std::string("Unknown symbol " + name));
62	return 0.f;
63}