SeExpr

Context.h
Go to the documentation of this file.
1 /*
2 * Copyright Disney Enterprises, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License
6 * and the following modification to it: Section 6 Trademarks.
7 * deleted and replaced with:
8 *
9 * 6. Trademarks. This License does not grant permission to use the
10 * trade names, trademarks, service marks, or product names of the
11 * Licensor and its affiliates, except as required for reproducing
12 * the content of the NOTICE file.
13 *
14 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
16 */
17 #pragma once
18
19 #include <map>
20 #include <string>
21
22 namespace SeExpr2 {
23
24 class Context {
25 public:
27 bool lookupParameter(const std::string& parameterName, std::string& value) const {
28 ParameterMap::const_iterator it = _parameters.find(parameterName);
29 if (it != _parameters.end()) {
30 value = it->second;
31 return true;
32 } else if (_parent)
33 return _parent->lookupParameter(parameterName, value);
34 else
35 return false;
36 }
38 void setParameter(const std::string& parameterName, const std::string& value);
40 Context* createChildContext() const;
41
42 // Parent access uses pointers as it is acceptable to set/get a NULL parent
43 void setParent(const Context* context) { _parent = context; }
44 const Context* getParent() const { return _parent; }
45
46 bool hasContext(const Context* context) const {
47 if (this == context) return true;
48 if (_parent) return _parent->hasContext(context);
49 return false;
50 }
51
53 static Context& global();
54
55 private:
58 Context(const Context&);
59 Context& operator=(const Context&);
60
61 Context(const Context* parent);
63 const Context* _parent;
64
65 // TODO: Use std::map until C++11 is ubiq.
66 typedef std::map<std::string, std::string> ParameterMap;
68 ParameterMap _parameters;
69 };
70 }
SeExpr2::Context::operator=
Context & operator=(const Context &)
SeExpr2::Context::global
static Context & global()
The global default context of the seexpr.
Definition: Context.cpp:29
SeExpr2::Context::createChildContext
Context * createChildContext() const
Create a context that is a child of this context.
Definition: Context.cpp:27
SeExpr2::Context::getParent
const Context * getParent() const
Definition: Context.h:44
SeExpr2::Context::lookupParameter
bool lookupParameter(const std::string &parameterName, std::string &value) const
Lookup a Context parameter by name.
Definition: Context.h:27
SeExpr2::Context
Definition: Context.h:24
SeExpr2
Definition: Context.h:22
SeExpr2::Context::hasContext
bool hasContext(const Context *context) const
Definition: Context.h:46
it
you may not use this file except in compliance with the License and the following modification to it
Definition: license.txt:10
value
For any rgb or hsl value(except for negative s values)
SeExpr2::Context::_parameters
ParameterMap _parameters
Attribute/value pairs.
Definition: Context.h:68
SeExpr2::Context::Context
Context(const Context &)
SeExpr2::Context::setParameter
void setParameter(const std::string &parameterName, const std::string &value)
Set a parameter. NOTE: this must be done when no threads are accessing lookupParameter for safety.
Definition: Context.cpp:23
context
If a scalar is used in a vector context
Definition: userdoc.txt:436
SeExpr2::Context::setParent
void setParent(const Context *context)
Definition: Context.h:43
SeExpr2::Context::_parent
const Context * _parent
The parent scope.
Definition: Context.h:63
SeExpr2::Context::ParameterMap
std::map< std::string, std::string > ParameterMap
Definition: Context.h:66