/*****************************************************************************
Copyright 1997 MBARI                                                      
******************************************************************************
Summary  : String Class
Filename : String.h
Author   : Michael B. Matthews                                                
Project  : New ROV                                                        
Version  : 1.01                                                          
Created  : 20.2.97                                                      
Modified : 17.3.98                                                             
Archived :                                                              
Notes    : 
Updates  : 17.3.98 - added string compare operators
******************************************************************************/

#ifndef _STRING_H
#define _STRING_H

#include <mbariTypes.h>
#include <strLib.h>
#include <stdioLib.h>


/******************************************************************************
Class   : S T R I N G                                              
Purpose : Provides for easy manipulation of strings 
Notes   :                               
******************************************************************************/

class String {
public:
  Int length;
  char* str;

  String(const char* s = "DEFAULT");
  String(Int n);
  String(const String&);
  ~String() { delete str; }

  String  operator+(const String&);
  String  operator+(const char*);
  String  operator+(const char);
  friend String operator+(const char*, const String&);

  String& operator+=(const String&);
  String& operator+=(const char*);
  String& operator+=(const char);

  String& operator=(const String&);
  String& operator=(const char*);
  String& operator=(const char);

  inline MBool operator==(const String& s) { Cmp(s); }
  inline MBool operator==(const char* s) { Cmp(s); }
  inline MBool operator==(const char s) { Cmp(s); }

  MBool Cmp(const String& s) 
  { if (!strcmp(str, s.str)) return TRUE; else return FALSE; }
  MBool Cmp(const char* s) 
  { if (!strcmp(str, s)) return TRUE; else return FALSE; }
  MBool Cmp(const char s) 
  { if (str[0] == s) return TRUE; else return FALSE; }

  inline Void Print() { printf("%s\n", str); }
  inline Void Write(FILE* fp) { fwrite((char*) str, length, 1, fp); }
};

#endif
