indexing description: "A message that maps key-value pairs." author: "Patrick Ruckstuhl " date: "$Date$" revision: "$Revision$" class MAP_MESSAGE inherit MESSAGE redefine cpp_delete end create {SESSION, MESSAGE_CONSUMER} make feature -- Status Report has_map_name (a_name: STRING): BOOLEAN -- Does `a_name' in the map? local l_name: C_STRING do create l_name.make (encode (a_name)) Result := cpp_item_exists (item, l_name.item) end feature -- Queries get_map_names: LIST [STRING] is -- Return a list of the mapped names. local l_map_list: ARRAYED_LIST [STRING] l_map_vector: POINTER i, l_size: INTEGER do l_map_vector := cpp_get_map_names (item) l_size := cpp_string_vector_size (l_map_vector) create l_map_list.make (l_size) from i := 0 until i >= l_size loop l_map_list.force (decode (cpp_string_vector_get (l_map_vector, i))) i := i + 1 end Result := l_map_list cpp_string_vector_free (l_map_vector) end get_string (a_name: STRING): STRING is -- Return the string value of a_name. local l_name: C_STRING do create l_name.make (encode (a_name)) Result := decode (cpp_get_string (item, l_name.item)) end get_boolean (a_name: STRING): BOOLEAN is -- Return the boolean value of a_name. local l_name: C_STRING do create l_name.make (encode (a_name)) Result := cpp_get_boolean (item, l_name.item) end get_int (a_name: STRING): INTEGER is -- Return the integer value of a_name. local l_name: C_STRING do create l_name.make (encode (a_name)) Result := cpp_get_int (item, l_name.item) end get_long (a_name: STRING): INTEGER_64 is -- Return the integer_64 value of a_name. local l_name: C_STRING do create l_name.make (encode (a_name)) Result := cpp_get_long (item, l_name.item) end get_double (a_name: STRING): REAL_64 is -- Return the real_64 value of a_name. local l_name: C_STRING do create l_name.make (encode (a_name)) Result := cpp_get_double (item, l_name.item) end get_bytes (a_name: STRING): STRING is -- Return the bytes value of a_name. local l_name: C_STRING do create l_name.make (encode (a_name)) Result := decode (cpp_get_bytes (item, l_name.item)) end feature -- Update set_string (a_name: STRING; a_value: STRING) is -- Set the string with a_name and a_value. local l_name, l_value: C_STRING do create l_name.make (encode (a_name)) create l_value.make (encode (a_value)) cpp_set_string (item, l_name.item, l_value.item) end set_boolean (a_name: STRING; a_value: BOOLEAN) is -- Set the boolean with a_name and a_value. local l_name: C_STRING do create l_name.make (encode (a_name)) cpp_set_boolean (item, l_name.item, a_value) end set_int (a_name: STRING; a_value: INTEGER) is -- Set the int with a_name and a_value. local l_name: C_STRING do create l_name.make (encode (a_name)) cpp_set_int (item, l_name.item, a_value) end set_long (a_name: STRING; a_value: INTEGER_64) is -- Set the integer_64 (long) with a_name and a_value. local l_name: C_STRING do create l_name.make (encode (a_name)) cpp_set_long (item, l_name.item, a_value) end set_double (a_name: STRING; a_value: REAL_64) is -- Set the real_64 (double) with a_name and a_value. local l_name: C_STRING do create l_name.make (encode (a_name)) cpp_set_double (item, l_name.item, a_value) end set_bytes (a_name: STRING; a_value: STRING) is -- Set the bytes with a_name and a_value. local l_name, l_value: C_STRING do create l_name.make (encode (a_name)) create l_value.make (encode (a_value)) cpp_set_bytes (item, l_name.item, l_value.item, l_value.bytes_count) end feature {NONE} -- Implementation encode (a_string: STRING): STRING is -- Encode a_string. -- require -- a_string_ok: a_string /= Void -- Note: this is how it _should_ be, but I map Void to "" local l_string_stream: KL_STRING_OUTPUT_STREAM l_encode_stream: UT_BASE64_ENCODING_OUTPUT_STREAM do if a_string = Void then Result := "" else create l_string_stream.make_empty create l_encode_stream.make (l_string_stream, False, False) l_encode_stream.put_string (a_string) l_encode_stream.close Result := l_string_stream.string end ensure Result_not_void: Result /= Void end decode (a_string: STRING): STRING is -- Decode a_string encoded by encode. require a_string_ok: a_string /= Void local l_string_stream: KL_STRING_INPUT_STREAM l_decode_stream: UT_BASE64_DECODING_INPUT_STREAM do create l_string_stream.make (a_string) create l_decode_stream.make (l_string_stream) from Result := "" until l_decode_stream.end_of_input loop l_decode_stream.read_string (1024) Result.append (l_decode_stream.last_string) end ensure Result_not_void: Result /= Void end feature {NONE} -- C++ methods cpp_delete (a_object: POINTER) is -- Delete cpp object. external "C++ inline use " alias "[ delete (cms::MapMessage*)$a_object; ]" end cpp_get_string (a_object: POINTER; a_name: POINTER): STRING is -- Get a value. external "C++ inline use " alias "[ try{ std::string str = ((cms::MapMessage*)$a_object)->getString((char*)$a_name); char* c_str = (char*)(str.c_str()); return RTMS(c_str); }catch(cms::CMSException& e){ eraise((char*)(e.getStackTraceString().c_str()), EN_PROG); } ]" end cpp_set_string (a_object: POINTER; a_name: POINTER; a_value: POINTER) is -- Set a value. external "C++ inline use " alias "[ try{ (((cms::MapMessage*)$a_object)->setString((char*)$a_name, (char*)$a_value)); }catch(cms::CMSException& e){ eraise((char*)(e.getStackTraceString().c_str()), EN_PROG); } ]" end cpp_get_boolean (a_object: POINTER; a_name: POINTER): BOOLEAN is -- Get a value. external "C++ inline use " alias "[ try{ return ((cms::MapMessage*)$a_object)->getBoolean((char*)$a_name); }catch(cms::CMSException& e){ eraise((char*)(e.getStackTraceString().c_str()), EN_PROG); } ]" end cpp_set_boolean (a_object: POINTER; a_name: POINTER; a_value: BOOLEAN) is -- Set a value. external "C++ inline use " alias "[ try{ (((cms::MapMessage*)$a_object)->setBoolean((char*)$a_name, $a_value)); }catch(cms::CMSException& e){ eraise((char*)(e.getStackTraceString().c_str()), EN_PROG); } ]" end cpp_get_int (a_object: POINTER; a_name: POINTER): INTEGER is -- Get a value. external "C++ inline use " alias "[ try{ return ((cms::MapMessage*)$a_object)->getInt((char*)$a_name); }catch(cms::CMSException& e){ eraise((char*)(e.getStackTraceString().c_str()), EN_PROG); } ]" end cpp_set_int (a_object: POINTER; a_name: POINTER; a_value: INTEGER) is -- Set a value. external "C++ inline use " alias "[ try{ (((cms::MapMessage*)$a_object)->setInt((char*)$a_name, $a_value)); }catch(cms::CMSException& e){ eraise((char*)(e.getStackTraceString().c_str()), EN_PROG); } ]" end cpp_get_long (a_object: POINTER; a_name: POINTER): INTEGER_64 is -- Get a value. external "C++ inline use " alias "[ try{ return ((cms::MapMessage*)$a_object)->getLong((char*)$a_name); }catch(cms::CMSException& e){ eraise((char*)(e.getStackTraceString().c_str()), EN_PROG); } ]" end cpp_set_long (a_object: POINTER; a_name: POINTER; a_value: INTEGER_64) is -- Set a value. external "C++ inline use " alias "[ try{ (((cms::MapMessage*)$a_object)->setLong((char*)$a_name, $a_value)); }catch(cms::CMSException& e){ eraise((char*)(e.getStackTraceString().c_str()), EN_PROG); } ]" end cpp_get_double (a_object: POINTER; a_name: POINTER): REAL_64 is -- Get a value. external "C++ inline use " alias "[ try{ return ((cms::MapMessage*)$a_object)->getDouble((char*)$a_name); }catch(cms::CMSException& e){ eraise((char*)(e.getStackTraceString().c_str()), EN_PROG); } ]" end cpp_set_double (a_object: POINTER; a_name: POINTER; a_value: REAL_64) is -- Set a value. external "C++ inline use " alias "[ try{ (((cms::MapMessage*)$a_object)->setDouble((char*)$a_name, $a_value)); }catch(cms::CMSException& e){ eraise((char*)(e.getStackTraceString().c_str()), EN_PROG); } ]" end cpp_get_bytes (a_object: POINTER; a_name: POINTER): STRING is -- Get a value. external "C++ inline use " alias "[ try{ std::vector bytes = ((cms::MapMessage*)$a_object)->getBytes((char*)$a_name); char* c_str = new char[bytes.size()+1]; std::copy(bytes.begin(), bytes.end(), c_str); c_str[bytes.size()] = '\0'; char* res = RTMS(c_str); delete[] c_str; return res; }catch(cms::CMSException& e){ eraise((char*)(e.getStackTraceString().c_str()), EN_PROG); } ]" end cpp_set_bytes (a_object: POINTER; a_name: POINTER; a_value: POINTER; a_count: INTEGER) is -- Set a value. external "C++ inline use " alias "[ try{ char* c_str = (char*)$a_value; std::vector bytes (c_str, c_str + $a_count); ((cms::MapMessage*)$a_object)->setBytes((char*)$a_name, bytes); }catch(cms::CMSException& e){ eraise((char*)(e.getStackTraceString().c_str()), EN_PROG); } ]" end cpp_get_map_names (a_object: POINTER): POINTER is -- Get the c++ vector of map names. external "C++ inline use " alias "[ try{ return new std::vector(((cms::MapMessage*)$a_object)->getMapNames()); }catch(cms::CMSException& e){ eraise((char*)(e.getStackTraceString().c_str()), EN_PROG); } ]" end cpp_string_vector_size (a_object: POINTER): INTEGER is -- Get the size of a string vector. external "C++ inline use ," alias "[ return ((std::vector*)$a_object)->size(); ]" end cpp_string_vector_get (a_object: POINTER; a_pos: INTEGER): STRING is -- Get the element at a_pos in a string vector. external "C++ inline use ," alias "[ std::string str = (*((std::vector*)$a_object))[$a_pos]; char* c_str = (char*)(str.c_str()); return RTMS(c_str); ]" end cpp_string_vector_free (a_object: POINTER) is -- Free a string vector. external "C++ inline use ," alias "[ delete (std::vector*)$a_object; ]" end cpp_item_exists (a_object: POINTER; a_pointer: POINTER): BOOLEAN -- Map name exists? external "C++ inline use " alias "[ try{ return ((cms::MapMessage*)$a_object)->itemExists((char *)$a_pointer); }catch(cms::CMSException& e){ eraise((char*)(e.getStackTraceString().c_str()), EN_PROG); } ]" end end