DataDirector API
DDD_ConvertFormat.h
Go to the documentation of this file.
1 #ifndef _CONVERT_FORMAT_H_
2 #define _CONVERT_FORMAT_H_
3 
4 /*! \file DDD_ConvertFormat.h
5  \brief The DDD_ConvertFormat class. Data Director converter for formatted i/o.
6 
7  \par Copyright Information
8 
9  Copyright (c) 2012 The DiSTI Corporation.<br>
10  11301 Corporate Blvd; Suite 100<br>
11  Orlando, Florida 32817<br>
12  USA<br>
13  <br>
14  All rights reserved.<br>
15 
16  This Software contains proprietary trade secrets of DiSTI and may not be
17 reproduced, in whole or part, in any form, or by any means of electronic,
18 mechanical, or otherwise, without the written permission of DiSTI. Said
19 permission may be derived through the purchase of applicable DiSTI product
20 licenses which detail the distribution rights of this content and any
21 Derivative Works based on this or other copyrighted DiSTI Software.
22 
23  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
24 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
25 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
26 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
27 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
28 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
29 
30  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
31 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
32 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
33 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
34 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
35 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBLITY
36 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
37 EXCEED FIVE DOLLARS (US$5.00).
38 
39  The aforementioned terms and restrictions are governed by the laws of the
40 State of Florida and the United States of America.
41 
42 */
43 
44 #include "DDD_ConvertBase.h"
45 #include "DDD_AttributeString.h"
46 #include "DDD_StringList.h"
47 #include <string>
48 #include <iostream>
49 #include <sstream>
50 
51 namespace disti
52 {
53 
54 ////////////////////////////////////////////////////////////////////////////////
55 /** \brief Format String Converter
56  *
57  * Formats a string similarly to the way printf does before outputting it.
58  * Format specifiers corresponding to parameters (ie- <tt>\%d</tt>, <tt>\%s</tt>,
59  * <tt>\%c</tt>, etc) are assigned to the order in which an input is given. <br><br>
60  * For example: <br>
61  * If the format string is <tt>"Value1: \%d Value2: \%f"</tt>, this converter expects at
62  * least two inputs and will try to extract the first as an integer and the second
63  * as a float. If the second input is missing, the outputted result next to
64  * <tt>"Value2:"</tt> would be <tt>"\#double\#"</tt>.<br>
65  * <br>
66  * input: [0,MAX_CONVERTER_INPUT] <br>
67  * ouput: [1,MAX_CONVERTER_OUTPUT] <br>
68  * parameters: <br>
69  * \b format \a (string) <br>
70  */
72 {
73 public:
74 
75  /** Constructor
76  * \param observer An attribute observer that will observer the parameters of the converter
77  * All converter parameters must use this observer for the converter to work right in the
78  * Data Director GUI.
79  */
81 
82  /** Destructor */
83  virtual ~DDD_ConvertFormat();
84 
85  static const char* CONVERT_FORMAT_CLASSNAME; /**< Classname string constant. Needed by the ConverterFactory */
86 
87  // Overrides from DDD_ConvertBase
88  virtual bool Convert(DDD_EndpointList& inputs, DDD_EndpointList& outputs);
89 
90  virtual int MinInputs() { return 0; }
91  virtual int MaxInputs() { return MAX_CONVERTER_INPUT; }
92  virtual int MinOutputs(){ return 1; }
93  virtual int MaxOutputs() { return MAX_CONVERTER_OUTPUT; }
94 
95  virtual const char* ClassName() { return CONVERT_FORMAT_CLASSNAME; }
96  virtual const char* Description() { return "Formats inputs the way printf would."; }
97 
98 private:
99  DDD_StringList Tokenize(const std::string& str,const std::string& delimiters);
100  std::string Parse(std::string token, DDD_EndpointList& inputs);
101 
102  std::string Parse_String(std::string token, DDD_EndpointList& inputs);
103  std::string Parse_Double(std::string token, DDD_EndpointList& inputs);
104  std::string Parse_Char(std::string token, DDD_EndpointList& inputs);
105  std::string Parse_Int(std::string token, DDD_EndpointList& inputs);
106 
107  DDD_AttributeString *_format; /**< The format string value for the converter */
108  int _currentInput; /**< Current input being processed by the converter */
109 };
110 
111 } // end namespace disti
112 
113 #endif
114 
The DDD_EndpintList class. A list of DDD_Endpoints.
Definition: DDD_ConnectionEndpoint.h:119
DataDirector attribute class corresponding to a string datatype.
Definition: DDD_AttributeString.h:52
virtual int MinInputs()
Definition: DDD_ConvertFormat.h:90
A templated array of objects. The array dynamically resizes as needed.
Definition: dynamic_array.h:61
Abstract base class for all DDD_DataDirector converters.
Definition: DDD_ConvertBase.h:68
DDD_ConvertFormat(DDD_AttributeObserver *observer)
The DDD_ConvertBase class. Base class for Data Director converters.
virtual const char * ClassName()
Definition: DDD_ConvertFormat.h:95
virtual int MaxOutputs()
Definition: DDD_ConvertFormat.h:93
#define MAX_CONVERTER_OUTPUT
Definition: DDD_ConvertBase.h:65
A virtual interface class for observers of attributes. AttributeObserver-derived objects are able to ...
Definition: DDD_AttributeBase.h:66
virtual bool Convert(DDD_EndpointList &inputs, DDD_EndpointList &outputs)
virtual int MinOutputs()
Definition: DDD_ConvertFormat.h:92
#define MAX_CONVERTER_INPUT
Definition: DDD_ConvertBase.h:64
Format String Converter.
Definition: DDD_ConvertFormat.h:71
virtual int MaxInputs()
Definition: DDD_ConvertFormat.h:91
The DDD_AttributeString class. String attribute.
Definition: AttributeChangedEmitter.h:46
static const char * CONVERT_FORMAT_CLASSNAME
Definition: DDD_ConvertFormat.h:85
virtual const char * Description()
Definition: DDD_ConvertFormat.h:96