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
22class 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);
39
40 // Parent access uses pointers as it is acceptable to set/get a NULL parent
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:
58
59 SeContext(const SeContext* parent);
62
63 // TODO: Use std::map until C++11 is ubiq.
64 typedef std::map<std::string, std::string> ParameterMap;
67};
std::map< std::string, std::string > ParameterMap
Definition: SeContext.h:64
ParameterMap _parameters
Attribute/value pairs.
Definition: SeContext.h:66
bool lookupParameter(const std::string &parameterName, std::string &value) const
Lookup a SeContext parameter by name.
Definition: SeContext.h:25
SeContext(const SeContext &)
SeContext * createChildContext() const
Create a context that is a child of this context.
Definition: SeContext.cpp:25
const SeContext * _parent
The parent scope.
Definition: SeContext.h:61
bool hasContext(const SeContext *context) const
Definition: SeContext.h:44
void setParent(const SeContext *context)
Definition: SeContext.h:41
SeContext & operator=(const SeContext &)
static SeContext & global()
The global default context of the seexpr.
Definition: SeContext.cpp:27
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
const SeContext * getParent() const
Definition: SeContext.h:42
you may not use this file except in compliance with the License and the following modification to it
Definition: license.txt:10
If a scalar is used in a vector context
Definition: userdoc.txt:436
For any rgb or hsl value(except for negative s values)