~d-nelson/research-assistant/nextDNK

« back to all changes in this revision

Viewing changes to RANet/Strings.h

  • Committer: Viktor Bursian
  • Date: 2013-06-06 13:42:39 UTC
  • Revision ID: vbursian@gmail.com-20130606134239-bx5ks8sg3y9oqckz
Tags: version_0.2.0
first usable version 0.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////////
 
2
/*! @file Strings.h   Символьные строки.
 
3
- Part of RANet - Research Assistant Net Library (based on ANSI C++).
 
4
- Copyright(C) 1994-2010, Viktor E. Bursian, St.Petersburg, Russia.
 
5
                     Viktor.Bursian@mail.ioffe.ru
 
6
*///////////////////////////////////////////////////////////////////////////////
 
7
#ifndef Strings_H
 
8
#define Strings_H
 
9
//#include "RANet_global.h"
 
10
#include "General.h"
 
11
#include <iostream>
 
12
#include <utility>
 
13
namespace RA {
 
14
//------------------------------------------------------------------------------
 
15
 
 
16
ANNOUNCE_CLASS(sString)       // the most universal class for strings
 
17
 
 
18
std::ostream &  operator << (std::ostream &  ,rcsString);
 
19
std::istream &  operator >> (std::istream &  ,rsString);
 
20
 
 
21
//using namespace std::rel_ops; NEVER EVER USE using IN HEADERS!!!
 
22
 
 
23
class RANet_EXPORT  sString
 
24
{
 
25
  public://static
 
26
    static sString            from_real (real                number
 
27
                                        ,unsigned short int  digits_after_dot);
 
28
 
 
29
  public:
 
30
    virtual                   ~sString ();
 
31
                              sString ();
 
32
                              sString (rcsString);
 
33
                              sString (literal);
 
34
                              sString (const char);
 
35
    bool                      Empty () const;
 
36
    size_t                    Length () const;
 
37
    char                      operator [] (size_t) const; //first char index==0
 
38
    /*!< @todo{completeness} op[] must return char& ? */
 
39
//                              operator literal () const;
 
40
                              operator ptr_to_const_char () const;
 
41
    sString                   Substr (size_t from ,size_t length) const;
 
42
    sString                   Tail (size_t from) const;
 
43
    size_t                    Pos (literal) const;
 
44
    size_t                    Pos (rcsString) const;
 
45
    rsString                  operator =  (rcsString);
 
46
    rsString                  operator =  (literal);
 
47
    sString                   operator + (rcsString) const;
 
48
    sString                   operator + (literal) const;
 
49
    rsString                  operator += (rcsString);
 
50
    rsString                  operator += (literal);
 
51
    rsString                  operator += (const char);
 
52
    rsString                  operator << (const int);
 
53
    rsString                  operator << (const unsigned int);
 
54
    rsString                  operator << (const long int);
 
55
    rsString                  operator << (const unsigned long int);
 
56
    rsString                  operator << (real);
 
57
    rsString                  operator << (const double);
 
58
    rsString                  operator >> (int &);
 
59
    rsString                  operator >> (real &);
 
60
    bool                      operator == (rcsString) const;
 
61
    bool                      operator == (literal) const;
 
62
    bool                      operator != (rcsString) const;
 
63
    bool                      operator != (literal) const;
 
64
    bool                      operator < (rcsString) const;
 
65
    /*!< @todo{completeness}  ==(char)  <,>,<=,>=  >>int/float */
 
66
    sString                   UpperCase () const;
 
67
    sString                   Trim () const;
 
68
    sString                   TrimSyntactic (literal Delimiters
 
69
                                                     = DefaultDelimiters) const;
 
70
    sString                   Translate (char O ,char N) const;
 
71
    virtual void              Read (std::istream &);
 
72
    virtual void              Write (std::ostream &) const;
 
73
//    virtual void              InputTextLine (std::istream &);
 
74
  protected:
 
75
    void                      SetValue (literal);
 
76
 
 
77
  private: //fields
 
78
    char *                    Body;
 
79
    size_t                    CurrentLength;
 
80
//    size_t                    CurrentSpace;
 
81
 
 
82
  private: //constants
 
83
    static literal           EmptyLiteral;
 
84
    static literal           DefaultDelimiters;
 
85
 
 
86
//  friend std::ostream &  operator << (std::ostream & ,rcsString);
 
87
//  friend std::istream &  operator >> (std::istream & ,rsString);
 
88
};
 
89
 
 
90
 
 
91
inline  sString::sString ()
 
92
    :Body(NULL)
 
93
    ,CurrentLength(0)
 
94
    //,CurrentSpace(0)
 
95
{
 
96
};
 
97
 
 
98
 
 
99
inline  bool  sString::Empty () const
 
100
{
 
101
  return Body ? (CurrentLength == 0) : true ;
 
102
};
 
103
 
 
104
 
 
105
inline  size_t  sString::Length () const
 
106
{
 
107
  return Body ? CurrentLength : 0 ;
 
108
};
 
109
 
 
110
 
 
111
//inline  sString::operator literal () const
 
112
inline  sString::operator ptr_to_const_char () const
 
113
{
 
114
  return Body ? Body : EmptyLiteral ;
 
115
};
 
116
 
 
117
 
 
118
inline  size_t  sString::Pos (rcsString S) const
 
119
{
 
120
  return Pos( (literal)S );
 
121
};
 
122
 
 
123
 
 
124
inline  rsString  sString::operator =  (literal V)
 
125
{
 
126
  SetValue(V); return *this;
 
127
};
 
128
 
 
129
 
 
130
inline  sString  sString::operator + (rcsString S) const
 
131
{
 
132
  return operator+(literal(S));
 
133
};
 
134
 
 
135
 
 
136
inline  rsString  sString::operator += (rcsString S)
 
137
{
 
138
  return operator+=(literal(S));//! @todo{bomb} что за нах!
 
139
};
 
140
 
 
141
 
 
142
inline  bool  sString::operator != (rcsString S) const
 
143
{
 
144
  return !( operator==(S) );
 
145
};
 
146
 
 
147
 
 
148
inline  bool  sString::operator != (literal L) const
 
149
{
 
150
  return !( operator==(L) );
 
151
};
 
152
 
 
153
 
 
154
//inline  rsStream  operator << (rsStream S ,rcsLongString L)
 
155
//for unknown reason this does not allow to use a field member of a class
 
156
//see Nodes.cpp
 
157
/*! @todo{?} Why? */
 
158
inline  std::ostream &  operator<< (std::ostream & a_stream ,rcsString a_string)
 
159
{
 
160
  a_string.Write(a_stream);
 
161
  return  a_stream;
 
162
};
 
163
 
 
164
inline  std::istream &  operator>> (std::istream & a__stream ,rsString a_string)
 
165
{
 
166
  a_string.Read(a__stream);
 
167
  return  a__stream;
 
168
};
 
169
 
 
170
//------------------------------------------------------------------------------
 
171
}; //namespace RA
 
172
#endif
 
173