SeExpr

SeContext.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 class SeContext {
23 public:
25 bool lookupParameter(const std::string& parameterName, std::string& value) const {
26 ParameterMap::const_iterator it = _parameters.find(parameterName);
27 if (it != _parameters.end()) {
28 value = it->second;
29 return true;
30 } else if (_parent)
31 return _parent->lookupParameter(parameterName, value);
32 else
33 return false;
34 }
36 void setParameter(const std::string& parameterName, const std::string& value);
38 SeContext* createChildContext() const;
39
40 // Parent access uses pointers as it is acceptable to set/get a NULL parent
41 void setParent(const SeContext* context) { _parent = context; }
42 const SeContext* getParent() const { return _parent; }
43
44 bool hasContext(const SeContext* context) const {
45 if (this == context) return true;
46 if (_parent) return _parent->hasContext(context);
47 return false;
48 }
49
51 static SeContext& global();
52
53 private:
56 SeContext(const SeContext&);
57 SeContext& operator=(const SeContext&);
58
59 SeContext(const SeContext* parent);
61 const SeContext* _parent;
62
63 // TODO: Use std::map until C++11 is ubiq.
64 typedef std::map<std::string, std::string> ParameterMap;
66 ParameterMap _parameters;
67 };
SeContext::_parent
const SeContext * _parent
The parent scope.
Definition: SeContext.h:61
SeContext::createChildContext
SeContext * createChildContext() const
Create a context that is a child of this context.
Definition: SeContext.cpp:25
SeContext::ParameterMap
std::map< std::string, std::string > ParameterMap
Definition: SeContext.h:64
SeContext::getParent
const SeContext * getParent() const
Definition: SeContext.h:42
SeContext::operator=
SeContext & operator=(const SeContext &)
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)
SeContext::hasContext
bool hasContext(const SeContext *context) const
Definition: SeContext.h:44
SeContext::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: SeContext.cpp:21
SeContext
Definition: SeContext.h:22
SeContext::_parameters
ParameterMap _parameters
Attribute/value pairs.
Definition: SeContext.h:66
SeContext::global
static SeContext & global()
The global default context of the seexpr.
Definition: SeContext.cpp:27
SeContext::SeContext
SeContext(const SeContext &)
context
If a scalar is used in a vector context
Definition: userdoc.txt:436
SeContext::lookupParameter
bool lookupParameter(const std::string &parameterName, std::string &value) const
Lookup a SeContext parameter by name.
Definition: SeContext.h:25
SeContext::setParent
void setParent(const SeContext *context)
Definition: SeContext.h:41