Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / tt / lib / mp / mp_msg_context.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 //%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                  
24 //%%  (c) Copyright 1993, 1994 International Business Machines Corp.    
25 //%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                   
26 //%%  (c) Copyright 1993, 1994 Novell, Inc.                             
27 //%%  $XConsortium: mp_msg_context.C /main/3 1995/10/23 10:25:15 rswiston $                                                     
28 /*
29  * @(#)mp_msg_context.C 1.14 94/11/17
30  *
31  * @(#)mp_msg_context.C 1.9 93/09/07
32  *
33  * Implementation of the _Tt_msg_context: a context slot in a message.
34  */
35
36 #include "mp/mp_arg.h"
37 #include "mp/mp_msg_context.h"
38 #include "util/tt_iostream.h"
39
40 _Tt_msg_context::_Tt_msg_context()
41 {
42         _value = new _Tt_arg;
43 }
44
45 _Tt_msg_context::~_Tt_msg_context()
46 {
47 }
48
49 Tt_status
50 _Tt_msg_context::setValue(
51         const _Tt_string &value
52 )
53 {
54         _value->set_mode( TT_INOUT );
55         _value->set_type( "string" );
56         return _value->set_data_string( value );
57 }
58
59 Tt_status
60 _Tt_msg_context::setValue(
61         int value
62 )
63 {
64         _value->set_mode( TT_INOUT );
65         _value->set_type( "integer" );
66         return _value->set_data_int( value );
67 }
68
69 int
70 _Tt_msg_context::isEnvEntry() const
71 {
72         if (_slotName.len() == 0) {
73                 return 0;
74         }
75         return _slotName[0] == '$';
76 }
77
78 _Tt_string
79 _Tt_msg_context::enVarName() const
80 {
81         _Tt_string name( ((char *)_slotName)+1 );
82         return name;
83 }
84
85 _Tt_string
86 _Tt_msg_context::stringRep() const
87 {
88         _Tt_string rep;
89         char temp[ 20 ];
90         switch (_value->data_type()) {
91             case _Tt_arg::UNSET:
92                 break;
93             case _Tt_arg::STRING:
94                 rep = _value->data_string();
95                 break;
96             case _Tt_arg::INT:
97                 sprintf( temp, "%d", _value->data_int());
98                 rep = temp;
99                 break;
100         }
101         return rep;
102 }
103
104 void
105 _Tt_msg_context::print(
106         const _Tt_ostream &os
107 ) const
108 {
109         _Tt_context::print( os );
110         os << ": ";
111         if (!_value.is_null()) {
112                 _value->print( os );
113         } else {
114                 os << "\n";
115         }
116 }
117
118 void
119 _Tt_msg_context::print_(
120         const _Tt_ostream &os,
121         const _Tt_object *obj
122 )
123 {
124         ((_Tt_msg_context *)obj)->print( os );
125 }
126
127 bool_t
128 _Tt_msg_context::xdr(
129         XDR *xdrs
130 )
131 {
132         if (! _Tt_context::xdr( xdrs )) {
133                 return 0;
134         }
135         return _value.xdr( xdrs );
136 }