# Hurricane VLSI Database

List of all members | Public Member Functions
Hurricane::JsonStack Class Reference
JSON Support

JSON Parser Stack. More...

## Public Member Functions
size_t | size () const
template<typename T >
void | push_back (const std::string &, T)
void | pop_back (size_t count=1)
int | rhas (const std::string &) const
template<typename T >
T | as (const std::string &) const
template<typename T >
T | as (int) const
void | push_back_dbo (DBo *)
void | pop_back_dbo ()
DBo * | back_dbo () const
vector< JsonObject * > & | jobjects ()
template<typename T >
T | getEntity (unsigned int) const
void | addEntity (unsigned int jsonId, Entity *)
void | print (std::ostream &) const

## Detailed Description

JSON Parser Stack.

The JSON parser stack contains three separate stacks and a lookup table:

1. The `attribute` stack. Objects that have been translated from JSON to the Hurricane database (or POD objects).
2. The `dbo` stack, similar to the previous one, but contains only objects whose base class is DBo.
3. The JsonObject stack. The stack of objects currently under parsing.
4. A lookup table for the Entity, between the Hurricane `id` and the JSON `id`.

## Member Function Documentation

## ◆ size()

size_t Hurricane::JsonStack::size | ( |  | ) | const
| inline

Returns: The size of the attribute stack.

## ◆ push_back()

template<typename T >

void Hurricane::JsonStack::push_back | ( | const std::string & | key,
|  | T | hobject
| ) |  |
| inline

Parameters

  key | Key associated to `hobject`
  hobject | The attribute object.

Push back (on top) an element on the attribute stack.

References Hurricane::demangle().

Referenced by Hurricane::JsonObject::update().

## ◆ pop_back()

void Hurricane::JsonStack::pop_back | ( | size_t | count = `1` | ) |
| inline

Parameters

  count | The number of element to pop.

Remove `count` element(s) from the top of the stack.

Referenced by Hurricane::JsonObject::update().

## ◆ rhas()

int Hurricane::JsonStack::rhas | ( | const std::string & | key | ) | const
| inline

Parameters

  key | The key element's to look for.

Returns
  the index of the element, from the top.

The function name's stands for "Reverse HAS". Search from the top of the attribute stack downward an element with `key`. Return an index from the top of the stack, that is, the end of the vector. The returned index is a negative value, for exemple the element on top of the stack has an index of `-1`. If no element with a matching key is found, returns 0.

References Hurricane::demangle().

Referenced by Hurricane::JsonObject::get().

## ◆ as() [1/2]

template<typename T >

T Hurricane::JsonStack::as | ( | const std::string & | key | ) | const
| inline

Parameters

  key | The key's element to search.

Returns
  The element, casted as type T.

Search an element with key matching `key`, from the top of the stack. If found, returns the element casted as type `T`. As the cast operation uses `boost::any_cast<>`, the exact type `T` must be used (not a base class of `T`), otherwise the cast will fail and an exception will be thrown.

References Hurricane::demangle().

Referenced by Hurricane::JsonObject::get().

## ◆ as() [2/2]

template<typename T >

T Hurricane::JsonStack::as | ( | int | index | ) | const
| inline

Parameters

  index | the position of the element to convert.

Returns
  The element, casted as type T.

Cast the element at `index` into type T. As the cast operation uses `boost::any_cast<>`, the exact type `T` must be used (not a base class of `T`), otherwise the cast will fail and an exception will be thrown.

A positive or null index means the element must be taken from the bottom of the stack and a stictly negative one means from the top of the stack.

## ◆ push_back_dbo()

void Hurricane::JsonStack::push_back_dbo | ( | DBo * | dbo | ) |
| inline

Parameters

  dbo | The DataBase object to push back.

Dedicated stack to push objects after they had been casted into the DBo* base class. We need to create this separate stack from the attribute stack due to the inability of `boost::any_cast<>` to use a base class.

## ◆ pop_back_dbo()

void Hurricane::JsonStack::pop_back_dbo | ( |  | ) |
| inline

Remove one element from the top of the DBo* stack.

## ◆ back_dbo()

DBo * Hurricane::JsonStack::back_dbo | ( |  | ) | const
| inline

Returns: The elemet at the top of the DBo* stack.

## ◆ jobjects()

vector< JsonObject * > & Hurricane::JsonStack::jobjects | ( |  | ) |
| inline

Returns: the stack of JSON objects, for direct manipulation by the involded parties.

Referenced by Hurricane::JsonObject::jget().

## ◆ getEntity()

template<typename T >

T Hurricane::JsonStack::getEntity | ( | unsigned int | jsonId | ) | const
| inline

Returns: The entity, casted as type `T`.

Find an Entity with the JSON id `jsonId` and cast it into type `T`.

Obviously, this Entity must have been registered with a call to addEntity() before.

## ◆ addEntity()

void Hurricane::JsonStack::addEntity | ( | unsigned int | jsonId,
|  | Entity * | entity
| ) |  |

Parameters

  jsonId | the `id` of the Entity, in the JSON file
  entity | the associated Entity.

When parsing a DataBase object not in blob mode, we cannot restore the ids of the Entities as they are in the file. Thus when an Entity is re-created, it comes with a different id. So we have to keep track of the association between this newbox id (in the Hurricane database) and the one in the JSON file.

This function adds such an association.

## ◆ print()

void Hurricane::JsonStack::print | ( | std::ostream & | o | ) | const

Dump the contents of the attribute stack int the stream `o`. For debugging purposes.

The documentation for this class was generated from the following files:

- JsonObject.h
- JsonObject.dox

Generated by doxygen 1.8.14 on Sun Mar 8 2020 | Return to top of page

Hurricane VLSI Database | Copyright © 2000-2016 Bull S.A. All rights reserved