Note: Goby version 1 (shown here) is now considered obsolete. Please use version 2 for new projects, and consider upgrading old projects.

Goby Underwater Autonomy Project  Series: 1.1, revision: 163, released on 2013-02-06 14:23:27 -0500
acomms/libdccl/message_publish.h
00001 // copyright 2008, 2009 t. schneider tes@mit.edu
00002 //
00003 // this file is part of the Dynamic Compact Control Language (DCCL),
00004 // the goby-acomms codec. goby-acomms is a collection of libraries 
00005 // for acoustic underwater networking
00006 //
00007 // This program is free software: you can redistribute it and/or modify
00008 // it under the terms of the GNU General Public License as published by
00009 // the Free Software Foundation, either version 3 of the License, or
00010 // (at your option) any later version.
00011 //
00012 // This software is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with this software.  If not, see <http://www.gnu.org/licenses/>.
00019 
00020 #ifndef PUBLISH20091211H
00021 #define PUBLISH20091211H
00022 
00023 #include <iostream>
00024 #include <vector>
00025 #include <sstream>
00026 
00027 #include <boost/format.hpp>
00028 
00029 #include "message_var.h"
00030 #include "message_val.h"
00031 #include "message_algorithms.h"
00032 #include "dccl_constants.h"
00033 
00034 namespace goby
00035 {
00036     namespace acomms
00037     {
00038         class DCCLMessage;
00039     
00040 // defines (a single) thing to do with the decoded message
00041 // that is, where do we publish it and what should we include in the
00042 // published message
00043         class DCCLPublish
00044         {
00045           public:
00046           DCCLPublish() : var_(""),
00047                 format_(""),
00048                 format_set_(false),
00049                 use_all_names_(false),
00050                 type_(cpp_notype),
00051                 ap_(DCCLAlgorithmPerformer::getInstance()),
00052                 repeat_(1)
00053                 { }        
00054 
00055             //set
00056     
00057             void set_var(std::string var) {var_=var;}
00058             void set_format(std::string format) {format_=format; format_set_ = true;}
00059             void set_use_all_names(bool use_all_names) {use_all_names_ = use_all_names;}
00060             void set_type(DCCLCppType type) {type_ = type;}
00061 
00062             void add_name(const std::string& name) {names_.push_back(name);}
00063             void add_message_var(boost::shared_ptr<DCCLMessageVar> mv) {message_vars_.push_back(mv);}
00064             void add_algorithms(const std::vector<std::string> algorithms) {algorithms_.push_back(algorithms);}
00065     
00066             //get
00067 //    std::string var() const {return var_;}
00068 //    std::string format() const {return format_;}
00069 //    bool format_set()  const {return format_set_;}
00070 //    bool use_all_names() const {return use_all_names_;}
00071     
00072             DCCLCppType type() {return type_;}
00073 //    std::vector<std::string> const& names() {return names_;}
00074 //    std::vector<std::vector<std::string> > const& algorithms(){return algorithms_;}
00075     
00076         
00077             std::string get_display() const;
00078 
00079             void write_publish(const std::map<std::string,std::vector<DCCLMessageVal> >& vals,
00080                                std::multimap<std::string,DCCLMessageVal>* pubsub_vals);
00081         
00082         
00083         
00084 
00085             void initialize(const DCCLMessage& msg);
00086 
00087           private:
00088             void fill_format(const std::map<std::string,std::vector<DCCLMessageVal> >& vals,
00089                              std::string& key,
00090                              std::string& value,
00091                              unsigned repeat_index);
00092             
00093           private:
00094             std::string var_;
00095             std::string format_;
00096             bool format_set_;
00097             bool use_all_names_;
00098             DCCLCppType type_;
00099             std::vector<std::string> names_;
00100             std::vector<boost::shared_ptr<DCCLMessageVar> > message_vars_;
00101             std::vector< std::vector<std::string> > algorithms_;
00102             DCCLAlgorithmPerformer* ap_;
00103             unsigned repeat_;
00104         };
00105 
00106         std::ostream& operator<< (std::ostream& out, const DCCLPublish& publish);
00107     }
00108 }
00109 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends