ClientApi::GetClient()
Get current client setting.
Virtual? |
No |
|
Class |
||
Arguments |
None |
|
Returns |
|
a reference to the client setting |
Notes
The return value of GetClient()
is a fixed
reference to this ClientApi
object’s setting.
Assigning the return value to a StrPtr
results in a
StrPtr
containing a Text()
value that changes
if the ClientApi
object’s client setting changes.
Assigning the return value to a StrBuf
copies the text in
its entirety for future access, rather than simply storing a reference to
data that might change later.
Under some circumstances, GetClient()
calls GetHost()
and returns
that value - specifically, if no suitable P4CLIENT
value is available in the environment, or previously set with SetClient()
. (This is
why, under the
p4
client, client name defaults to the host name if not explicitly set.)
In some instances, GetHost()
does not
return valid results until after a call to Init()
- see the GetHost()
documentation
for details.
Example
This example demonstrates the use of GetClient()
and the
difference between StrPtr’s
and StrBuf’s
.
ClientApi client; StrPtr p; StrBuf b; client.Init(); client.SetClient( "one" ); p = client.GetClient(); b = client.GetClient(); client.SetClient( "two" ); printf( "Current client %s = %s\n", client.GetClient().Text(), p.Text() ); printf( "Previous client setting was %s\n", b.Text() );
Executing the preceding code produces the following output:
Current client two = two Previous client setting was one