RuntimeId.cpp
Go to the documentation of this file.
1 #include "RuntimeId.hpp"
2 #include "static_warning.hpp"
3 #include <iostream>
4 #include "Context.hpp"
5 #include "SS.hpp"
6 
7 namespace iv
8 {
9 
10 void RuntimeId_WarningIdDoesNotExist( Context * context, char const * type_name, char const * persistent_name )
11 {
12  context->log( SRC_INFO, iv::Defs::Log::Warning, "RuntimeId ", type_name, " with persistent name '", persistent_name, "' does not exist. Using InvalidId instead." );
13 }
14 
16 {
17  if( !this->_dict )
18  this->_dict = new runtime_id::Dictionary;
19  return this->_dict;
20 }
21 
22 namespace runtime_id
23 {
24 
26  next_free_runtime_id( Dictionary::InvalidRuntimeId + 1 ),
27  locked( false )
28 {
29 }
30 
32 {
33  this->locked = true;
34 }
35 
36 int Dictionary::create( const char * persistent_name, char const * type_name )
37 {
38  if( this->locked )
39  runtime_warning( SRC_INFO, SS()<<"RuntimeId "<<type_name<<" id already locked (someone does not want new ids to be created). Creating id '"<<persistent_name<<"' anyways, but the functionality associated with whoever locked it may be limited for this id."<<SS::c_str() );
40 
41  if( this->p2r.count( persistent_name ) )
42  {
43  //runtime_warning( SRC_INFO, SS()<<"RuntimeId "<<type_name<<": Persistent id '"<<persistent_name<<"' already exists. Definitions will have the same runtime name."<<SS::c_str() );
44 
45  int runtime_name = this->p2r.at( persistent_name );
46  return runtime_name;
47  }
48 
49  int new_id = this->next_free_runtime_id++;
50  this->p2r[ persistent_name ] = new_id;
51  this->r2p[ new_id ] = persistent_name;
52  return new_id;
53 }
54 
55 std::string Dictionary::runtime_to_persistent( int runtime )
56 {
57  auto it = this->r2p.find( runtime );
58  if( it != this->r2p.end() )
59  return it->second;
60  else
61  return "InvalidRuntimeId";
62 }
63 
64 int Dictionary::persistent_to_runtime( const char * persistent )
65 {
66  auto it = this->p2r.find( persistent );
67  if( it != this->p2r.end() )
68  return it->second;
69  else
71 }
72 
73 int Dictionary::runtime_validate( int runtime )
74 {
75  if( this->r2p.count( runtime ) )
76  return runtime;
77  else
79 }
80 
82 {
83  return this->next_free_runtime_id;
84 }
85 
86 }
87 }