Skip to content

Commit

Permalink
add totalinvtracker as known type so archetypes can init buypol with one
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearkatie committed Jan 30, 2024
1 parent 17b7c05 commit bbb20b4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
10 changes: 9 additions & 1 deletion cli/cycpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,14 @@
('{0}::toolkit::ResBuf'.format(CYCNS), CYCNS + '::Product'),
('{0}::toolkit::ResBuf'.format(CYCNS), CYCNS + '::Material'),
'{0}::toolkit::ResMap'.format(CYCNS),
'{0}::toolkit::TotalInvTracker'.format(CYCNS),
('{0}::toolkit::TotalInvTracker'.format(CYCNS), '{0}::toolkit::ResBuf'.format(CYCNS), CYCNS + '::Material'),
}

TEMPLATES = {'std::vector', 'std::set', 'std::list', 'std::pair',
'std::map', '{0}::toolkit::ResBuf'.format(CYCNS),
CYCNS + '::toolkit::ResMap',}
CYCNS + '::toolkit::ResMap',
CYCNS + '::toolkit::TotalInvTracker',}

WRANGLERS = {
'{0}::Agent'.format(CYCNS),
Expand Down Expand Up @@ -1079,6 +1082,7 @@ def impl(self, ind=" "):
"m->{var}.capacity());\n"),
CYCNS + '::toolkit::ResBuf': "{var}.capacity(m->{var}.capacity());\n",
CYCNS + '::toolkit::ResMap': '{var}.obj_ids(m->obj_ids());\n',
CYCNS + '::toolkit::TotalInvTracker': "{var}.capacity();\n",
}

class InitFromDbFilter(CodeGeneratorFilter):
Expand Down Expand Up @@ -1145,6 +1149,7 @@ def impl(self, ind=" "):
CYCNS + '::toolkit::ResBuf': '{var}.capacity({capacity});\n',
CYCNS + '::toolkit::ResMap': (
'{var}.obj_ids(qr.GetVal<{tstr}>("{var}"))\n;'),
CYCNS + '::toolkit::TotalInvTracker': '{var}.capacity();\n',
}


Expand Down Expand Up @@ -1893,6 +1898,7 @@ def impl(self, ind=" "):
CYCNS + '::toolkit::ResourceBuff': None,
CYCNS + '::toolkit::ResBuf': None,
CYCNS + '::toolkit::ResMap': '{var}.obj_ids()',
CYCNS + '::Toolkit::TotalInvTracker': None,
}


Expand Down Expand Up @@ -1947,6 +1953,7 @@ def impl(self, ind=" "):
'invs[\"{var}\"] = {var}.PopNRes({var}.count());\n'
'{var}.Push(invs["{var}"]);\n'),
CYCNS + '::toolkit::ResMap': "invs[\"{var}\"] = {var}.ResValues();\n",
CYCNS + '::toolkit::TotalInvTracker': ';\n',
}


Expand Down Expand Up @@ -1995,6 +2002,7 @@ def impl(self, ind=" "):
CYCNS + '::toolkit::ResourceBuff': "{var}.PushAll(inv[\"{var}\"]);\n",
CYCNS + '::toolkit::ResBuf': "{var}.Push(inv[\"{var}\"]);\n",
CYCNS + '::toolkit::ResMap': "{var}.ResValues(inv[\"{var}\"]);\n",
CYCNS + '::toolkit::TotalInvTracker': ";\n",
}


Expand Down
15 changes: 14 additions & 1 deletion cyclus/gentypesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,15 @@ def convert_to_cpp(self, x, t):
'std::list': 'std_list',
'std::vector': 'std_vector',
'cyclus::toolkit::ResBuf': 'cpp_cyclus.ResBuf',
'cyclus::toolkit::TotalInvTracker': 'cpp_cyclus.TotalInvTracker',
'cyclus::toolkit::ResMap': 'cpp_cyclus.ResMap',
}

# Don't include the base resource class here since it is pure virtual.
RESOURCES = ['MATERIAL', 'PRODUCT']

INVENTORIES = ['cyclus::toolkit::ResourceBuff', 'cyclus::toolkit::ResBuf',
'cyclus::toolkit::ResMap']
'cyclus::toolkit::TotalInvTracker', 'cyclus::toolkit::ResMap']

USE_SHARED_PTR = ('MATERIAL', 'PRODUCT', 'cyclus::Material', 'cyclus::Product')

Expand Down Expand Up @@ -419,6 +420,7 @@ def convert_to_cpp(self, x, t):
'std::list': 'std_list',
'std::vector': 'std_vector',
'cyclus::toolkit::ResBuf': 'res_buf',
'cyclus::toolkit::TotalInvTracker': 'total_inv_tracker',
'cyclus::toolkit::ResMap': 'res_map',
}

Expand Down Expand Up @@ -453,6 +455,7 @@ def convert_to_cpp(self, x, t):
'std::list': 'List',
'std::vector': 'Vector',
'cyclus::toolkit::ResBuf': 'ResBuf',
'cyclus::toolkit::TotalInvTracker': 'total_inv_tracker',
'cyclus::toolkit::ResMap': 'ResMap',
}

Expand Down Expand Up @@ -489,6 +492,7 @@ def convert_to_cpp(self, x, t):
'std::list': ('val',),
'std::vector': ('val',),
'cyclus::toolkit::ResBuf': ('val',),
'cyclus::toolkit::TotalInvTracker': ('val',),
'cyclus::toolkit::ResMap': ('key', 'val'),
}

Expand All @@ -509,6 +513,7 @@ def convert_to_cpp(self, x, t):
'std::list': 'np.NPY_OBJECT',
'std::vector': 'np.NPY_OBJECT',
'cyclus::toolkit::ResBuf': 'np.NPY_OBJECT',
'cyclus::toolkit::TotalInvTracker': 'np.NPY_OBJECT',
'cyclus::toolkit::ResMap': 'np.NPY_OBJECT',
}

Expand All @@ -529,6 +534,7 @@ def convert_to_cpp(self, x, t):
'std::list': '[]',
'std::vector': '[]',
'cyclus::toolkit::ResBuf': 'None',
'cyclus::toolkit::TotalInvTracker': 'None',
'cyclus::toolkit::ResMap': 'None',
}

Expand Down Expand Up @@ -646,6 +652,7 @@ def convert_to_cpp(self, x, t):
' py{var}[i] = {var}_i\n',
'py{var}'),
'cyclus::toolkit::ResBuf': ('', '', 'None'),
'cyclus::toolkit::TotalInvTracker': ('', '', 'None'),
'cyclus::toolkit::ResMap': ('', '', 'None'),
}

Expand Down Expand Up @@ -758,6 +765,12 @@ def convert_to_cpp(self, x, t):
'py{var} = <_{classname}> {var}\n'
'cpp{var} = deref(py{var}.ptx)\n',
'cpp{var}'),
'cyclus::toolkit::TotalInvTracker': (
'cdef _{classname} py{var}\n'
'cdef cpp_cyclus.TotalInvTracker[{valtype}] cpp{var}\n',
'py{var} = <_{classname}> {var}\n'
'cpp{var} = deref(py{var}.ptx)\n',
'cpp{var}'),
'cyclus::toolkit::ResMap': (
'cdef _{classname} py{var}\n'
'cdef cpp_cyclus.ResMap[{keytype}, {valtype}] cpp{var}\n',
Expand Down

0 comments on commit bbb20b4

Please sign in to comment.