[Bro] On Modifying Bro tables in C++

José María González chema at cs.berkeley.edu
Thu Jul 29 12:18:34 PDT 2004


The following problem is probably easy, but my knowledge 
of C++ is pretty limited. 

I have a table defined in Bro, and I want to modify it 
(add/delete terms) in C++. Actually, I want to modify the 
table *only* in C++, but this is another subject. 

I use internal_val() to get a Val* from the table's Bro name. 
When I want to read the table, I access to the table 
underneath using my_table->AsTable() or, if I want to 
do further casting, using my_table->AsTable()->AsTableVal(). 
Everything works fine. 

Problem is when I want to write. AsTable() is defined in 
Val.h as a const accessor, but not as a non-const one. This 
means that my_table->AsTable() returns actually a "const 
TableEntryValPDict" object. Therefore, any access to Insert() 
or Remove() causes a "discards qualifiers" compiler error. 

While I can do brute-force cast and turn my "const 
TableEntryValPDict" into a simple TableEntryValPDict, I've 
read in Val.h that  "Accessors for mutable values are called 
AsNonConst* and are protected to avoid external state 
changes." This seems to state that there is a valid reason 
to avoid doing what I'm doing. "Avoid external state 
changes" is not descriptive enough for me. 

Can somebody provide advice on this? 


More information about the Bro mailing list