mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-16 17:10:20 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0784aa131 |
No files matched your search
@@ -9,5 +9,3 @@ stamp-h
|
||||
libtool
|
||||
Makefile.in
|
||||
config.log
|
||||
config.h.in
|
||||
mono-*.tar.gz
|
||||
@@ -1,2 +1 @@
|
||||
Miguel de Icaza ([email protected])
|
||||
Paolo Molaro ([email protected])
|
||||
@@ -1,14 +1,3 @@
|
||||
2001-07-15 Sean MacIsaac <[email protected]>
|
||||
|
||||
* doc/download: added instructions for cygwin
|
||||
|
||||
* doc/c-sharp: removed bit about compiling
|
||||
|
||||
* status/compare-assembly.cs: basedir should be there if
|
||||
parameters are provided.
|
||||
|
||||
* status/makefile: made targets to dump info.
|
||||
|
||||
2001-07-15 Joe Shaw <[email protected]>
|
||||
|
||||
* configure.in: Don't create doc/Makefile as there's nothing there
|
||||
|
||||
@@ -1,42 +1,8 @@
|
||||
This is Mono.
|
||||
This is MonoNet.
|
||||
|
||||
A directory roadmap:
|
||||
|
||||
doc/
|
||||
Contains documentation and the web site contents.
|
||||
|
||||
mono/
|
||||
The core of the executable.
|
||||
|
||||
metadata/
|
||||
The library to deal with executables and libraries for
|
||||
.NET
|
||||
|
||||
dis/
|
||||
CIL executable Disassembler
|
||||
|
||||
cli/
|
||||
Common code for the JIT and the interpreter.
|
||||
|
||||
cil/
|
||||
Common Intermediate Representation, XML
|
||||
definition of the CIL bytecodes.
|
||||
|
||||
interp/
|
||||
Interpreter for CLI executables.
|
||||
|
||||
* Using Mono
|
||||
|
||||
Once you have installed the software, you can run a few programs:
|
||||
|
||||
monodis program.exe
|
||||
|
||||
That will dump the bytecodes for program.exe. Monodis support
|
||||
a number of options that dumps various metadata tables
|
||||
(chapter 23 of the Partition III).
|
||||
|
||||
You can try the interpreter like this:
|
||||
|
||||
mono-int program.exe
|
||||
Ximian's portable implementation of .NET
|
||||
|
||||
|
||||
----------
|
||||
|
||||
To edit the go-mono website, see doc/README.
|
||||
+2
-12
@@ -1,6 +1,6 @@
|
||||
AC_INIT(README)
|
||||
AM_CONFIG_HEADER(config.h)
|
||||
AM_INIT_AUTOMAKE(mono, 0.5)
|
||||
AM_INIT_AUTOMAKE(mono, 0.3)
|
||||
AM_MAINTAINER_MODE
|
||||
|
||||
AC_PROG_CC
|
||||
@@ -23,15 +23,6 @@ GLIB_LIBS=`glib-config --libs glib`
|
||||
AC_SUBST(GLIB_CFLAGS)
|
||||
AC_SUBST(GLIB_LIBS)
|
||||
|
||||
GMODULE_CFLAGS=`glib-config --cflags gmodule`
|
||||
GMODULE_LIBS=`glib-config --libs gmodule`
|
||||
|
||||
AC_SUBST(GMODULE_CFLAGS)
|
||||
AC_SUBST(GMODULE_LIBS)
|
||||
|
||||
AC_CHECK_LIB(ffi, ffi_prep_cif, ,[
|
||||
AC_MSG_ERROR(libffi 1.20 or higher is required.)])
|
||||
|
||||
CFLAGS='-g -Wall -Wunused -Wmissing-prototypes -Wmissing-declarations'
|
||||
AC_SUBST(CFLAGS)
|
||||
|
||||
@@ -41,7 +32,6 @@ mono/Makefile
|
||||
mono/metadata/Makefile
|
||||
mono/dis/Makefile
|
||||
mono/cil/Makefile
|
||||
mono/cli/Makefile
|
||||
mono/interpreter/Makefile
|
||||
doc/Makefile
|
||||
mono/doc/Makefile
|
||||
])
|
||||
+2
-5
@@ -1,6 +1,6 @@
|
||||
WEB_FILES= \
|
||||
WEB_FILES=
|
||||
c-sharp class-library contact contributing documentation download \
|
||||
faq gcc-frontend ideas index passport rationale resources \
|
||||
faq gcc-frontend ideas index makefile passport rationale resources \
|
||||
roadmap runtime status team testing thanks tools
|
||||
|
||||
OTHERS= pending resources-pending todo
|
||||
@@ -14,6 +14,3 @@ all-docs: $(WEB_FILES)
|
||||
|
||||
webit:
|
||||
(cd web; make && make push)
|
||||
|
||||
push-notes:
|
||||
scp release-notes/mono* www@www:/web/cvsmodules/mono/archive
|
||||
+15
-12
@@ -82,7 +82,7 @@
|
||||
parents are.
|
||||
</ul>
|
||||
|
||||
Interesting and Fun hacks to the compiler:
|
||||
Interesting tasks:
|
||||
|
||||
<ul>
|
||||
* Finishing the JB port from Java to C#. If you are
|
||||
@@ -95,17 +95,6 @@
|
||||
JB will allow us to move from the Berkeley Yacc
|
||||
based Jay to a Bison-based compiler (better error
|
||||
reporting and recovery).
|
||||
|
||||
* Semantic Analysis: Return path coverage and
|
||||
initialization before use coverage are two great
|
||||
features of C# that help reduce the number of bugs
|
||||
in applications. It is one interesting hack.
|
||||
|
||||
* TypeRefManager. This exists currently in its infancy only.
|
||||
|
||||
* Enum resolutions: it is another fun hack, as enums can be defined
|
||||
in terms of themselves (<tt>enum X { a = b + 1, b = 5 }</tt>).
|
||||
|
||||
</ul>
|
||||
|
||||
** Questions and Answers
|
||||
@@ -144,5 +133,19 @@ A: No, currently I am using Jay which is a port of Berkeley Yacc to
|
||||
In the future I want to port one of the Bison/Java ports to C# for
|
||||
the parser.
|
||||
|
||||
Q: How do I compile it?
|
||||
|
||||
A: Compiling MCS currently requires you to run my port of <a
|
||||
href="http://primates.ximian.com/~miguel/code/jay.cs.tar.gz">Jay to
|
||||
C#</a> on a Unix system to generate the parser, and then you need
|
||||
to use Microsoft's .NET csc.exe compiler to compile the compiler.
|
||||
|
||||
You only need to compile the compiler compiler (C code), the
|
||||
samples are Java samples that I did not port, and you do not need
|
||||
them.
|
||||
|
||||
It might be simple to port Jay.cs to Windows, but I have not tried
|
||||
this.
|
||||
|
||||
You might also want to look at the <a href="faq.html#gcc">GCC</a>
|
||||
section on the main FAQ
|
||||
+15
-4
@@ -4,13 +4,24 @@
|
||||
registered to work on what parts of the system. These list
|
||||
work-in-progress components currently.
|
||||
|
||||
Browse the current <a href="class-status/index.html">status</a>.
|
||||
<ul>
|
||||
* Per <a href="class-status/per-assembly.html">Assembly</a>
|
||||
|
||||
* Per <a href="class-status/per-completion.html">Completion</a>
|
||||
|
||||
* Per <a href="class-status/per-maintainer.html">Maintainer</a>
|
||||
|
||||
* Per <a href="class-status/per-unimplemented.html">Unimplemented</a>
|
||||
</ul>
|
||||
|
||||
A better mechanism will soon be in place, I just did this
|
||||
really quickly, as we already got one duplicated implementation.
|
||||
|
||||
You can also download the XML <a
|
||||
href="class-status/maintainers.xml">maintainers</a> file that
|
||||
contains the actual maintainers list.
|
||||
|
||||
You can also download the master <a
|
||||
href="class-status/class.xml">Class Status XML</a> file.
|
||||
|
||||
I am sure we can generate better reports, if you are
|
||||
interested in contributing, let <a
|
||||
href="mailto:[email protected]">me</a> know.
|
||||
|
||||
+2
-9
@@ -18,15 +18,6 @@
|
||||
something that would help tremendously would be to help with
|
||||
small duties in the project that need to be addressed.
|
||||
|
||||
** Bug reporting
|
||||
|
||||
If you find bugs in Mono, please make sure you enter a bug
|
||||
report so we can keep track of problems in Mono.
|
||||
|
||||
To enter bug reports go to <a href="http://bugzilla.ximian.com">
|
||||
http://bugzilla.ximian.com</a> and enter bug reports against
|
||||
your favorite component (Mono, Runtime, C# compiler).
|
||||
|
||||
** Small tasks
|
||||
|
||||
A few smaller tasks are here, dropped in no particular order:
|
||||
@@ -38,6 +29,8 @@
|
||||
|
||||
* <b>Mono/doc and web site:</b> They need to be
|
||||
packaged up in the official `distribution'
|
||||
|
||||
* <b>Enthusiasts: </b>
|
||||
</ul>
|
||||
|
||||
* Special note
|
||||
|
||||
+4
-111
@@ -10,55 +10,19 @@
|
||||
test suite and the class library are in the `mcs' package, we
|
||||
will move this later into `mono' itself.
|
||||
|
||||
In order to make mcs and the class libraries you will need the
|
||||
GNU make tools. These may be obtained for the Windows
|
||||
environment from <a href="www.cygwin.com">cygwin.com</a>.
|
||||
The mcs compiler requires the `jay' parser generator, this is
|
||||
available in module `jay'.
|
||||
|
||||
You will also need to get GLIB, from: <a
|
||||
href="ftp://ftp.gtk.org/pub/gtk/v1.2/glib-1.2.10.tar.gz">ftp://ftp.gtk.org/pub/gtk/v1.2/glib-1.2.10.tar.gz</a>
|
||||
|
||||
<a name="sources">
|
||||
** Sources
|
||||
|
||||
Currently we will be providing CVS snapshots every day, until
|
||||
we make the first tarball release.
|
||||
|
||||
<ul>
|
||||
<a name="july-22">
|
||||
<b>July 22, 2001</b>
|
||||
<ul>
|
||||
* <a href="archive/mcs-22-Jul-2001.tar.gz">mcs-22-Jul-2001.tar.gz</a>: CVS snapshot.
|
||||
* <a href="archive/mcs-Jul-22-Jul-19-2001.tar.gz">Differences since 19</a>: CVS snapshot.
|
||||
* <a href="archive/mcs-22">Release Notes</a>
|
||||
</ul>
|
||||
|
||||
<a name="july-19">
|
||||
<b>July 19th, 2001</b>
|
||||
<ul>
|
||||
* <a href="archive/mcs-19-Jul-2001.tar.gz">mcs-19-Jul-2001.tar.gz</a>: CVS snapshot.
|
||||
* <a href="archive/mcs-Jul-17-Jul-19-2001.tar.gz">Differences since 17</a>: CVS snapshot.
|
||||
* <a href="archive/mcs-19">Release Notes</a>
|
||||
</ul>
|
||||
|
||||
<a name="july-17">
|
||||
<b>July 17th, 2001</b>
|
||||
<ul>
|
||||
* <a href="archive/mcs-17-Jul-2001.tar.gz">mcs-17-Jul-2001.tar.gz</a>: CVS snapshot.
|
||||
* <a href="archive/mcs-Jul-15-Jul-17-2001.tar.gz">Differences since 15</a>: CVS snapshot.
|
||||
* <a href="archive/mcs-17">Release Notes</a>
|
||||
</ul>
|
||||
|
||||
<a name="july-15">
|
||||
<b>July 15th, 2001</b>
|
||||
<ul>
|
||||
* <a href="archive/mcs-15-Jul-2001.tar.gz">mcs-15-Jul-2001.tar.gz</a>: CVS snapshot.
|
||||
* <a href="archive/mono-0.4.tar.gz">mono-0.4.tar.gz</a>: Packaged Source Code.
|
||||
* <a href="archive/mono-0.4">Release Notes</a>
|
||||
</ul>
|
||||
|
||||
<a name="july-14">
|
||||
<b>July 14th, 2001</b>
|
||||
<ul>
|
||||
* <a href="archive/jay.cs.tar.gz">archive/jay.cs.tar.gz</a>: Sources to Jay.
|
||||
* <a href="archive/mcs-12-Jul-2001.tar.gz">mcs-12-Jul-2001.tar.gz</a>: CVS snapshot.
|
||||
* <a href="archive/mono-0.3.tar.gz">mono-0.3.tar.gz</a>: Packaged Source Code.
|
||||
</ul>
|
||||
@@ -67,85 +31,14 @@ href="ftp://ftp.gtk.org/pub/gtk/v1.2/glib-1.2.10.tar.gz">ftp://ftp.gtk.org/pub/g
|
||||
<b>July 8th, 2001</b>
|
||||
|
||||
<ul>
|
||||
* <a href="archive/jay.cs.tar.gz">archive/jay.cs.tar.gz</a>: Sources.
|
||||
* <a href="archive/mcs-08-Jul-2001.tar.gz">mcs-08-Jul-2001.tar.gz</a>: CVS Snapshot
|
||||
* <a href="archive/mono-08-Jul-2001.tar.gz">mono-08-Jul-2001.tar.gz</a>: CVS Snapshot
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
<a name="install">
|
||||
** Installing the software
|
||||
|
||||
To install and work on the compiler and the class libraries,
|
||||
follow these instructions:
|
||||
|
||||
<ul>
|
||||
* Install <a href="http://www.cygwin.org">CygWin</a> first.
|
||||
|
||||
* Untar the MCS distribution (see below for information).
|
||||
|
||||
* Go into the MCS directory and type `make windows'
|
||||
</ul>
|
||||
|
||||
To compile the mono runtime on windows:
|
||||
|
||||
<ul>
|
||||
* Install <a href="http://www.cygwin.org">CygWin</a> first.
|
||||
|
||||
* Once installed, in a terminal window or a cygwin
|
||||
window (a shortcut should be on your desktop), untar the glib
|
||||
distribution:
|
||||
|
||||
<pre>
|
||||
tar xzvf glib-1.2.10.tar.gz
|
||||
</pre>
|
||||
|
||||
* Configure, compile and install glib, like this:
|
||||
|
||||
<pre>
|
||||
./configure --prefix=/usr/bin
|
||||
make
|
||||
make install
|
||||
</pre>
|
||||
|
||||
* Unpack the mono distribution:
|
||||
|
||||
<pre>
|
||||
tar xzvf mono-XXX.tar.gz
|
||||
</pre>
|
||||
|
||||
* Configure, compile and install:
|
||||
|
||||
<pre>
|
||||
./configure --prefix=//c/mono
|
||||
make
|
||||
make install
|
||||
</pre>
|
||||
</ul>
|
||||
|
||||
To compile the mono runtime on Unix:
|
||||
|
||||
<ul>
|
||||
|
||||
* Download the mono distribution
|
||||
|
||||
* Unpack the mono distribution:
|
||||
|
||||
<pre>
|
||||
tar xzvf mono-XXX.tar.gz
|
||||
</pre>
|
||||
|
||||
* Configure, compile and install:
|
||||
<pre>
|
||||
./configure
|
||||
make
|
||||
make install
|
||||
</pre>
|
||||
</ul>
|
||||
|
||||
** CVS
|
||||
|
||||
We are trying to figure out where to put our CVS repository.
|
||||
We are debating between the GNOME CVS or SourceForge. Watch
|
||||
this spot.
|
||||
|
||||
|
||||
@@ -138,8 +138,8 @@ A: We like the features that the CLI and its related technologies
|
||||
Q: Will I be able to write proprietary applications that run with
|
||||
Mono?
|
||||
|
||||
A: Yes. The licensing scheme is planned to allow proprietary
|
||||
developers to write applications with Mono.
|
||||
A: Yes. We will make sure that the licensing will allow developers to
|
||||
create proprietary applications.
|
||||
|
||||
Q: What license is Mono on?
|
||||
|
||||
@@ -147,8 +147,10 @@ A: The C# Compiler is released under the terms of the GPL. The class
|
||||
libraries will be under the LGPL or the GPL with a special
|
||||
exception. The runtime libraries are under the LGPL.
|
||||
|
||||
Since the LGPL is not suitable for embedded systems development, we
|
||||
are also licensing the libraries under the GPL with the following exception:
|
||||
Here is the exception for the class libraries:
|
||||
|
||||
The library is distributed under the terms of the GNU General
|
||||
Public License with the following exception:
|
||||
|
||||
If you link this library against your own program, then you do not
|
||||
need to release the source code for that program. However, any
|
||||
@@ -160,15 +162,6 @@ A: The C# Compiler is released under the terms of the GPL. The class
|
||||
href="http://www.gnu.org/software/classpath/classpath.html">GNU
|
||||
Classpath.</a>
|
||||
|
||||
Q: But in Object Oriented Programming I need to subclass your library
|
||||
functions, does that mean that I am making modifications to your
|
||||
library and hence I would have to distribute my sources under the
|
||||
LGPL?
|
||||
|
||||
A: No. Object Oriented Programming in the class library is a well
|
||||
understood interface barrier, so you can actually develop
|
||||
proprietary applications with the Mono libraries.
|
||||
|
||||
Q: Will you accept code under the XXX License?
|
||||
|
||||
A: If the XXX License is compatible with the license we use in that
|
||||
@@ -242,13 +235,6 @@ Q: What is your opinion?
|
||||
A: You can read my personal <a href="passport.html">opinion on
|
||||
passport</a>.
|
||||
|
||||
Q: Will Mono running on Linux make Passport available for Linux?
|
||||
|
||||
A: The Passport toolkit for Linux-based web servers is available from
|
||||
Microsoft.
|
||||
|
||||
Again, Mono has nothing to do with Passport.
|
||||
|
||||
** Mono and Windows
|
||||
|
||||
Q: Will Mono allow me to run Microsoft Office on Linux?
|
||||
@@ -403,12 +389,6 @@ A: The CIL is better suited to be JITed than JVM byte codes, but you
|
||||
can interpret them as trivially as you can interpret JVM byte
|
||||
codes.
|
||||
|
||||
Q: Could Java target the CLI?
|
||||
|
||||
A: Yes, Java could target the CLI. We have details on a <a
|
||||
href="ideas.html#guavac">project</a> that someone could take on to
|
||||
make this happen.
|
||||
|
||||
** Extending Mono
|
||||
|
||||
Q: Would you allow other classes other than those in the
|
||||
@@ -463,34 +443,8 @@ A: We are also researching <a
|
||||
href="http://www.gnu.org/software/lightning/lightning.html">GNU
|
||||
Lightning</a>.
|
||||
|
||||
<a name="ximian-and-microsoft">
|
||||
** Ximian and Microsoft
|
||||
|
||||
Q: I read that Microsoft is helping out Ximian, is this true?
|
||||
|
||||
A: Initial contact between David Stutz and Miguel de Icaza happened.
|
||||
It was a friendly conversation. Microsoft is interested in other
|
||||
implementing .NET and are willing to help make the ECMA spec more
|
||||
accurate for this purpose.
|
||||
|
||||
We were initially contacted by Sam Ruby at the ECMA TG3 committee
|
||||
to discuss the same issue. And we are glad to have good contacts
|
||||
to ask questions about the specs.
|
||||
|
||||
Q: Do you fear that Microsoft will change the spec and render Mono useless?
|
||||
|
||||
A: No. Microsoft proved with the CLI and the C# language that it was
|
||||
possible to create a powerful foundation for many languages to
|
||||
interoperate. We will always have that.
|
||||
|
||||
Even if changes happened in the platform which were undocumented
|
||||
(which is very unlikely), the existing platform has a value on its
|
||||
own.
|
||||
|
||||
Miguel once explained its motivation for working on Mono to Dave
|
||||
Winer, and his mail got posted <a
|
||||
href="http://scriptingnews.userland.com/stories/storyReader$1275">here</a>
|
||||
|
||||
Q: Didn't Miguel de Icaza say that `Unix Sucks'?
|
||||
|
||||
A: Yes, he did, as a catch phrase in his opening remark on the Ottawa
|
||||
@@ -584,6 +538,12 @@ Q: Why are you writing a JIT engine instead of a front-end to GCC?
|
||||
A: The JIT engine and runtime engine will be able to execute CIL
|
||||
executables generated on Windows.
|
||||
|
||||
** Mono and GNU
|
||||
|
||||
Q: Is Mono part of the GNU project?
|
||||
|
||||
A: Mono is a Ximian project, that is also part of the GNU project.
|
||||
|
||||
** Mono and Portability
|
||||
|
||||
Q: Will Mono work on other variants of Unix?
|
||||
@@ -633,16 +593,17 @@ A: We can not predict the future, but a conservative estimate is that
|
||||
Q: You say that the CLI allows multiple languages to execute on the
|
||||
same environment. Isn't this the purpose of CORBA?
|
||||
|
||||
A: The key difference between CORBA (and COM) and the CLI is that the
|
||||
CLI allows "data-level interoperability" because every
|
||||
language/component uses the same data layout and memory management.
|
||||
A: CORBA can be used for this purpose, but think of CORBA mostly as a
|
||||
inter-process (local machine or remote machine) communication
|
||||
system.
|
||||
|
||||
This means you can operate directly upon the datatypes that someone
|
||||
else provides, without having to go via their interfaces. It also
|
||||
means you don't have to "marshall" (convert) parameters (data
|
||||
layouts are the same, so you can just pass components directly) and
|
||||
you don't have to worry about memory managment, because all
|
||||
languages/components share the same garbage collector and address
|
||||
space. This means much less copying and no need for reference
|
||||
counting.
|
||||
Think of the CLI to be targeted to interoperation of languages in
|
||||
the same process, and CORBA as being a nifty addition for
|
||||
out-of-process.
|
||||
|
||||
Sure, we have used CORBA for in-proc components, but the lack of an
|
||||
ABI for in-proc components does not translate into a good framework
|
||||
for in-proc systems
|
||||
|
||||
|
||||
|
||||
@@ -3,28 +3,13 @@
|
||||
Here are a few ideas of tools, classes and projects that you
|
||||
could start. More are forthcoming.
|
||||
|
||||
<a name="runtime">
|
||||
** Runtime
|
||||
|
||||
We need a verifier that can be run on an executable (assembly)
|
||||
and tells whether the metadata for the executable is correct
|
||||
or not. It should report any anomalies.
|
||||
|
||||
For a list of anomalies in assemblies, check the various assertions
|
||||
that are described on the ECMA documentation.
|
||||
|
||||
This will help test our generated executables and can be also
|
||||
used as an external verifier.
|
||||
|
||||
<a name="classes">
|
||||
** Classes
|
||||
|
||||
<ul>
|
||||
TODO=jxta,The JXTA Peer to Peer foundation
|
||||
* Implement a JXTA protocol implementation:
|
||||
<a href="http://www.jxta.org">http://www.jxta.org</a>
|
||||
|
||||
TODO=camel,Mail API
|
||||
* Implement a Mail API, similar to Camel or JavaMail (Camel has
|
||||
significant architecture features that are required on a real
|
||||
mailer).
|
||||
@@ -33,87 +18,23 @@ TODO=camel,Mail API
|
||||
<a href="http://cvs.gnome.org/bonsai/rview.cgi?dir=evolution%2Fcamel">
|
||||
Camel implementation</a>.
|
||||
|
||||
Such an implementation could be used both with
|
||||
Microsoft .NET and Mono.
|
||||
|
||||
TODO=multimedia
|
||||
* Interfacing to Multimedia systems. You might want
|
||||
to look into the Quicktime API. I know <a
|
||||
href="mailto:[email protected]">Vladimir</a> has
|
||||
researched the problem before
|
||||
|
||||
TODO=gtk,Gtk+ wrappers for Mono and .NET
|
||||
* Wrap the Gtk+ API. This is simple and can be done
|
||||
on Windows as Gtk+ 2.0 works on Windows.
|
||||
|
||||
This work can also be used on Windows and will
|
||||
enable developers on Windows to use some of Gtk+'s
|
||||
advanced features.
|
||||
|
||||
The idea is to wrap the Gtk+ API and allow us to
|
||||
build GUI applications using Gtk+ and in the future
|
||||
other Gtk+-based libraries from Mono (Gal, GtkHTML).
|
||||
|
||||
There is extensive knowledge on wrapping Gtk+ in
|
||||
other languages (this has been done this for Perl,
|
||||
Python, Java, Scheme, Haskel and other languages in
|
||||
the past).
|
||||
</ul>
|
||||
|
||||
<a name="projects">
|
||||
** Projects
|
||||
|
||||
<ul>
|
||||
TODO=xmlStorage,
|
||||
* Implement an xmlStorageSystem for the CLI:
|
||||
<a href="http://www.soapware.org/xmlStorageSystem">
|
||||
http://www.soapware.org/xmlStorageSystem</a>
|
||||
|
||||
TODO=guavac,Java compiler for .NET
|
||||
* You could take one of the existing Java compilers
|
||||
(Guavac comes to mind as it is so nice) and modify
|
||||
it to generate .NET code rather than JVM byte
|
||||
codes.
|
||||
|
||||
This should be a pretty straightforward task.
|
||||
Guavac has the advantage of being written in C++ and
|
||||
it could be compiled with the Microsoft Managed C++
|
||||
compiler and produce a .NET executable with it.
|
||||
|
||||
TODO=CORBA,CORBA implementation
|
||||
* Build a CORBA interoperability engine for the CLR.
|
||||
You do not need to do all of the work, just talking
|
||||
the protocol will get us a long way (<a
|
||||
href="http://www.omg.org">The OMG site</a> has the
|
||||
CORBA specs).
|
||||
|
||||
Get in touch with David Taylor (dtaylo11 at bigpond
|
||||
dot net dot au) as he has been working on this
|
||||
project.
|
||||
|
||||
TODO=Bonobo,Bonobo for Mono
|
||||
* Once CORBA is done, implement the Bonobo interfaces
|
||||
to allow people to use Bonobo components in Mono and
|
||||
Mono components with Bonobo. The best of both worlds!
|
||||
|
||||
TODO=moniker,Object Naming System with Monikers
|
||||
* A naming space for Mono. An object naming space is
|
||||
a very powerful tool. Bonobo implements a moniker
|
||||
system that is more powerful than the original
|
||||
moniker concept that was pioneered by COM/OLE in the
|
||||
Microsoft world.
|
||||
|
||||
Our implementation builds on a concept, and we have
|
||||
made it simpler, more powerful, more extensible and
|
||||
a much better mechanism than the equivalent monikers
|
||||
on Windows.
|
||||
|
||||
Implementing Mono monikers would benefit both
|
||||
Windows users using .NET and Mono users on Unix and
|
||||
Windows.
|
||||
|
||||
Here is <a
|
||||
href="http://primates.ximian.com/~miguel/monikers.html">an
|
||||
overview of the moniker system</a> in Bonobo.
|
||||
href="http://www.omg.org">The OMG site</a> has the CORBA specs).
|
||||
|
||||
</ul>
|
||||
@@ -1,63 +1,3 @@
|
||||
<a href="http://www.ximian.com">Ximian</a> announced the
|
||||
launch of the Mono project, an effort to create a <a
|
||||
href="http://www.gnu.org/philosophy/free-sw.html">Free
|
||||
Software</a> (sometimes called open source) implementation of
|
||||
the .NET Development Framework.
|
||||
|
||||
You can read our <a href="rationale.html">rationale</a> for
|
||||
this project. If you have questions about the project, please
|
||||
read our list of <a href="faq.html">Frequently Asked
|
||||
Questions</a> or contact us.
|
||||
|
||||
You might also want to <a href="download.html">Download the
|
||||
source</a> for our work so far.
|
||||
|
||||
You might want to <a
|
||||
href="resources.html#mailing">subscribe</a> to our mono-list
|
||||
and mono-announce-list
|
||||
|
||||
You can contact the team at: <a
|
||||
href="mailto:[email protected]">[email protected]</a>
|
||||
|
||||
** JUl 25, 2001
|
||||
|
||||
The slides for <A href="Presentations/O-Reilly">my
|
||||
presentation</a> at <a href="http://www.oreilly.com">O'Reilly
|
||||
Open Source Software Convention</a>
|
||||
|
||||
** Jul 22, 2001
|
||||
|
||||
Another release of the class libraries is out, check the <a
|
||||
href="archive/mcs-22">MCS 22-July Release Notes</a>. You can
|
||||
get the new class libraries from <a
|
||||
href="download.html#july-22">here</a>
|
||||
|
||||
** Jul 19, 2001
|
||||
|
||||
Another release of the class libraries is out, check the <a
|
||||
href="archive/mcs-19">MCS 19-July Release Notes</a>. You can
|
||||
get the new class libraries from <a
|
||||
href="download.html#july-19">here</a>
|
||||
|
||||
** Jul 17, 2001
|
||||
|
||||
Another release of the class libraries is out, check the <a
|
||||
href="archive/mcs-17">MCS 17-July Release Notes</a>. You can
|
||||
get the new class libraries from <a
|
||||
href="download.html#july-17">here</a>
|
||||
|
||||
Do not forget to check out the updated <a href="faq.html">FAQ</a>.
|
||||
|
||||
Got Sean's new <a href="class-status/index.html">Class
|
||||
Status</a> web pages up. These are a lot better than mine, and
|
||||
we are now keeping better track of contributors.
|
||||
|
||||
** Jul 15, 2001
|
||||
|
||||
Another release of Mono is out, check the <a
|
||||
href="archive/mono-0.4">Mono 0.4 Release Notes</a>. Get it <a
|
||||
href="download.html#july-15">here</a>.
|
||||
|
||||
** Jul 14, 2001
|
||||
|
||||
A <a
|
||||
@@ -73,7 +13,25 @@
|
||||
|
||||
** Jul 9, 2001
|
||||
|
||||
Project launched.
|
||||
Today <a href="http://www.ximian.com">Ximian</a> announced the
|
||||
launch of the Mono
|
||||
project, an effort to create a free software
|
||||
(sometimes called open source) implementation of the .NET
|
||||
Development Framework.
|
||||
|
||||
If you have questions about the
|
||||
project, please read our list of <a
|
||||
href="faq.html">Frequently Asked Questions</a>.
|
||||
|
||||
You might also want to <a href="download.html">Download the
|
||||
source</a> for our work so far.
|
||||
|
||||
You might want to <a
|
||||
href="resources.html#mailing">subscribe</a> to our mono-list
|
||||
and mono-announce-list
|
||||
|
||||
You can contact the team at: <a
|
||||
href="mailto:[email protected]">[email protected]</a>
|
||||
|
||||
** O'Reilly
|
||||
|
||||
|
||||
@@ -207,18 +207,6 @@
|
||||
Currently, we are too far from the point where this is a real
|
||||
issue.
|
||||
|
||||
** Passport and endangering Open Source.
|
||||
|
||||
A few people have said: `Mono will allow Passport to be
|
||||
available for Linux and that is bad'. This is plain
|
||||
miss-information.
|
||||
|
||||
Currently, you can obtain Passport for Linux from Microsoft
|
||||
itself and deploy it today on your Web server. Mono does not
|
||||
even enter the picture here. Go to passport.com and download
|
||||
the toolkit and you will see with your own eyes that passport
|
||||
is <B>already</b> available for Linux.
|
||||
|
||||
** Disclaimer
|
||||
|
||||
This is just a group of personal thoughts of mine that I have
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
To: [email protected], [email protected]
|
||||
Subject: July 12 snapshots.
|
||||
FCC: ~/Mail/outbox.txt
|
||||
X-Windows: Sometimes you fill a vacuum and it still sucks.
|
||||
--text follows this line--
|
||||
|
||||
Hey!
|
||||
|
||||
July 12 snapshots of class libraries, the compiler and the mono
|
||||
runtime are available.
|
||||
|
||||
New on this release:
|
||||
|
||||
* Runtime (module: mono)
|
||||
|
||||
The beginning of a simple interpreter that Paolo started
|
||||
workign on (can run really simple .NET programs).
|
||||
|
||||
Disassembler copes with more elements of the binary format and
|
||||
more tokens are decoded. Paolo is working now on moving some
|
||||
of these to the metadata library.
|
||||
|
||||
More tables are dumped.
|
||||
|
||||
* Class libraries (module: mcs/class)
|
||||
|
||||
Many new more classes are in from Joe, Vladimir, Jeff, Sean
|
||||
and yours truly.
|
||||
|
||||
Sean fixed the build process, and it is now possible to
|
||||
compile with a single command the assemblies. We will be
|
||||
revisiting this mechanism in the future to compile per-OS
|
||||
assemblies (ie, Unix, Windows, MacOS, etc).
|
||||
|
||||
* Compiler (module mcs/mcs)
|
||||
|
||||
Not much done this week, just a few fixes here and there, and
|
||||
more work to make it easy to compiler.
|
||||
|
||||
* Documentation (module: mono/doc)
|
||||
|
||||
All the changes to the web site are there for your browsing
|
||||
pleasure. We still need to integrate the status system in
|
||||
there.
|
||||
|
||||
Miguel.
|
||||
@@ -1,43 +0,0 @@
|
||||
To: [email protected]
|
||||
Subject: Sunday snapshot available.
|
||||
Gcc: mail.2001-07
|
||||
--text follows this line--
|
||||
|
||||
Hey guys,
|
||||
|
||||
I promise I will not be doing these so often once we have the CVS
|
||||
server up. In the meantime:
|
||||
|
||||
* MCS
|
||||
|
||||
Sean got the classes to compile in a single go. You
|
||||
will need CygWin (www.cygwin.org) to compile though
|
||||
(GNU make and stuff is required).
|
||||
|
||||
System.Xml.XmlReader contribution from Jason
|
||||
(WOOHHOO!!). It also contains a nice test-suite for
|
||||
his functions, and in his new code bit, his
|
||||
implementation is faster than Microsoft's
|
||||
|
||||
We now ship `jay' as part of the distribution to allow
|
||||
you to compile the compiler with the same `make'
|
||||
command. Small fixes to the parser as well were
|
||||
introduced.
|
||||
|
||||
* Mono 0.4
|
||||
|
||||
Paolo's interpreter supports call instructions and has
|
||||
the test suite program that he posted about.
|
||||
|
||||
|
||||
All documentation ships now in the mono-0.4.tar.gz
|
||||
|
||||
Notes:
|
||||
|
||||
As usual, MCS is targeted to be compiled on a Windows machine
|
||||
(you will need Cygwin).
|
||||
|
||||
Mono is targeted to be compiled on a Unix machine or a Windows
|
||||
machine running Cygwin.
|
||||
|
||||
Miguel.
|
||||
@@ -77,7 +77,6 @@
|
||||
|
||||
* <a
|
||||
href="http://www.southern-storm.com.au/portable_net.html">Portable.NET:</a>
|
||||
Another implementation of the CLI and C# compiler.
|
||||
|
||||
* <a href="http://nunit.sourceforge.net">NUnit:</a> A
|
||||
testing framework for .NET classes.
|
||||
|
||||
+11
-19
@@ -1,13 +1,17 @@
|
||||
* The Mono runtime
|
||||
The MonoNet runtime
|
||||
|
||||
The Mono runtime will implement the JIT engine (and a byte
|
||||
The MonoNet runtime will implement the JIT engine (and a byte
|
||||
code interpreter for quickly porting to new systems), the
|
||||
class loader, the garbage collector, threading system and
|
||||
metadata access libraries.
|
||||
|
||||
Currently the runtime has an image loader and metadata access
|
||||
entry points. The runtime comes with a simple interpreter
|
||||
that can execute very simple programs.
|
||||
Currently the runtime contains the beginning of an image
|
||||
loader and metadata access entry points. Since Beta2 has been
|
||||
now released, it is possible to resume work using the ECMA
|
||||
specs and testing with Beta2-generated executables.
|
||||
|
||||
The runtime core will be implemented in C, in a library
|
||||
"libMonoVES.so".
|
||||
|
||||
** Executing MSIL/CIL images
|
||||
|
||||
@@ -96,17 +100,9 @@
|
||||
* Garbage collection list and FAQ:<br>
|
||||
<a href="http://www.iecc.com/gclist/">http://www.iecc.com/gclist/</a>
|
||||
|
||||
* "GC points in a Threaded Environment":<br>
|
||||
<a href="http://research.sun.com/techrep/1998/abstract-70.html">
|
||||
http://research.sun.com/techrep/1998/abstract-70.html</a>
|
||||
|
||||
* "A Generational Mostly-concurrent Garbage Collector":
|
||||
<a href="http://http://research.sun.com/techrep/2000/abstract-88.html">
|
||||
http://http://research.sun.com/techrep/2000/abstract-88.html</a>
|
||||
|
||||
* Details on The Microsoft .NET Garbage Collection Implementation:<br>
|
||||
* The Microsoft .NET Garbage Collection Implementation:<br>
|
||||
<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmag00/html/GCI.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmag00/html/GCI.asp</a>
|
||||
<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmag00/html/GCI.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmag00/html/GCI.asp</a>
|
||||
<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmag00/html/GCI2.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmag00/html/GCI2.asp</a>
|
||||
</ul>
|
||||
|
||||
** Useful links
|
||||
@@ -135,7 +131,3 @@
|
||||
calls, these in turn are required for reusing some of the
|
||||
GNOME libraries that will reduce the work we have to do to
|
||||
deliver a complete class library.
|
||||
|
||||
To implement PInvoke we are looking into using the <a
|
||||
href="http://sources.redhat.com/libffi">Foreign Function
|
||||
Interface</a> Library from Cygnus.
|
||||
+16
-10
@@ -10,29 +10,35 @@
|
||||
|
||||
* Metadata library: Can currently parse and load
|
||||
information from .NET modules (executables and DLL
|
||||
files).
|
||||
files). It has a few bugs outstanding (table
|
||||
dimension computation is incorrect).
|
||||
|
||||
Parsing of Exception tables is missing.
|
||||
|
||||
It lacks Token to (Table, Index) mapping, but this
|
||||
should be trivial to write.
|
||||
|
||||
* Disassembler: Can disassemble .NET modules. Still
|
||||
lacking exception handling as well as useful debugging
|
||||
tools (hex dumping, token dumping).
|
||||
|
||||
* Class Libraries: You can check the current status in the
|
||||
<a href="class-status.html">Class Status page</a>
|
||||
* Class Libraries: Only a few classes have been
|
||||
implemented.
|
||||
</ul>
|
||||
|
||||
Tasks on the critical path:
|
||||
|
||||
<ul>
|
||||
* Bytecode interpreter: (Paolo is working on this).
|
||||
* Method and Field resolution.
|
||||
|
||||
* Simple JIT: Not implemented yet (Miguel is
|
||||
researching the code-generator generator)
|
||||
* Bytecode interpreter: Not implemented yet.
|
||||
|
||||
* Garbage collection engine (Dick is working on this, his contact is <a
|
||||
href="mailto:[email protected]">[email protected]</a>
|
||||
* Simple JIT: Not implemented yet.
|
||||
|
||||
* Garbage collection engine.
|
||||
</ul>
|
||||
|
||||
If you want to work on any task here, please mail <a
|
||||
href="mailto:[email protected]">[email protected]</a>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,64 +4,22 @@
|
||||
Mono-based solution. Some of these tools can be developed on
|
||||
Windows before Mono is fully finished.
|
||||
|
||||
All of these tools should be written using C#.
|
||||
|
||||
For the tools that are typically command line tools: Try to
|
||||
write these as components that could load their input from
|
||||
streams or collections of streams, and implement the command
|
||||
line tools as wrappers around those classes.
|
||||
|
||||
For example, we will be making the C# compiler a component
|
||||
that could be reused by applications that might have a use for
|
||||
the various bits of the compiler (either to embed the
|
||||
compiler, or reuse the code generator part of it).
|
||||
|
||||
This is important so that these components (compiler,
|
||||
assembler, linker, etc) can be integrated later into the
|
||||
visual development environment (hopefully with the help of the
|
||||
SharpDevelop hackers).
|
||||
|
||||
TODO=ilasm,IL Assembler
|
||||
** IL Assembler.
|
||||
|
||||
This assembler should basically take as input a file
|
||||
containing IL bytecodes as specified in the `Partition II' of
|
||||
the ECMA spec, and produce a binary file.
|
||||
|
||||
TODO=al,Assembly Linker
|
||||
** Assembly Linker.
|
||||
|
||||
This tool is used to construct assemblies, which are basically
|
||||
deployment units for CLI executables.
|
||||
|
||||
TODO=debugger,Debugger
|
||||
** Debugger
|
||||
|
||||
We will need a debugging API to debug CLI applications and
|
||||
then a debugger component that can be used in an IDE
|
||||
environment.
|
||||
|
||||
TODO=ide,Integrated Development Environment
|
||||
** Integrated Development Environment
|
||||
|
||||
There is already a project to create a C# development
|
||||
environment: <a
|
||||
href="http://www.icsharpcode.net/OpenSource/SD/default.asp">SharpDevelop</a>.
|
||||
People should work with the SharpDevelop hackers to produce a
|
||||
unified development environment.
|
||||
environment (SharpDevelop). People could work with the
|
||||
SharpDevelop hackers to produce a unified development environment.
|
||||
|
||||
Please work with the SharpDevelop hackers to build a good IDE.
|
||||
We will work on creating an embedable compiler component and
|
||||
an embeddable debugger component that can be used withing
|
||||
SharpDevelop
|
||||
|
||||
TODO=hbrowser,Help Browser
|
||||
** Help Browser
|
||||
|
||||
We need a good help browser that can be used to browse
|
||||
documentation. Ideally this help browser can accept as input
|
||||
XML Docbook input and an assorted set of file formats
|
||||
(Microsoft Help, Unix manual pages, Unix Info pages)
|
||||
We need a good help browser that can be used to browse all the
|
||||
Mono documentation.
|
||||
|
||||
|
||||
|
||||
Look at the GNOME DevHelp for a good set of ideas on how to
|
||||
implement this.
|
||||
+2
-4
@@ -14,13 +14,11 @@ while (<>){
|
||||
} elsif (/^\t\t\* (.*)$/) {
|
||||
print "<li>$1\n";
|
||||
} elsif (/^Q: (.*)$/){
|
||||
print "<p><a name=\"q$q\"></a><b>Question $q:</b> $1\n";
|
||||
print "<p><a name=\"q$q\"><b>Question $q:</b> $1\n";
|
||||
$q++;
|
||||
} elsif (/^A: (.*)$/){
|
||||
print "$1\n";
|
||||
} elsif (/^TODO=(.*),$/){
|
||||
print "<a name=\"$1\">\n";
|
||||
} else {
|
||||
} else {
|
||||
print "$_\n";
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.3 KiB |
@@ -47,13 +47,13 @@
|
||||
</table>
|
||||
</td>
|
||||
<td bgcolor="black" width="1"><img src="images/pixel.gif" width="1"></td>
|
||||
<td bgcolor="white" align="left" width="80%" valign="top">
|
||||
<td bgcolor="white">
|
||||
<table cellpadding="16">
|
||||
<tr><td>
|
||||
#CONTENT#
|
||||
</td></tr>
|
||||
</table>
|
||||
</td>
|
||||
</td>
|
||||
<td bgcolor="black"><img src="images/pixel.gif" width="1"></td>
|
||||
<td width="100"><img src="images/pixel.gif"></td>
|
||||
</tr>
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
2001-07-20 Patrik Torstensson ([email protected])
|
||||
|
||||
* Added directory: System.Web.Caching
|
||||
@@ -1,520 +0,0 @@
|
||||
//
|
||||
// System.Web.Caching
|
||||
//
|
||||
// Author:
|
||||
// Patrik Torstensson ([email protected])
|
||||
//
|
||||
// (C) Copyright Patrik Torstensson, 2001
|
||||
//
|
||||
namespace System.Web.Caching
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements a cache for Web applications and other. The difference from the MS.NET implementation is that we
|
||||
/// support to use the Cache object as cache in our applications.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The Singleton cache is created per application domain, and it remains valid as long as the application domain remains active.
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// Usage of the singleton cache:
|
||||
///
|
||||
/// Cache objManager = Cache.SingletonCache;
|
||||
///
|
||||
/// String obj = "tobecached";
|
||||
/// objManager.Add("kalle", obj);
|
||||
/// </example>
|
||||
public class Cache : System.Collections.IEnumerable, System.IDisposable
|
||||
{
|
||||
// Declarations
|
||||
|
||||
// MS.NET Does only have the cache connected to the HttpRuntime and we don't have the HttpRuntime (yet)
|
||||
static Cache objSingletonCache = new Cache();
|
||||
|
||||
private bool _boolDisposed;
|
||||
|
||||
// Helper objects
|
||||
private CacheExpires _objExpires;
|
||||
|
||||
// The data storage
|
||||
// Todo: Make a specialized storage for the cache entries?
|
||||
// todo: allow system to replace the storage?
|
||||
private System.Collections.Hashtable _arrEntries;
|
||||
private System.Threading.ReaderWriterLock _lockEntries;
|
||||
|
||||
static private System.TimeSpan _datetimeOneYear = System.TimeSpan.FromDays(365);
|
||||
|
||||
// Number of items in the cache
|
||||
private long _longItems;
|
||||
|
||||
// Constructor
|
||||
public Cache()
|
||||
{
|
||||
_boolDisposed = false;
|
||||
_longItems = 0;
|
||||
|
||||
_lockEntries = new System.Threading.ReaderWriterLock();
|
||||
_arrEntries = new System.Collections.Hashtable();
|
||||
|
||||
_objExpires = new CacheExpires(this);
|
||||
}
|
||||
|
||||
// Public methods and properties
|
||||
|
||||
//
|
||||
/// <summary>
|
||||
/// Returns a static version of the cache. In MS.NET the cache is stored in the System.Web.HttpRuntime
|
||||
/// but we keep it here as a singleton (right now anyway).
|
||||
/// </summary>
|
||||
public static Cache SingletonCache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (objSingletonCache == null)
|
||||
{
|
||||
throw new System.InvalidOperationException();
|
||||
}
|
||||
|
||||
return objSingletonCache;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used in the absoluteExpiration parameter in an Insert method call to indicate the item should never expire. This field is read-only.
|
||||
/// </summary>
|
||||
public static readonly System.DateTime NoAbsoluteExpiration = System.DateTime.MaxValue;
|
||||
|
||||
/// <summary>
|
||||
/// Used as the slidingExpiration parameter in an Insert method call to disable sliding expirations. This field is read-only.
|
||||
/// </summary>
|
||||
public static readonly System.TimeSpan NoSlidingExpiration = System.TimeSpan.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// Internal method to create a enumerator and over all public items in the cache and is used by GetEnumerator method.
|
||||
/// </summary>
|
||||
/// <returns>Returns IDictionaryEnumerator that contains all public items in the cache</returns>
|
||||
private System.Collections.IDictionaryEnumerator CreateEnumerator()
|
||||
{
|
||||
System.Collections.Hashtable objTable;
|
||||
|
||||
_lockEntries.AcquireReaderLock(int.MaxValue);
|
||||
try
|
||||
{
|
||||
// Create a new hashtable to return as collection of public items
|
||||
objTable = new System.Collections.Hashtable(_arrEntries.Count);
|
||||
|
||||
foreach(System.Collections.DictionaryEntry objEntry in _arrEntries)
|
||||
{
|
||||
if (objEntry.Key != null)
|
||||
{
|
||||
// Check if this is a public entry
|
||||
if (((CacheEntry) objEntry.Value).TestFlag(CacheEntry.Flags.Public))
|
||||
{
|
||||
// Add to the collection
|
||||
objTable.Add(objEntry.Key, ((CacheEntry) objEntry.Value).Item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_lockEntries.ReleaseReaderLock();
|
||||
}
|
||||
|
||||
return objTable.GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of IEnumerable interface and calls the GetEnumerator that returns
|
||||
/// IDictionaryEnumerator.
|
||||
/// </summary>
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Virtual override of the IEnumerable.GetEnumerator() method, returns a specialized enumerator.
|
||||
/// </summary>
|
||||
public virtual System.Collections.IDictionaryEnumerator GetEnumerator()
|
||||
{
|
||||
return CreateEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Touches a object in the cache. Used to update expire time and hit count.
|
||||
/// </summary>
|
||||
/// <param name="strKey">The identifier for the cache item to retrieve.</param>
|
||||
public void Touch(string strKey)
|
||||
{
|
||||
// Just touch the object
|
||||
Get(strKey);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified item to the Cache object with dependencies, expiration and priority policies, and a
|
||||
/// delegate you can use to notify your application when the inserted item is removed from the Cache.
|
||||
/// </summary>
|
||||
/// <param name="strKey">The cache key used to reference the item.</param>
|
||||
/// <param name="objItem">The item to be added to the cache.</param>
|
||||
/// <param name="objDependency">The file or cache key dependencies for the item. When any dependency changes, the object becomes invalid and is removed from the cache. If there are no dependencies, this paramter contains a null reference.</param>
|
||||
/// <param name="absolutExpiration">The time at which the added object expires and is removed from the cache. </param>
|
||||
/// <param name="slidingExpiration">The interval between the time the added object was last accessed and when that object expires. If this value is the equivalent of 20 minutes, the object expires and is removed from the cache 20 minutes after it is last accessed.</param>
|
||||
/// <param name="enumPriority">The relative cost of the object, as expressed by the CacheItemPriority enumeration. The cache uses this value when it evicts objects; objects with a lower cost are removed from the cache before objects with a higher cost.</param>
|
||||
/// <param name="enumPriorityDecay">The rate at which an object in the cache decays in importance. Objects that decay quickly are more likely to be removed.</param>
|
||||
/// <param name="eventRemoveCallback">A delegate that, if provided, is called when an object is removed from the cache. You can use this to notify applications when their objects are deleted from the cache.</param>
|
||||
/// <returns>The Object item added to the Cache.</returns>
|
||||
public object Add(string strKey, object objItem, CacheDependency objDependency, System.DateTime absolutExpiration, System.TimeSpan slidingExpiration, CacheItemPriority enumPriority, CacheItemPriorityDecay enumPriorityDecay, CacheItemRemovedCallback eventRemoveCallback)
|
||||
{
|
||||
if (_boolDisposed)
|
||||
{
|
||||
throw new System.ObjectDisposedException("System.Web.Cache");
|
||||
}
|
||||
|
||||
if (strKey == null)
|
||||
{
|
||||
throw new System.ArgumentNullException("strKey");
|
||||
}
|
||||
|
||||
if (objItem == null)
|
||||
{
|
||||
throw new System.ArgumentNullException("objItem");
|
||||
}
|
||||
|
||||
if (slidingExpiration > _datetimeOneYear)
|
||||
{
|
||||
throw new System.ArgumentOutOfRangeException("slidingExpiration");
|
||||
}
|
||||
|
||||
CacheEntry objEntry;
|
||||
CacheEntry objNewEntry;
|
||||
|
||||
long longHitRange = 10000;
|
||||
|
||||
// todo: check decay and make up the minHit range
|
||||
|
||||
objEntry = new CacheEntry(this, strKey, objItem, objDependency, eventRemoveCallback, absolutExpiration, slidingExpiration, longHitRange, true, enumPriority);
|
||||
|
||||
System.Threading.Interlocked.Increment(ref _longItems);
|
||||
|
||||
// If we have any kind of expiration add into the CacheExpires class
|
||||
if (objEntry.HasSlidingExpiration || objEntry.HasAbsoluteExpiration)
|
||||
{
|
||||
// Add it to CacheExpires
|
||||
_objExpires.Add(objEntry);
|
||||
}
|
||||
|
||||
// Check and get the new item..
|
||||
objNewEntry = UpdateCache(strKey, objEntry, true, CacheItemRemovedReason.Removed);
|
||||
|
||||
if (objNewEntry != null)
|
||||
{
|
||||
// Return added item
|
||||
return objEntry.Item;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts an item into the Cache object with a cache key to reference its location and using default values
|
||||
/// provided by the CacheItemPriority and CacheItemPriorityDecay enumerations.
|
||||
/// </summary>
|
||||
/// <param name="strKey">The cache key used to reference the item.</param>
|
||||
/// <param name="objItem">The item to be added to the cache.</param>
|
||||
public void Insert(string strKey, object objItem)
|
||||
{
|
||||
Add(strKey, objItem, null, System.DateTime.MaxValue, System.TimeSpan.Zero, CacheItemPriority.Default, CacheItemPriorityDecay.Default, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts an object into the Cache that has file or key dependencies.
|
||||
/// </summary>
|
||||
/// <param name="strKey">The cache key used to reference the item.</param>
|
||||
/// <param name="objItem">The item to be added to the cache.</param>
|
||||
/// <param name="objDependency">The file or cache key dependencies for the item. When any dependency changes, the object becomes invalid and is removed from the cache. If there are no dependencies, this paramter contains a null reference.</param>
|
||||
public void Insert(string strKey, object objItem, CacheDependency objDependency)
|
||||
{
|
||||
Add(strKey, objItem, objDependency, System.DateTime.MaxValue, System.TimeSpan.Zero, CacheItemPriority.Default, CacheItemPriorityDecay.Default, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts an object into the Cache with dependencies and expiration policies.
|
||||
/// </summary>
|
||||
/// <param name="strKey">The cache key used to reference the item.</param>
|
||||
/// <param name="objItem">The item to be added to the cache.</param>
|
||||
/// <param name="objDependency">The file or cache key dependencies for the item. When any dependency changes, the object becomes invalid and is removed from the cache. If there are no dependencies, this paramter contains a null reference.</param>
|
||||
/// <param name="absolutExpiration">The time at which the added object expires and is removed from the cache. </param>
|
||||
/// <param name="slidingExpiration">The interval between the time the added object was last accessed and when that object expires. If this value is the equivalent of 20 minutes, the object expires and is removed from the cache 20 minutes after it is last accessed.</param>
|
||||
public void Insert(string strKey, object objItem, CacheDependency objDependency, System.DateTime absolutExpiration, System.TimeSpan slidingExpiration)
|
||||
{
|
||||
Add(strKey, objItem, objDependency, absolutExpiration, slidingExpiration, CacheItemPriority.Default, CacheItemPriorityDecay.Default, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts an object into the Cache object with dependencies, expiration and priority policies, and a delegate
|
||||
/// you can use to notify your application when the inserted item is removed from the Cache.
|
||||
/// </summary>
|
||||
/// <param name="strKey">The cache key used to reference the item.</param>
|
||||
/// <param name="objItem">The item to be added to the cache.</param>
|
||||
/// <param name="objDependency">The file or cache key dependencies for the item. When any dependency changes, the object becomes invalid and is removed from the cache. If there are no dependencies, this paramter contains a null reference.</param>
|
||||
/// <param name="absolutExpiration">The time at which the added object expires and is removed from the cache. </param>
|
||||
/// <param name="slidingExpiration">The interval between the time the added object was last accessed and when that object expires. If this value is the equivalent of 20 minutes, the object expires and is removed from the cache 20 minutes after it is last accessed.</param>
|
||||
/// <param name="enumPriority">The relative cost of the object, as expressed by the CacheItemPriority enumeration. The cache uses this value when it evicts objects; objects with a lower cost are removed from the cache before objects with a higher cost.</param>
|
||||
/// <param name="enumPriorityDecay">The rate at which an object in the cache decays in importance. Objects that decay quickly are more likely to be removed.</param>
|
||||
/// <param name="eventRemoveCallback">A delegate that, if provided, is called when an object is removed from the cache. You can use this to notify applications when their objects are deleted from the cache.</param>
|
||||
public void Insert(string strKey, object objItem, CacheDependency objDependency, System.DateTime absolutExpiration, System.TimeSpan slidingExpiration, CacheItemPriority enumPriority, CacheItemPriorityDecay enumPriorityDecay, CacheItemRemovedCallback eventRemoveCallback)
|
||||
{
|
||||
Add(strKey, objItem, objDependency, absolutExpiration, slidingExpiration, enumPriority, enumPriorityDecay, eventRemoveCallback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the specified item from the Cache object.
|
||||
/// </summary>
|
||||
/// <param name="strKey">The cache key for the cache item to remove.</param>
|
||||
/// <returns>The item removed from the Cache. If the value in the key parameter is not found, returns a null reference.</returns>
|
||||
public object Remove(string strKey)
|
||||
{
|
||||
return Remove(strKey, CacheItemRemovedReason.Removed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal method that updates the cache, decremenents the number of existing items and call close on the cache entry. This method
|
||||
/// is also used from the ExpiresBuckets class to remove an item during GC flush.
|
||||
/// </summary>
|
||||
/// <param name="strKey">The cache key for the cache item to remove.</param>
|
||||
/// <param name="enumReason">Reason why the item is removed.</param>
|
||||
/// <returns>The item removed from the Cache. If the value in the key parameter is not found, returns a null reference.</returns>
|
||||
internal object Remove(string strKey, CacheItemRemovedReason enumReason)
|
||||
{
|
||||
CacheEntry objEntry = UpdateCache(strKey, null, true, enumReason);
|
||||
|
||||
if (objEntry != null)
|
||||
{
|
||||
System.Threading.Interlocked.Decrement(ref _longItems);
|
||||
|
||||
// Close the cache entry (calls the remove delegate)
|
||||
objEntry.Close(enumReason);
|
||||
|
||||
return objEntry.Item;
|
||||
} else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the specified item from the Cache object.
|
||||
/// </summary>
|
||||
/// <param name="strKey">The identifier for the cache item to retrieve.</param>
|
||||
/// <returns>The retrieved cache item, or a null reference.</returns>
|
||||
public object Get(string strKey)
|
||||
{
|
||||
CacheEntry objEntry = UpdateCache(strKey, null, false, CacheItemRemovedReason.Expired);
|
||||
|
||||
if (objEntry == null)
|
||||
{
|
||||
return null;
|
||||
} else
|
||||
{
|
||||
return objEntry.Item;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal method used for removing, updating and adding CacheEntries into the cache.
|
||||
/// </summary>
|
||||
/// <param name="strKey">The identifier for the cache item to modify</param>
|
||||
/// <param name="objEntry">CacheEntry to use for overwrite operation, if this parameter is null and overwrite true the item is going to be removed</param>
|
||||
/// <param name="boolOverwrite">If true the objEntry parameter is used to overwrite the strKey entry</param>
|
||||
/// <param name="enumReason">Reason why an item was removed</param>
|
||||
/// <returns></returns>
|
||||
private CacheEntry UpdateCache(string strKey, CacheEntry objEntry, bool boolOverwrite, CacheItemRemovedReason enumReason)
|
||||
{
|
||||
if (_boolDisposed)
|
||||
{
|
||||
throw new System.ObjectDisposedException("System.Web.Cache", "Can't update item(s) in a disposed cache");
|
||||
}
|
||||
|
||||
if (strKey == null)
|
||||
{
|
||||
throw new System.ArgumentNullException("System.Web.Cache");
|
||||
}
|
||||
|
||||
long ticksNow = System.DateTime.Now.Ticks;
|
||||
long ticksExpires = long.MaxValue;
|
||||
|
||||
bool boolGetItem = false;
|
||||
bool boolExpiried = false;
|
||||
bool boolWrite = false;
|
||||
bool boolRemoved = false;
|
||||
|
||||
// Are we getting the item from the hashtable
|
||||
if (boolOverwrite == false && strKey.Length > 0 && objEntry == null)
|
||||
{
|
||||
boolGetItem = true;
|
||||
}
|
||||
|
||||
// TODO: Optimize this method, move out functionality outside the lock
|
||||
_lockEntries.AcquireReaderLock(int.MaxValue);
|
||||
try
|
||||
{
|
||||
if (boolGetItem)
|
||||
{
|
||||
objEntry = (CacheEntry) _arrEntries[strKey];
|
||||
if (objEntry == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (objEntry != null)
|
||||
{
|
||||
// Check if we have expired
|
||||
if (objEntry.HasSlidingExpiration || objEntry.HasAbsoluteExpiration)
|
||||
{
|
||||
if (objEntry.Expires < ticksNow)
|
||||
{
|
||||
// We have expired, remove the item from the cache
|
||||
boolWrite = true;
|
||||
boolExpiried = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we going to modify the hashtable
|
||||
if (boolWrite || (boolOverwrite && !boolExpiried))
|
||||
{
|
||||
// Upgrade our lock to write
|
||||
System.Threading.LockCookie objCookie = _lockEntries.UpgradeToWriterLock(int.MaxValue);
|
||||
try
|
||||
{
|
||||
// Check if we going to just modify an existing entry (or add)
|
||||
if (boolOverwrite && objEntry != null)
|
||||
{
|
||||
_arrEntries[strKey] = objEntry;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We need to remove the item, fetch the item first
|
||||
objEntry = (CacheEntry) _arrEntries[strKey];
|
||||
if (objEntry != null)
|
||||
{
|
||||
_arrEntries.Remove(strKey);
|
||||
}
|
||||
|
||||
boolRemoved = true;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_lockEntries.DowngradeFromWriterLock(ref objCookie);
|
||||
}
|
||||
}
|
||||
|
||||
// If the entry haven't expired or been removed update the info
|
||||
if (!boolExpiried && !boolRemoved)
|
||||
{
|
||||
// Update that we got a hit
|
||||
objEntry.Hits++;
|
||||
if (objEntry.HasSlidingExpiration)
|
||||
{
|
||||
ticksExpires = ticksNow + objEntry.SlidingExpiration;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_lockEntries.ReleaseLock();
|
||||
|
||||
}
|
||||
|
||||
// If the item was removed we need to remove it from the CacheExpired class also
|
||||
if (boolRemoved)
|
||||
{
|
||||
if (objEntry != null)
|
||||
{
|
||||
if (objEntry.HasAbsoluteExpiration || objEntry.HasSlidingExpiration)
|
||||
{
|
||||
_objExpires.Remove(objEntry);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the entry, it's not up to the UpdateCache to call Close on the entry
|
||||
return objEntry;
|
||||
}
|
||||
|
||||
// If we have sliding expiration and we have a correct hit, update the expiration manager
|
||||
if (objEntry.HasSlidingExpiration)
|
||||
{
|
||||
_objExpires.Update(objEntry, ticksExpires);
|
||||
}
|
||||
|
||||
// Return the cache entry
|
||||
return objEntry;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of items stored in the cache.
|
||||
/// </summary>
|
||||
long Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return _longItems;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the cache item at the specified key.
|
||||
/// </summary>
|
||||
public object this[string strKey]
|
||||
{
|
||||
get
|
||||
{
|
||||
return Get(strKey);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Insert(strKey, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called to close the cache when the AppDomain is closing down or the GC has decided it's time to destroy the object.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
_boolDisposed = true;
|
||||
|
||||
_lockEntries.AcquireReaderLock(int.MaxValue);
|
||||
try
|
||||
{
|
||||
foreach(System.Collections.DictionaryEntry objEntry in _arrEntries)
|
||||
{
|
||||
if (objEntry.Key != null)
|
||||
{
|
||||
// Check if this is active
|
||||
if ( ((CacheEntry) objEntry.Value).TestFlag(CacheEntry.Flags.Removed) )
|
||||
{
|
||||
try
|
||||
{
|
||||
((CacheEntry) objEntry.Value).Close(CacheItemRemovedReason.Removed);
|
||||
}
|
||||
catch (System.Exception objException)
|
||||
{
|
||||
System.Diagnostics.Debug.Fail("System.Web.Cache.Dispose() Exception when closing cache entry", "Message: " + objException.Message + " Stack: " + objException.StackTrace + " Source:" + objException.Source);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_lockEntries.ReleaseReaderLock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
//
|
||||
// System.Web.Caching
|
||||
//
|
||||
// Author:
|
||||
// Patrik Torstensson ([email protected])
|
||||
//
|
||||
// (C) Copyright Patrik Torstensson, 2001
|
||||
//
|
||||
namespace System.Web.Caching
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies the relative priority of items stored in the Cache.
|
||||
/// </summary>
|
||||
public enum CacheItemPriority {
|
||||
AboveNormal,
|
||||
BelowNormal,
|
||||
Default,
|
||||
High,
|
||||
Low,
|
||||
Normal,
|
||||
NotRemovable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the rate at which the priority of items stored in the Cache are downgraded when not accessed frequently.
|
||||
/// </summary>
|
||||
public enum CacheItemPriorityDecay {
|
||||
Default,
|
||||
Fast,
|
||||
Medium,
|
||||
Never,
|
||||
Slow
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the reason an item was removed from the Cache.
|
||||
/// </summary>
|
||||
public enum CacheItemRemovedReason {
|
||||
DependencyChanged,
|
||||
Expired,
|
||||
Removed,
|
||||
Underused
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines a callback method for notifying applications when a cached item is removed from the Cache.
|
||||
/// </summary>
|
||||
/// <param name="key">The index location for the item removed from the cache. </param>
|
||||
/// <param name="value">The Object item removed from the cache. </param>
|
||||
/// <param name="reason">The reason the item was removed from the cache, as specified by the CacheItemRemovedReason enumeration.</param>
|
||||
public delegate void CacheItemRemovedCallback(string key, object value, CacheItemRemovedReason reason);
|
||||
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
//
|
||||
// System.Web.Caching
|
||||
//
|
||||
// Author:
|
||||
// Patrik Torstensson ([email protected])
|
||||
//
|
||||
// (C) Copyright Patrik Torstensson, 2001
|
||||
//
|
||||
namespace System.Web.Caching
|
||||
{
|
||||
/// <summary>
|
||||
/// Class to handle cache dependency, right now this class is only a mookup
|
||||
/// </summary>
|
||||
public class CacheDependency : System.IDisposable
|
||||
{
|
||||
private bool _boolDisposed;
|
||||
|
||||
public CacheDependency()
|
||||
{
|
||||
_boolDisposed = false;
|
||||
}
|
||||
|
||||
public delegate void CacheDependencyCallback(CacheDependency objDependency);
|
||||
|
||||
public event CacheDependencyCallback Changed;
|
||||
|
||||
public void OnChanged()
|
||||
{
|
||||
if (_boolDisposed)
|
||||
{
|
||||
throw new System.ObjectDisposedException("System.Web.CacheDependency");
|
||||
}
|
||||
|
||||
if (Changed != null)
|
||||
{
|
||||
Changed(this);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsDisposed
|
||||
{
|
||||
get
|
||||
{
|
||||
return _boolDisposed;
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasEvents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_boolDisposed)
|
||||
{
|
||||
throw new System.ObjectDisposedException("System.Web.CacheDependency");
|
||||
}
|
||||
|
||||
if (Changed != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_boolDisposed = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used in testing.
|
||||
/// </summary>
|
||||
public void Signal()
|
||||
{
|
||||
OnChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,363 +0,0 @@
|
||||
//
|
||||
// System.Web.Caching
|
||||
//
|
||||
// Author:
|
||||
// Patrik Torstensson ([email protected])
|
||||
//
|
||||
// (C) Copyright Patrik Torstensson, 2001
|
||||
//
|
||||
namespace System.Web.Caching
|
||||
{
|
||||
/// <summary>
|
||||
/// Class responsible for representing a cache entry.
|
||||
/// </summary>
|
||||
public class CacheEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the status of the current cache entry
|
||||
/// </summary>
|
||||
public enum Flags
|
||||
{
|
||||
Removed = 0,
|
||||
Public = 1
|
||||
}
|
||||
|
||||
private CacheItemPriority _enumPriority;
|
||||
|
||||
private long _longHits;
|
||||
|
||||
private byte _byteExpiresBucket;
|
||||
private int _intExpiresIndex;
|
||||
|
||||
private long _ticksExpires;
|
||||
private long _ticksSlidingExpiration;
|
||||
|
||||
private string _strKey;
|
||||
private object _objItem;
|
||||
|
||||
private long _longMinHits;
|
||||
|
||||
private Flags _enumFlags;
|
||||
|
||||
private CacheDependency _objDependency;
|
||||
private Cache _objCache;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new cache entry
|
||||
/// </summary>
|
||||
/// <param name="strKey">The cache key used to reference the item.</param>
|
||||
/// <param name="objItem">The item to be added to the cache.</param>
|
||||
/// <param name="objDependency">The file or cache key dependencies for the item. When any dependency changes, the object becomes invalid and is removed from the cache. If there are no dependencies, this paramter contains a null reference.</param>
|
||||
/// <param name="dtExpires">The time at which the added object expires and is removed from the cache. </param>
|
||||
/// <param name="tsSpan">The interval between the time the added object was last accessed and when that object expires. If this value is the equivalent of 20 minutes, the object expires and is removed from the cache 20 minutes after it is last accessed.</param>
|
||||
/// <param name="longMinHits">Used to detect and control if the item should be flushed due to under usage</param>
|
||||
/// <param name="boolPublic">Defines if the item is public or not</param>
|
||||
/// <param name="enumPriority">The relative cost of the object, as expressed by the CacheItemPriority enumeration. The cache uses this value when it evicts objects; objects with a lower cost are removed from the cache before objects with a higher cost.</param>
|
||||
public CacheEntry( Cache objManager, string strKey, object objItem, CacheDependency objDependency, CacheItemRemovedCallback eventRemove,
|
||||
System.DateTime dtExpires, System.TimeSpan tsSpan, long longMinHits, bool boolPublic, CacheItemPriority enumPriority )
|
||||
{
|
||||
if (boolPublic)
|
||||
{
|
||||
SetFlag(Flags.Public);
|
||||
}
|
||||
|
||||
_strKey = strKey;
|
||||
_objItem = objItem;
|
||||
_objCache = objManager;
|
||||
|
||||
_onRemoved += eventRemove;
|
||||
|
||||
_enumPriority = enumPriority;
|
||||
|
||||
_ticksExpires = dtExpires.Ticks;
|
||||
|
||||
_ticksSlidingExpiration = tsSpan.Ticks;
|
||||
|
||||
// If we have a sliding expiration it overrides the absolute expiration (MS behavior)
|
||||
if (tsSpan.Ticks != System.TimeSpan.Zero.Ticks)
|
||||
{
|
||||
_ticksExpires = System.DateTime.Now.AddTicks(_ticksSlidingExpiration).Ticks;
|
||||
}
|
||||
|
||||
_objDependency = objDependency;
|
||||
if (_objDependency != null)
|
||||
{
|
||||
if (_objDependency.IsDisposed)
|
||||
{
|
||||
throw new System.ObjectDisposedException("System.Web.CacheDependency");
|
||||
}
|
||||
|
||||
// Add the entry to the cache dependency handler (we support multiple entries per handler)
|
||||
_objDependency.Changed += new CacheDependency.CacheDependencyCallback(OnChanged);
|
||||
}
|
||||
|
||||
_longMinHits = longMinHits;
|
||||
}
|
||||
|
||||
private event CacheItemRemovedCallback _onRemoved;
|
||||
|
||||
public void OnChanged(CacheDependency objDependency)
|
||||
{
|
||||
_objCache.Remove(_strKey, CacheItemRemovedReason.DependencyChanged);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cleans up the cache entry, removes the cache dependency and calls the remove delegate.
|
||||
/// </summary>
|
||||
/// <param name="enumReason">The reason why the cache entry are going to be removed</param>
|
||||
public void Close(CacheItemRemovedReason enumReason)
|
||||
{
|
||||
lock(this)
|
||||
{
|
||||
// Check if the item already is removed
|
||||
if (TestFlag(Flags.Removed))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SetFlag(Flags.Removed);
|
||||
|
||||
if (_onRemoved != null)
|
||||
{
|
||||
// Call the delegate to tell that we are now removing the entry
|
||||
try
|
||||
{
|
||||
_onRemoved(_strKey, _objItem, enumReason);
|
||||
}
|
||||
catch (System.Exception objException)
|
||||
{
|
||||
System.Diagnostics.Debug.Fail("System.Web.CacheEntry.Close() Exception when calling remove delegate", "Message: " + objException.Message + " Stack: " + objException.StackTrace + " Source:" + objException.Source);
|
||||
}
|
||||
}
|
||||
|
||||
// If we have a dependency, remove the entry
|
||||
if (_objDependency != null)
|
||||
{
|
||||
_objDependency.Changed -= new CacheDependency.CacheDependencyCallback(OnChanged);
|
||||
if (!_objDependency.HasEvents)
|
||||
{
|
||||
_objDependency.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests a specific flag is set or not.
|
||||
/// </summary>
|
||||
/// <param name="oFlag">Flag to test agains</param>
|
||||
/// <returns>Returns true if the flag is set.</returns>
|
||||
public bool TestFlag(Flags oFlag)
|
||||
{
|
||||
lock(this)
|
||||
{
|
||||
if ((_enumFlags & oFlag) != 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a specific flag.
|
||||
/// </summary>
|
||||
/// <param name="oFlag">Flag to set.</param>
|
||||
public void SetFlag(Flags oFlag)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
_enumFlags |= oFlag;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the object has minimum hit usage flushing enabled.
|
||||
/// </summary>
|
||||
public bool HasUsage
|
||||
{
|
||||
get {
|
||||
if (_longMinHits == System.Int64.MaxValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the entry has absolute expiration.
|
||||
/// </summary>
|
||||
public bool HasAbsoluteExpiration
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_ticksExpires == System.DateTime.MaxValue.Ticks)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the entry has sliding expiration enabled.
|
||||
/// </summary>
|
||||
public bool HasSlidingExpiration
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_ticksSlidingExpiration == System.TimeSpan.Zero.Ticks)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets and sets the current expires bucket the entry is active in.
|
||||
/// </summary>
|
||||
public byte ExpiresBucket
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
return _byteExpiresBucket;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
_byteExpiresBucket = ExpiresBucket;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets and sets the current index in the expires bucket of the current cache entry.
|
||||
/// </summary>
|
||||
public int ExpiresIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
return _intExpiresIndex;
|
||||
}
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
_intExpiresIndex = ExpiresIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets and sets the expiration of the cache entry.
|
||||
/// </summary>
|
||||
public long Expires
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
return _ticksExpires;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
_ticksExpires = Expires;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sliding expiration value. The return value is in ticks (since 0/0-01 in 100nanosec)
|
||||
/// </summary>
|
||||
public long SlidingExpiration
|
||||
{
|
||||
get
|
||||
{
|
||||
return _ticksSlidingExpiration;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current cached item.
|
||||
/// </summary>
|
||||
public object Item
|
||||
{
|
||||
get
|
||||
{
|
||||
return _objItem;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current cache identifier.
|
||||
/// </summary>
|
||||
public string Key
|
||||
{
|
||||
get
|
||||
{
|
||||
return _strKey;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets and sets the current number of hits on the cache entry.
|
||||
/// </summary>
|
||||
public long Hits
|
||||
{
|
||||
// todo: Could be optimized by using interlocked methods..
|
||||
get
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
return _longHits;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
_longHits = Hits;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns minimum hits for the usage flushing rutine.
|
||||
/// </summary>
|
||||
public long MinimumHits
|
||||
{
|
||||
get
|
||||
{
|
||||
return _longMinHits;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the priority of the cache entry.
|
||||
/// </summary>
|
||||
public CacheItemPriority Priority
|
||||
{
|
||||
get
|
||||
{
|
||||
return _enumPriority;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
//
|
||||
// System.Web.Caching
|
||||
//
|
||||
// Author:
|
||||
// Patrik Torstensson ([email protected])
|
||||
//
|
||||
// (C) Copyright Patrik Torstensson, 2001
|
||||
//
|
||||
namespace System.Web.Caching
|
||||
{
|
||||
/// <summary>
|
||||
/// Class responsible for handling time based flushing of entries in the cache. The class creates
|
||||
/// and manages 60 buckets each holding every item that expires that minute. The bucket calculated
|
||||
/// for an entry is one minute more than the timeout just to make sure that the item end up in the
|
||||
/// bucket where it should be flushed.
|
||||
/// </summary>
|
||||
public class CacheExpires : System.IDisposable
|
||||
{
|
||||
static int _intFlush;
|
||||
static long _ticksPerBucket = 600000000;
|
||||
static long _ticksPerCycle = _ticksPerBucket * 60;
|
||||
|
||||
private ExpiresBucket[] _arrBuckets;
|
||||
private System.Threading.Timer _objTimer;
|
||||
private Cache _objManager;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="objManager">The cache manager, used when flushing items in a bucket.</param>
|
||||
public CacheExpires(Cache objManager)
|
||||
{
|
||||
_objManager = objManager;
|
||||
Initialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the class.
|
||||
/// </summary>
|
||||
private void Initialize()
|
||||
{
|
||||
// Create one bucket per minute
|
||||
_arrBuckets = new ExpiresBucket[60];
|
||||
|
||||
byte bytePos = 0;
|
||||
do
|
||||
{
|
||||
_arrBuckets[bytePos] = new ExpiresBucket(bytePos, _objManager);
|
||||
bytePos++;
|
||||
} while (bytePos < 60);
|
||||
|
||||
// GC Bucket controller
|
||||
_intFlush = System.DateTime.Now.Minute - 1;
|
||||
_objTimer = new System.Threading.Timer(new System.Threading.TimerCallback(GarbageCleanup), null, 10000, 60000);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a Cache entry to the correct flush bucket.
|
||||
/// </summary>
|
||||
/// <param name="objEntry">Cache entry to add.</param>
|
||||
public void Add(CacheEntry objEntry)
|
||||
{
|
||||
long ticksNow = System.DateTime.Now.Ticks;
|
||||
|
||||
lock(this)
|
||||
{
|
||||
// If the entry doesn't have a expires time we assume that the entry is due to expire now.
|
||||
if (objEntry.Expires == 0)
|
||||
{
|
||||
objEntry.Expires = ticksNow;
|
||||
}
|
||||
|
||||
_arrBuckets[GetHashBucket(objEntry.Expires)].Add(objEntry);
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(CacheEntry objEntry)
|
||||
{
|
||||
long ticksNow = System.DateTime.Now.Ticks;
|
||||
|
||||
lock(this)
|
||||
{
|
||||
// If the entry doesn't have a expires time we assume that the entry is due to expire now.
|
||||
if (objEntry.Expires == 0)
|
||||
{
|
||||
objEntry.Expires = ticksNow;
|
||||
}
|
||||
|
||||
_arrBuckets[GetHashBucket(objEntry.Expires)].Remove(objEntry);
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(CacheEntry objEntry, long ticksExpires)
|
||||
{
|
||||
long ticksNow = System.DateTime.Now.Ticks;
|
||||
|
||||
lock(this)
|
||||
{
|
||||
// If the entry doesn't have a expires time we assume that the entry is due to expire now.
|
||||
if (objEntry.Expires == 0)
|
||||
{
|
||||
objEntry.Expires = ticksNow;
|
||||
}
|
||||
|
||||
_arrBuckets[GetHashBucket(objEntry.Expires)].Update(objEntry, ticksExpires);
|
||||
}
|
||||
}
|
||||
|
||||
public void GarbageCleanup(object State)
|
||||
{
|
||||
ExpiresBucket objBucket;
|
||||
|
||||
lock(this)
|
||||
{
|
||||
// Do cleanup of the bucket
|
||||
objBucket = _arrBuckets[(++_intFlush) % 60];
|
||||
}
|
||||
|
||||
// Flush expired items in the current bucket (defined by _intFlush)
|
||||
objBucket.FlushExpiredItems();
|
||||
}
|
||||
|
||||
private int GetHashBucket(long ticks)
|
||||
{
|
||||
// Get bucket to add expire item into, add one minute to the bucket just to make sure that we get it in the bucket gc
|
||||
return (int) (((((ticks + 60000) % _ticksPerCycle) / _ticksPerBucket) + 1) % 60);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by the cache for cleanup.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
lock(this)
|
||||
{
|
||||
// Cleanup the internal timer
|
||||
if (_objTimer != null)
|
||||
{
|
||||
_objTimer.Dispose();
|
||||
_objTimer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
2001-07-20 Patrik Torstensson ([email protected])
|
||||
|
||||
* Cache.cs: Implemented. (90% ready)
|
||||
* CacheDefinitions.cs: Implemented.
|
||||
* CacheDependency.cs: Added. (20% ready)
|
||||
* CacheExpires: Implemented.
|
||||
* CacheEntry.cs: Implemented. (95% ready, going to be changed due to CacheDependecy support)
|
||||
* ExpiresBuckets.cs: Implemented.
|
||||
@@ -1,253 +0,0 @@
|
||||
//
|
||||
// System.Web.Caching
|
||||
//
|
||||
// Author:
|
||||
// Patrik Torstensson ([email protected])
|
||||
//
|
||||
// (C) Copyright Patrik Torstensson, 2001
|
||||
//
|
||||
namespace System.Web.Caching
|
||||
{
|
||||
/// <summary>
|
||||
/// Responsible for holding a cache entry in the linked list bucket.
|
||||
/// </summary>
|
||||
public struct ExpiresEntry
|
||||
{
|
||||
public CacheEntry _objEntry;
|
||||
public long _ticksExpires;
|
||||
public int _intNext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Holds cache entries that has a expiration in a bucket list.
|
||||
/// </summary>
|
||||
public class ExpiresBucket
|
||||
{
|
||||
private static int MIN_ENTRIES = 16;
|
||||
|
||||
private byte _byteID;
|
||||
private int _intSize;
|
||||
private int _intCount;
|
||||
private int _intNext;
|
||||
|
||||
private Cache _objManager;
|
||||
|
||||
private ExpiresEntry [] _arrEntries;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new bucket.
|
||||
/// </summary>
|
||||
/// <param name="bucket">Current bucket ID.</param>
|
||||
/// <param name="objManager">Cache manager reponsible for the item(s) in the expires bucket.</param>
|
||||
public ExpiresBucket(byte bucket, Cache objManager)
|
||||
{
|
||||
_objManager = objManager;
|
||||
Initialize(bucket);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the expires bucket, creates a linked list of MIN_ENTRIES.
|
||||
/// </summary>
|
||||
/// <param name="bucket">Bucket ID.</param>
|
||||
private void Initialize(byte bucket)
|
||||
{
|
||||
_byteID = bucket;
|
||||
_intNext = 0;
|
||||
_intCount = 0;
|
||||
|
||||
_arrEntries = new ExpiresEntry[MIN_ENTRIES];
|
||||
_intSize = MIN_ENTRIES;
|
||||
|
||||
int intPos = 0;
|
||||
do
|
||||
{
|
||||
_arrEntries[intPos]._intNext = intPos + 1;
|
||||
_arrEntries[intPos]._ticksExpires = System.DateTime.MaxValue.Ticks;
|
||||
|
||||
intPos++;
|
||||
} while (intPos < _intSize);
|
||||
|
||||
_arrEntries[_intSize - 1]._intNext = -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Expands the bucket linked array list.
|
||||
/// </summary>
|
||||
private void Expand()
|
||||
{
|
||||
ExpiresEntry [] arrData;
|
||||
int intPos = 0;
|
||||
int intOldSize;
|
||||
|
||||
lock(this)
|
||||
{
|
||||
intOldSize = _intSize;
|
||||
_intSize *= 2;
|
||||
|
||||
// Create a new array and copy the old data into the new array
|
||||
arrData = new ExpiresEntry[_intSize];
|
||||
do
|
||||
{
|
||||
arrData[intPos] = _arrEntries[intPos];
|
||||
intPos++;
|
||||
} while (intPos < intOldSize);
|
||||
|
||||
_intNext = intPos;
|
||||
|
||||
// Initialize the "new" positions.
|
||||
do
|
||||
{
|
||||
arrData[intPos]._intNext = intPos + 1;
|
||||
intPos++;
|
||||
} while (intPos < _intSize);
|
||||
|
||||
arrData[_intSize - 1]._intNext = -1;
|
||||
|
||||
_arrEntries = arrData;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a cache entry into the expires bucket.
|
||||
/// </summary>
|
||||
/// <param name="objEntry">Cache Entry object to be added.</param>
|
||||
public void Add(CacheEntry objEntry)
|
||||
{
|
||||
if (_intNext == -1)
|
||||
{
|
||||
Expand();
|
||||
}
|
||||
|
||||
lock(this)
|
||||
{
|
||||
_arrEntries[_intNext]._ticksExpires = objEntry.Expires;
|
||||
_arrEntries[_intNext]._objEntry = objEntry;
|
||||
|
||||
_intNext = _arrEntries[_intNext]._intNext;
|
||||
|
||||
_intCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a cache entry from the expires bucket.
|
||||
/// </summary>
|
||||
/// <param name="objEntry">Cache entry to be removed.</param>
|
||||
public void Remove(CacheEntry objEntry)
|
||||
{
|
||||
lock(this)
|
||||
{
|
||||
// Check if this is our bucket
|
||||
if (objEntry.ExpiresIndex != _byteID) return;
|
||||
if (objEntry.ExpiresIndex == System.Int32.MaxValue) return;
|
||||
if (_arrEntries.Length < objEntry.ExpiresIndex) return;
|
||||
|
||||
_intCount--;
|
||||
|
||||
_arrEntries[objEntry.ExpiresIndex]._objEntry.ExpiresBucket = byte.MaxValue;
|
||||
_arrEntries[objEntry.ExpiresIndex]._objEntry.ExpiresIndex = int.MaxValue;
|
||||
_arrEntries[objEntry.ExpiresIndex]._objEntry = null;
|
||||
_intNext = _arrEntries[objEntry.ExpiresIndex]._intNext;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a cache entry in the expires bucket, this is called during a hit of an item if the
|
||||
/// cache item has a sliding expiration. The function is responsible for updating the cache
|
||||
/// entry.
|
||||
/// </summary>
|
||||
/// <param name="objEntry">Cache entry to update.</param>
|
||||
/// <param name="ticksExpires">New expiration value for the cache entry.</param>
|
||||
public void Update(CacheEntry objEntry, long ticksExpires)
|
||||
{
|
||||
lock(this)
|
||||
{
|
||||
// Check if this is our bucket
|
||||
if (objEntry.ExpiresIndex != _byteID) return;
|
||||
if (objEntry.ExpiresIndex == System.Int32.MaxValue) return;
|
||||
if (_arrEntries.Length < objEntry.ExpiresIndex) return;
|
||||
|
||||
_arrEntries[objEntry.ExpiresIndex]._ticksExpires = ticksExpires;
|
||||
_arrEntries[objEntry.ExpiresIndex]._objEntry.Expires = ticksExpires;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Flushes all cache entries that has expired and removes them from the cache manager.
|
||||
/// </summary>
|
||||
public void FlushExpiredItems()
|
||||
{
|
||||
ExpiresEntry objEntry;
|
||||
CacheEntry [] arrCacheEntries;
|
||||
|
||||
int intCachePos;
|
||||
int intPos;
|
||||
long ticksNow;
|
||||
|
||||
ticksNow = System.DateTime.Now.Ticks;
|
||||
|
||||
intCachePos = 0;
|
||||
|
||||
// Lookup all items that needs to be removed, this is done in a two part
|
||||
// operation to minimize the locking time.
|
||||
lock (this)
|
||||
{
|
||||
arrCacheEntries = new CacheEntry[_intSize];
|
||||
|
||||
intPos = 0;
|
||||
do
|
||||
{
|
||||
objEntry = _arrEntries[intPos];
|
||||
if (objEntry._objEntry != null)
|
||||
{
|
||||
if (objEntry._ticksExpires < ticksNow)
|
||||
{
|
||||
arrCacheEntries[intCachePos++] = objEntry._objEntry;
|
||||
|
||||
objEntry._objEntry.ExpiresBucket = byte.MaxValue;
|
||||
objEntry._objEntry.ExpiresIndex = int.MaxValue;
|
||||
objEntry._objEntry = null;
|
||||
_intNext = objEntry._intNext;
|
||||
}
|
||||
}
|
||||
|
||||
intPos++;
|
||||
} while (intPos < _intSize);
|
||||
}
|
||||
|
||||
// If we have any entries to remove, go ahead and call the cache manager remove.
|
||||
if (intCachePos > 0)
|
||||
{
|
||||
intPos = 0;
|
||||
do
|
||||
{
|
||||
_objManager.Remove(arrCacheEntries[intPos].Key, CacheItemRemovedReason.Expired);
|
||||
|
||||
intPos++;
|
||||
} while (intPos < intCachePos);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current size of the expires bucket.
|
||||
/// </summary>
|
||||
public int Size
|
||||
{
|
||||
get
|
||||
{
|
||||
return _arrEntries.Length;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns number of items in the bucket.
|
||||
/// </summary>
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return _intCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
Cache.cs
|
||||
CacheDefinitions.cs
|
||||
CacheDependency.cs
|
||||
CacheEntry.cs
|
||||
CacheExpires.cs
|
||||
ExpiresBuckets.cs
|
||||
Whitespace-only changes.
Whitespace-only changes.
@@ -1,16 +0,0 @@
|
||||
DIRS=System.Web.Caching
|
||||
|
||||
all:
|
||||
@echo "You must use 'make windows' or 'make unix'."
|
||||
@echo "'make unix' is broken for now."
|
||||
|
||||
windows: make-list
|
||||
$(CSC) /target:library /out:System.Web.dll /nowarn:1595 @list
|
||||
|
||||
unix:
|
||||
@echo "'make unix' is broken for now."
|
||||
|
||||
make-list:
|
||||
for i in $(DIRS); do \
|
||||
cat $$i/common.src $$i/windows.src | sed "s/^/$$i\\\\/"; \
|
||||
done > list
|
||||
@@ -1,2 +0,0 @@
|
||||
*.dll
|
||||
list
|
||||
@@ -35,23 +35,6 @@ public class Driver
|
||||
Console.WriteLine(" AttributeCount = {0}", xmlReader.AttributeCount);
|
||||
Console.WriteLine(" HasValue = {0}", xmlReader.HasValue);
|
||||
Console.WriteLine(" Value = {0}", xmlReader.Value);
|
||||
Console.WriteLine(" Depth = {0}", xmlReader.Depth);
|
||||
|
||||
if (xmlReader.HasAttributes)
|
||||
{
|
||||
while (xmlReader.MoveToNextAttribute())
|
||||
{
|
||||
Console.WriteLine(" AttributeName = {0}", xmlReader.Name);
|
||||
Console.WriteLine(" AttributeValue = {0}", xmlReader.Value);
|
||||
|
||||
while (xmlReader.ReadAttributeValue())
|
||||
{
|
||||
Console.WriteLine(" AttributeValueNodeType = {0}", xmlReader.NodeType);
|
||||
Console.WriteLine(" AttributeValueName = {0}", xmlReader.Name);
|
||||
Console.WriteLine(" AttributeValueValue = {0}", xmlReader.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
// -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
||||
//
|
||||
// System.Xml.IXmlLineInfo.cs
|
||||
//
|
||||
// Author:
|
||||
// Jason Diamond ([email protected])
|
||||
//
|
||||
// (C) 2001 Jason Diamond http://injektilo.org/
|
||||
//
|
||||
|
||||
namespace System.Xml
|
||||
{
|
||||
public interface IXmlLineInfo
|
||||
{
|
||||
int LineNumber { get; }
|
||||
int LinePosition { get; }
|
||||
|
||||
bool HasLineInfo();
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
// -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
||||
//
|
||||
// Profile.cs
|
||||
//
|
||||
// Author:
|
||||
// Jason Diamond ([email protected])
|
||||
//
|
||||
// (C) 2001 Jason Diamond http://injektilo.org/
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Xml;
|
||||
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
public class Profile
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
XmlReader xmlReader = null;
|
||||
|
||||
if (args.Length < 1)
|
||||
{
|
||||
xmlReader = new XmlTextReader(Console.In);
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlReader = new XmlTextReader(args[0]);
|
||||
}
|
||||
|
||||
int nodes = 0;
|
||||
|
||||
DateTime start = DateTime.Now;
|
||||
|
||||
while (xmlReader.Read())
|
||||
{
|
||||
++nodes;
|
||||
}
|
||||
|
||||
DateTime end = DateTime.Now;
|
||||
|
||||
Console.WriteLine("time = {0}", end - start);
|
||||
|
||||
Console.WriteLine("nodes = {0}", nodes);
|
||||
}
|
||||
}
|
||||
@@ -24,14 +24,12 @@ namespace System.Xml
|
||||
{
|
||||
Assert(xmlReader.ReadState == ReadState.Initial);
|
||||
Assert(xmlReader.NodeType == XmlNodeType.None);
|
||||
Assert(xmlReader.Depth == 0);
|
||||
Assert(!xmlReader.EOF);
|
||||
}
|
||||
|
||||
private void AssertNode(
|
||||
XmlReader xmlReader,
|
||||
XmlNodeType nodeType,
|
||||
int depth,
|
||||
bool isEmptyElement,
|
||||
string name,
|
||||
string value,
|
||||
@@ -42,7 +40,6 @@ namespace System.Xml
|
||||
Assert(!xmlReader.EOF);
|
||||
|
||||
Assert(xmlReader.NodeType == nodeType);
|
||||
Assert(xmlReader.Depth == depth);
|
||||
Assert(xmlReader.IsEmptyElement == isEmptyElement);
|
||||
Assert(xmlReader.Name == name);
|
||||
Assert(xmlReader.HasValue == (value != String.Empty));
|
||||
@@ -64,7 +61,6 @@ namespace System.Xml
|
||||
{
|
||||
Assert(!xmlReader.Read());
|
||||
Assert(xmlReader.NodeType == XmlNodeType.None);
|
||||
Assert(xmlReader.Depth == 0);
|
||||
Assert(xmlReader.ReadState == ReadState.EndOfFile);
|
||||
Assert(xmlReader.EOF);
|
||||
|
||||
@@ -83,7 +79,6 @@ namespace System.Xml
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Element, // nodeType
|
||||
0, // depth
|
||||
true, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
@@ -104,7 +99,6 @@ namespace System.Xml
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Element, // nodeType
|
||||
0, //depth
|
||||
true, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
@@ -125,7 +119,6 @@ namespace System.Xml
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Element, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
@@ -135,7 +128,6 @@ namespace System.Xml
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.EndElement, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
@@ -156,7 +148,6 @@ namespace System.Xml
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Element, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
@@ -166,7 +157,6 @@ namespace System.Xml
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.EndElement, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
@@ -187,7 +177,6 @@ namespace System.Xml
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Element, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
@@ -197,7 +186,6 @@ namespace System.Xml
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Element, // nodeType
|
||||
1, //depth
|
||||
true, // isEmptyElement
|
||||
"bar", // name
|
||||
String.Empty, // value
|
||||
@@ -207,7 +195,6 @@ namespace System.Xml
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.EndElement, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
@@ -228,7 +215,6 @@ namespace System.Xml
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Element, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
@@ -238,7 +224,6 @@ namespace System.Xml
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Text, // nodeType
|
||||
1, //depth
|
||||
false, // isEmptyElement
|
||||
String.Empty, // name
|
||||
"bar", // value
|
||||
@@ -248,7 +233,6 @@ namespace System.Xml
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.EndElement, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
@@ -269,7 +253,6 @@ namespace System.Xml
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Element, // nodeType
|
||||
0, //depth
|
||||
true, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
@@ -296,7 +279,6 @@ namespace System.Xml
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Element, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
@@ -312,7 +294,6 @@ namespace System.Xml
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.EndElement, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
@@ -333,7 +314,6 @@ namespace System.Xml
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Element, // nodeType
|
||||
0, //depth
|
||||
true, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
@@ -366,7 +346,6 @@ namespace System.Xml
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.ProcessingInstruction, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
"foo", // name
|
||||
"bar", // value
|
||||
@@ -376,7 +355,6 @@ namespace System.Xml
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Element, // nodeType
|
||||
0, //depth
|
||||
true, // isEmptyElement
|
||||
"baz", // name
|
||||
String.Empty, // value
|
||||
@@ -397,7 +375,6 @@ namespace System.Xml
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Comment, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
String.Empty, // name
|
||||
"foo", // value
|
||||
@@ -407,7 +384,6 @@ namespace System.Xml
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Element, // nodeType
|
||||
0, //depth
|
||||
true, // isEmptyElement
|
||||
"bar", // name
|
||||
String.Empty, // value
|
||||
@@ -417,312 +393,6 @@ namespace System.Xml
|
||||
AssertEndDocument(xmlReader);
|
||||
}
|
||||
|
||||
public void TestPredefinedEntities()
|
||||
{
|
||||
string xml = "<foo><>&'"</foo>";
|
||||
XmlReader xmlReader =
|
||||
new XmlTextReader(new StringReader(xml));
|
||||
|
||||
AssertStartDocument(xmlReader);
|
||||
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Element, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
0 // attributeCount
|
||||
);
|
||||
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Text, // nodeType
|
||||
1, //depth
|
||||
false, // isEmptyElement
|
||||
String.Empty, // name
|
||||
"<>&'\"", // value
|
||||
0 // attributeCount
|
||||
);
|
||||
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.EndElement, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
0 // attributeCount
|
||||
);
|
||||
|
||||
AssertEndDocument(xmlReader);
|
||||
}
|
||||
|
||||
public void TestEntityReference()
|
||||
{
|
||||
string xml = "<foo>&bar;</foo>";
|
||||
XmlReader xmlReader =
|
||||
new XmlTextReader(new StringReader(xml));
|
||||
|
||||
AssertStartDocument(xmlReader);
|
||||
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Element, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
0 // attributeCount
|
||||
);
|
||||
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.EntityReference, // nodeType
|
||||
1, //depth
|
||||
false, // isEmptyElement
|
||||
"bar", // name
|
||||
String.Empty, // value
|
||||
0 // attributeCount
|
||||
);
|
||||
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.EndElement, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
0 // attributeCount
|
||||
);
|
||||
|
||||
AssertEndDocument(xmlReader);
|
||||
}
|
||||
|
||||
public void TestEntityReferenceInsideText()
|
||||
{
|
||||
string xml = "<foo>bar&baz;quux</foo>";
|
||||
XmlReader xmlReader =
|
||||
new XmlTextReader(new StringReader(xml));
|
||||
|
||||
AssertStartDocument(xmlReader);
|
||||
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Element, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
0 // attributeCount
|
||||
);
|
||||
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Text, // nodeType
|
||||
1, //depth
|
||||
false, // isEmptyElement
|
||||
String.Empty, // name
|
||||
"bar", // value
|
||||
0 // attributeCount
|
||||
);
|
||||
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.EntityReference, // nodeType
|
||||
1, //depth
|
||||
false, // isEmptyElement
|
||||
"baz", // name
|
||||
String.Empty, // value
|
||||
0 // attributeCount
|
||||
);
|
||||
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Text, // nodeType
|
||||
1, //depth
|
||||
false, // isEmptyElement
|
||||
String.Empty, // name
|
||||
"quux", // value
|
||||
0 // attributeCount
|
||||
);
|
||||
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.EndElement, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
0 // attributeCount
|
||||
);
|
||||
|
||||
AssertEndDocument(xmlReader);
|
||||
}
|
||||
|
||||
public void TestCharacterReferences()
|
||||
{
|
||||
string xml = "<foo>FOO</foo>";
|
||||
XmlReader xmlReader =
|
||||
new XmlTextReader(new StringReader(xml));
|
||||
|
||||
AssertStartDocument(xmlReader);
|
||||
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Element, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
0 // attributeCount
|
||||
);
|
||||
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Text, // nodeType
|
||||
1, //depth
|
||||
false, // isEmptyElement
|
||||
String.Empty, // name
|
||||
"FOO", // value
|
||||
0 // attributeCount
|
||||
);
|
||||
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.EndElement, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
0 // attributeCount
|
||||
);
|
||||
|
||||
AssertEndDocument(xmlReader);
|
||||
}
|
||||
|
||||
public void TestEntityReferenceInAttribute()
|
||||
{
|
||||
string xml = "<foo bar='&baz;'/>";
|
||||
XmlReader xmlReader =
|
||||
new XmlTextReader(new StringReader(xml));
|
||||
|
||||
AssertStartDocument(xmlReader);
|
||||
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Element, // nodeType
|
||||
0, //depth
|
||||
true, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
1 // attributeCount
|
||||
);
|
||||
|
||||
AssertAttribute(
|
||||
xmlReader, // xmlReader
|
||||
"bar", // name
|
||||
"&baz;" // value
|
||||
);
|
||||
|
||||
AssertEndDocument(xmlReader);
|
||||
}
|
||||
|
||||
public void TestPredefinedEntitiesInAttribute()
|
||||
{
|
||||
string xml = "<foo bar='<>&'"'/>";
|
||||
XmlReader xmlReader =
|
||||
new XmlTextReader(new StringReader(xml));
|
||||
|
||||
AssertStartDocument(xmlReader);
|
||||
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Element, // nodeType
|
||||
0, //depth
|
||||
true, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
1 // attributeCount
|
||||
);
|
||||
|
||||
AssertAttribute(
|
||||
xmlReader, // xmlReader
|
||||
"bar", // name
|
||||
"<>&'\"" // value
|
||||
);
|
||||
|
||||
AssertEndDocument(xmlReader);
|
||||
}
|
||||
|
||||
public void TestCharacterReferencesInAttribute()
|
||||
{
|
||||
string xml = "<foo bar='FOO'/>";
|
||||
XmlReader xmlReader =
|
||||
new XmlTextReader(new StringReader(xml));
|
||||
|
||||
AssertStartDocument(xmlReader);
|
||||
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Element, // nodeType
|
||||
0, //depth
|
||||
true, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
1 // attributeCount
|
||||
);
|
||||
|
||||
AssertAttribute(
|
||||
xmlReader, // xmlReader
|
||||
"bar", // name
|
||||
"FOO" // value
|
||||
);
|
||||
|
||||
AssertEndDocument(xmlReader);
|
||||
}
|
||||
|
||||
public void TestCDATA()
|
||||
{
|
||||
string xml = "<foo><![CDATA[<>&]]></foo>";
|
||||
XmlReader xmlReader =
|
||||
new XmlTextReader(new StringReader(xml));
|
||||
|
||||
AssertStartDocument(xmlReader);
|
||||
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.Element, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
0 // attributeCount
|
||||
);
|
||||
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.CDATA, // nodeType
|
||||
1, //depth
|
||||
false, // isEmptyElement
|
||||
String.Empty, // name
|
||||
"<>&", // value
|
||||
0 // attributeCount
|
||||
);
|
||||
|
||||
AssertNode(
|
||||
xmlReader, // xmlReader
|
||||
XmlNodeType.EndElement, // nodeType
|
||||
0, //depth
|
||||
false, // isEmptyElement
|
||||
"foo", // name
|
||||
String.Empty, // value
|
||||
0 // attributeCount
|
||||
);
|
||||
|
||||
AssertEndDocument(xmlReader);
|
||||
}
|
||||
|
||||
// The following is #if'ed out because it's specific to the Mono
|
||||
// implementation and won't compile when testing Microsoft's code.
|
||||
// Feel free to turn it on if you want to test Mono's name tables.
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
// -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
||||
//
|
||||
// System.Xml.WhitespaceHandling.cs
|
||||
//
|
||||
// Author:
|
||||
// Jason Diamond ([email protected])
|
||||
//
|
||||
// (C) 2001 Jason Diamond http://injektilo.org/
|
||||
//
|
||||
|
||||
namespace System.Xml
|
||||
{
|
||||
public enum WhitespaceHandling
|
||||
{
|
||||
All,
|
||||
None,
|
||||
Signifigant
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@
|
||||
// (C) 2001 Jason Diamond http://injektilo.org/
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
namespace System.Xml
|
||||
{
|
||||
internal class XmlChar
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
// -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
||||
//
|
||||
// System.Xml.XmlResolver.cs
|
||||
//
|
||||
// Author:
|
||||
// Jason Diamond ([email protected])
|
||||
//
|
||||
// (C) 2001 Jason Diamond http://injektilo.org/
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
|
||||
namespace System.Xml
|
||||
{
|
||||
public abstract class XmlResolver
|
||||
{
|
||||
public abstract ICredentials Credentials { set; }
|
||||
|
||||
public abstract object GetEntity(
|
||||
Uri absoluteUri,
|
||||
string role,
|
||||
Type type);
|
||||
|
||||
public abstract Uri ResolveUri(
|
||||
Uri baseUri,
|
||||
string relativeUri);
|
||||
}
|
||||
}
|
||||
@@ -11,17 +11,20 @@
|
||||
// FIXME:
|
||||
// This can only parse basic XML: elements, attributes, processing
|
||||
// instructions, and comments are OK but there's no support for
|
||||
// namespaces yet.
|
||||
// entity/character references or namespaces yet.
|
||||
//
|
||||
// It barfs on DOCTYPE declarations.
|
||||
// It barfs on DOCTYPE declarations and CDATA sections.
|
||||
//
|
||||
// There's also no checking being done for either well-formedness
|
||||
// or validity.
|
||||
//
|
||||
// ParserContext and NameTables aren't being used yet.
|
||||
//
|
||||
// The XmlTextReader-specific properties and methods have yet to
|
||||
// be added or implemented.
|
||||
//
|
||||
// Some thought needs to be given to performance. There's too many
|
||||
// strings being allocated.
|
||||
// strings and string builders being allocated.
|
||||
//
|
||||
// None of the MoveTo methods have been implemented yet.
|
||||
//
|
||||
@@ -39,7 +42,7 @@ using System.Text;
|
||||
|
||||
namespace System.Xml
|
||||
{
|
||||
public class XmlTextReader : XmlReader, IXmlLineInfo
|
||||
public class XmlTextReader : XmlReader
|
||||
{
|
||||
// constructors
|
||||
|
||||
@@ -164,7 +167,7 @@ namespace System.Xml
|
||||
{
|
||||
get
|
||||
{
|
||||
// XmlTextReaders don't resolve entities.
|
||||
// TODO: implement me.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -174,16 +177,7 @@ namespace System.Xml
|
||||
get
|
||||
{
|
||||
// TODO: implement me.
|
||||
return depth > 0 ? depth : 0;
|
||||
}
|
||||
}
|
||||
|
||||
public Encoding Encoding
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO: implement me.
|
||||
return null;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +203,7 @@ namespace System.Xml
|
||||
{
|
||||
get
|
||||
{
|
||||
// XmlTextReader does not expand default attributes.
|
||||
// TODO: implement me.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -248,24 +242,6 @@ namespace System.Xml
|
||||
}
|
||||
}
|
||||
|
||||
public int LineNumber
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO: implement me.
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int LinePosition
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO: implement me.
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public override string LocalName
|
||||
{
|
||||
get
|
||||
@@ -283,20 +259,6 @@ namespace System.Xml
|
||||
}
|
||||
}
|
||||
|
||||
public bool Namespaces
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO: implement me.
|
||||
return false;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
// TODO: implement me.
|
||||
}
|
||||
}
|
||||
|
||||
public override string NamespaceURI
|
||||
{
|
||||
get
|
||||
@@ -323,20 +285,6 @@ namespace System.Xml
|
||||
}
|
||||
}
|
||||
|
||||
public bool Normalization
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO: implement me.
|
||||
return false;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
// TODO: implement me.
|
||||
}
|
||||
}
|
||||
|
||||
public override string Prefix
|
||||
{
|
||||
get
|
||||
@@ -371,20 +319,6 @@ namespace System.Xml
|
||||
}
|
||||
}
|
||||
|
||||
public WhitespaceHandling WhitespaceHandling
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO: implement me.
|
||||
return WhitespaceHandling.All;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
// TODO: implement me.
|
||||
}
|
||||
}
|
||||
|
||||
public override string XmlLang
|
||||
{
|
||||
get
|
||||
@@ -394,14 +328,6 @@ namespace System.Xml
|
||||
}
|
||||
}
|
||||
|
||||
public XmlResolver XmlResolver
|
||||
{
|
||||
set
|
||||
{
|
||||
// TODO: implement me.
|
||||
}
|
||||
}
|
||||
|
||||
public override XmlSpace XmlSpace
|
||||
{
|
||||
get
|
||||
@@ -437,19 +363,6 @@ namespace System.Xml
|
||||
return null;
|
||||
}
|
||||
|
||||
public TextReader GetRemainder()
|
||||
{
|
||||
// TODO: implement me.
|
||||
return null;
|
||||
}
|
||||
|
||||
// Why does this use explicit interface implementation?
|
||||
bool IXmlLineInfo.HasLineInfo()
|
||||
{
|
||||
// TODO: implement me.
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string LookupNamespace(string prefix)
|
||||
{
|
||||
// TODO: implement me.
|
||||
@@ -510,24 +423,6 @@ namespace System.Xml
|
||||
return false;
|
||||
}
|
||||
|
||||
public int ReadBase64(byte[] buffer, int offset, int length)
|
||||
{
|
||||
// TODO: implement me.
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int ReadBinHex(byte[] buffer, int offset, int length)
|
||||
{
|
||||
// TODO: implement me.
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int ReadChars(char[] buffer, int offset, int length)
|
||||
{
|
||||
// TODO: implement me.
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override string ReadInnerXml()
|
||||
{
|
||||
// TODO: implement me.
|
||||
@@ -548,8 +443,7 @@ namespace System.Xml
|
||||
|
||||
public override void ResolveEntity()
|
||||
{
|
||||
// XmlTextReaders don't resolve entities.
|
||||
throw new InvalidOperationException("XmlTextReaders don't resolve entities.");
|
||||
// TODO: implement me.
|
||||
}
|
||||
|
||||
// privates
|
||||
@@ -557,51 +451,21 @@ namespace System.Xml
|
||||
private TextReader reader;
|
||||
private ReadState readState;
|
||||
|
||||
private int depth;
|
||||
private bool depthDown;
|
||||
|
||||
private XmlNodeType nodeType;
|
||||
private string name;
|
||||
private bool isEmptyElement;
|
||||
private string value;
|
||||
private Hashtable attributes;
|
||||
|
||||
private bool returnEntityReference;
|
||||
private string entityReferenceName;
|
||||
|
||||
private char[] nameBuffer;
|
||||
private int nameLength;
|
||||
private int nameCapacity;
|
||||
private const int initialNameCapacity = 256;
|
||||
|
||||
private char[] valueBuffer;
|
||||
private int valueLength;
|
||||
private int valueCapacity;
|
||||
private const int initialValueCapacity = 8192;
|
||||
|
||||
private void Init()
|
||||
{
|
||||
readState = ReadState.Initial;
|
||||
|
||||
depth = -1;
|
||||
depthDown = false;
|
||||
|
||||
nodeType = XmlNodeType.None;
|
||||
name = String.Empty;
|
||||
isEmptyElement = false;
|
||||
value = String.Empty;
|
||||
attributes = new Hashtable();
|
||||
|
||||
returnEntityReference = false;
|
||||
entityReferenceName = String.Empty;
|
||||
|
||||
nameBuffer = new char[initialNameCapacity];
|
||||
nameLength = 0;
|
||||
nameCapacity = initialNameCapacity;
|
||||
|
||||
valueBuffer = new char[initialValueCapacity];
|
||||
valueLength = 0;
|
||||
valueCapacity = initialValueCapacity;
|
||||
}
|
||||
|
||||
// Use this method rather than setting the properties
|
||||
@@ -634,20 +498,7 @@ namespace System.Xml
|
||||
|
||||
private void ClearAttributes()
|
||||
{
|
||||
if (attributes.Count > 0)
|
||||
{
|
||||
attributes.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
private int PeekChar()
|
||||
{
|
||||
return reader.Peek();
|
||||
}
|
||||
|
||||
private int ReadChar()
|
||||
{
|
||||
return reader.Read();
|
||||
attributes.Clear();
|
||||
}
|
||||
|
||||
// This should really keep track of some state so
|
||||
@@ -657,77 +508,49 @@ namespace System.Xml
|
||||
{
|
||||
bool more = false;
|
||||
|
||||
if (depthDown)
|
||||
switch (reader.Peek())
|
||||
{
|
||||
--depth;
|
||||
}
|
||||
|
||||
if (returnEntityReference)
|
||||
{
|
||||
++depth;
|
||||
SetEntityReferenceProperties();
|
||||
case '<':
|
||||
reader.Read();
|
||||
ReadTag();
|
||||
more = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (PeekChar())
|
||||
{
|
||||
case '<':
|
||||
ReadChar();
|
||||
ReadTag();
|
||||
more = true;
|
||||
break;
|
||||
case -1:
|
||||
readState = ReadState.EndOfFile;
|
||||
SetProperties(
|
||||
XmlNodeType.None, // nodeType
|
||||
String.Empty, // name
|
||||
false, // isEmptyElement
|
||||
String.Empty, // value
|
||||
true // clearAttributes
|
||||
);
|
||||
more = false;
|
||||
break;
|
||||
default:
|
||||
ReadText();
|
||||
more = true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case -1:
|
||||
readState = ReadState.EndOfFile;
|
||||
SetProperties(
|
||||
XmlNodeType.None, // nodeType
|
||||
String.Empty, // name
|
||||
false, // isEmptyElement
|
||||
String.Empty, // value
|
||||
true // clearAttributes
|
||||
);
|
||||
more = false;
|
||||
break;
|
||||
default:
|
||||
ReadText();
|
||||
more = true;
|
||||
break;
|
||||
}
|
||||
|
||||
return more;
|
||||
}
|
||||
|
||||
private void SetEntityReferenceProperties()
|
||||
{
|
||||
SetProperties(
|
||||
XmlNodeType.EntityReference, // nodeType
|
||||
entityReferenceName, // name
|
||||
false, // isEmptyElement
|
||||
String.Empty, // value
|
||||
true // clearAttributes
|
||||
);
|
||||
|
||||
returnEntityReference = false;
|
||||
entityReferenceName = String.Empty;
|
||||
}
|
||||
|
||||
// The leading '<' has already been consumed.
|
||||
private void ReadTag()
|
||||
{
|
||||
switch (PeekChar())
|
||||
switch (reader.Peek())
|
||||
{
|
||||
case '/':
|
||||
ReadChar();
|
||||
reader.Read();
|
||||
ReadEndTag();
|
||||
break;
|
||||
case '?':
|
||||
ReadChar();
|
||||
reader.Read();
|
||||
ReadProcessingInstruction();
|
||||
break;
|
||||
case '!':
|
||||
ReadChar();
|
||||
ReadDeclaration();
|
||||
reader.Read();
|
||||
ReadComment();
|
||||
break;
|
||||
default:
|
||||
ReadStartTag();
|
||||
@@ -745,22 +568,19 @@ namespace System.Xml
|
||||
|
||||
ClearAttributes();
|
||||
|
||||
if (XmlChar.IsFirstNameChar(PeekChar()))
|
||||
if (XmlChar.IsFirstNameChar(reader.Peek()))
|
||||
{
|
||||
ReadAttributes();
|
||||
}
|
||||
|
||||
if (PeekChar() == '/')
|
||||
if (reader.Peek() == '/')
|
||||
{
|
||||
ReadChar();
|
||||
reader.Read();
|
||||
isEmptyElement = true;
|
||||
depthDown = true;
|
||||
}
|
||||
|
||||
Expect('>');
|
||||
|
||||
++depth;
|
||||
|
||||
SetProperties(
|
||||
XmlNodeType.Element, // nodeType
|
||||
name, // name
|
||||
@@ -778,8 +598,6 @@ namespace System.Xml
|
||||
SkipWhitespace();
|
||||
Expect('>');
|
||||
|
||||
--depth;
|
||||
|
||||
SetProperties(
|
||||
XmlNodeType.EndElement, // nodeType
|
||||
name, // name
|
||||
@@ -789,232 +607,25 @@ namespace System.Xml
|
||||
);
|
||||
}
|
||||
|
||||
private void AppendNameChar(int ch)
|
||||
{
|
||||
CheckNameCapacity();
|
||||
nameBuffer[nameLength++] = (char)ch;
|
||||
}
|
||||
|
||||
private void CheckNameCapacity()
|
||||
{
|
||||
if (nameLength == nameCapacity)
|
||||
{
|
||||
nameCapacity = nameCapacity * 2;
|
||||
char[] oldNameBuffer = nameBuffer;
|
||||
nameBuffer = new char[nameCapacity];
|
||||
Array.Copy(oldNameBuffer, nameBuffer, nameLength);
|
||||
}
|
||||
}
|
||||
|
||||
private string CreateNameString()
|
||||
{
|
||||
return new String(nameBuffer, 0, nameLength);
|
||||
}
|
||||
|
||||
private void AppendValueChar(int ch)
|
||||
{
|
||||
CheckValueCapacity();
|
||||
valueBuffer[valueLength++] = (char)ch;
|
||||
}
|
||||
|
||||
private void CheckValueCapacity()
|
||||
{
|
||||
if (valueLength == valueCapacity)
|
||||
{
|
||||
valueCapacity = valueCapacity * 2;
|
||||
char[] oldValueBuffer = valueBuffer;
|
||||
valueBuffer = new char[valueCapacity];
|
||||
Array.Copy(oldValueBuffer, valueBuffer, valueLength);
|
||||
}
|
||||
}
|
||||
|
||||
private string CreateValueString()
|
||||
{
|
||||
return new String(valueBuffer, 0, valueLength);
|
||||
}
|
||||
|
||||
// The reader is positioned on the first character
|
||||
// of the text.
|
||||
private void ReadText()
|
||||
{
|
||||
valueLength = 0;
|
||||
StringBuilder text = new StringBuilder();
|
||||
text.Append((char)reader.Read());
|
||||
|
||||
int ch = PeekChar();
|
||||
|
||||
while (ch != '<' && ch != -1)
|
||||
while (reader.Peek() != '<' && reader.Peek() != -1)
|
||||
{
|
||||
if (ch == '&')
|
||||
{
|
||||
ReadChar();
|
||||
|
||||
if (ReadReference(false))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AppendValueChar(ReadChar());
|
||||
}
|
||||
|
||||
ch = PeekChar();
|
||||
text.Append((char)reader.Read());
|
||||
}
|
||||
|
||||
if (returnEntityReference && valueLength == 0)
|
||||
{
|
||||
++depth;
|
||||
SetEntityReferenceProperties();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (depth >= 0)
|
||||
{
|
||||
++depth;
|
||||
depthDown = true;
|
||||
}
|
||||
|
||||
SetProperties(
|
||||
XmlNodeType.Text, // nodeType
|
||||
String.Empty, // name
|
||||
false, // isEmptyElement
|
||||
CreateValueString(), // value
|
||||
true // clearAttributes
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// The leading '&' has already been consumed.
|
||||
// Returns true if the entity reference isn't a simple
|
||||
// character reference or one of the predefined entities.
|
||||
// This allows the ReadText method to break so that the
|
||||
// next call to Read will return the EntityReference node.
|
||||
private bool ReadReference(bool ignoreEntityReferences)
|
||||
{
|
||||
if (PeekChar() == '#')
|
||||
{
|
||||
ReadChar();
|
||||
ReadCharacterReference();
|
||||
}
|
||||
else
|
||||
{
|
||||
ReadEntityReference(ignoreEntityReferences);
|
||||
}
|
||||
|
||||
return returnEntityReference;
|
||||
}
|
||||
|
||||
private void ReadCharacterReference()
|
||||
{
|
||||
int value = 0;
|
||||
|
||||
if (PeekChar() == 'x')
|
||||
{
|
||||
ReadChar();
|
||||
|
||||
while (PeekChar() != ';' && PeekChar() != -1)
|
||||
{
|
||||
int ch = ReadChar();
|
||||
|
||||
if (ch >= '0' && ch <= '9')
|
||||
{
|
||||
value = (value << 4) + ch - '0';
|
||||
}
|
||||
else if (ch >= 'A' && ch <= 'F')
|
||||
{
|
||||
value = (value << 4) + ch - 'A' + 10;
|
||||
}
|
||||
else if (ch >= 'a' && ch <= 'f')
|
||||
{
|
||||
value = (value << 4) + ch - 'a' + 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(
|
||||
String.Format(
|
||||
"invalid hexadecimal digit: {0} (#x{1:X})",
|
||||
(char)ch,
|
||||
ch));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (PeekChar() != ';' && PeekChar() != -1)
|
||||
{
|
||||
int ch = ReadChar();
|
||||
|
||||
if (ch >= '0' && ch <= '9')
|
||||
{
|
||||
value = value * 10 + ch - '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(
|
||||
String.Format(
|
||||
"invalid decimal digit: {0} (#x{1:X})",
|
||||
(char)ch,
|
||||
ch));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReadChar(); // ';'
|
||||
|
||||
AppendValueChar(value);
|
||||
}
|
||||
|
||||
private void ReadEntityReference(bool ignoreEntityReferences)
|
||||
{
|
||||
nameLength = 0;
|
||||
|
||||
int ch = PeekChar();
|
||||
|
||||
while (ch != ';' && ch != -1)
|
||||
{
|
||||
AppendNameChar(ReadChar());
|
||||
ch = PeekChar();
|
||||
}
|
||||
|
||||
Expect(';');
|
||||
|
||||
string name = CreateNameString();
|
||||
|
||||
switch (name)
|
||||
{
|
||||
case "lt":
|
||||
AppendValueChar('<');
|
||||
break;
|
||||
case "gt":
|
||||
AppendValueChar('>');
|
||||
break;
|
||||
case "amp":
|
||||
AppendValueChar('&');
|
||||
break;
|
||||
case "apos":
|
||||
AppendValueChar('\'');
|
||||
break;
|
||||
case "quot":
|
||||
AppendValueChar('"');
|
||||
break;
|
||||
default:
|
||||
if (ignoreEntityReferences)
|
||||
{
|
||||
AppendValueChar('&');
|
||||
|
||||
foreach (char ch2 in name)
|
||||
{
|
||||
AppendValueChar(ch2);
|
||||
}
|
||||
|
||||
AppendValueChar(';');
|
||||
}
|
||||
else
|
||||
{
|
||||
returnEntityReference = true;
|
||||
entityReferenceName = name;
|
||||
}
|
||||
break;
|
||||
}
|
||||
SetProperties(
|
||||
XmlNodeType.Text, // nodeType
|
||||
String.Empty, // name
|
||||
false, // isEmptyElement
|
||||
text.ToString(), // value
|
||||
true // clearAttributes
|
||||
);
|
||||
}
|
||||
|
||||
// The reader is positioned on the first character of
|
||||
@@ -1032,43 +643,39 @@ namespace System.Xml
|
||||
|
||||
AddAttribute(name, value);
|
||||
}
|
||||
while (PeekChar() != '/' && PeekChar() != '>' && PeekChar() != -1);
|
||||
while (reader.Peek() != '/' && reader.Peek() != '>' && reader.Peek() != -1);
|
||||
}
|
||||
|
||||
// The reader is positioned on the quote character.
|
||||
private string ReadAttribute()
|
||||
{
|
||||
int quoteChar = ReadChar();
|
||||
int quoteChar = reader.Read();
|
||||
|
||||
if (quoteChar != '\'' && quoteChar != '\"')
|
||||
{
|
||||
throw new Exception("an attribute value was not quoted");
|
||||
}
|
||||
|
||||
valueLength = 0;
|
||||
StringBuilder valueBuilder = new StringBuilder();
|
||||
|
||||
while (PeekChar() != quoteChar)
|
||||
while (reader.Peek() != quoteChar)
|
||||
{
|
||||
int ch = ReadChar();
|
||||
int ch = reader.Read();
|
||||
|
||||
switch (ch)
|
||||
{
|
||||
case '<':
|
||||
throw new Exception("attribute values cannot contain '<'");
|
||||
case '&':
|
||||
ReadReference(true);
|
||||
break;
|
||||
case -1:
|
||||
throw new Exception("unexpected end of file in an attribute value");
|
||||
default:
|
||||
AppendValueChar(ch);
|
||||
break;
|
||||
}
|
||||
|
||||
valueBuilder.Append((char)ch);
|
||||
}
|
||||
|
||||
ReadChar(); // quoteChar
|
||||
reader.Read();
|
||||
|
||||
return CreateValueString();
|
||||
return valueBuilder.ToString();
|
||||
}
|
||||
|
||||
// The reader is positioned on the first character
|
||||
@@ -1078,128 +685,64 @@ namespace System.Xml
|
||||
string target = ReadName();
|
||||
SkipWhitespace();
|
||||
|
||||
valueLength = 0;
|
||||
StringBuilder valueBuilder = new StringBuilder();
|
||||
|
||||
while (PeekChar() != -1)
|
||||
while (reader.Peek() != -1)
|
||||
{
|
||||
int ch = ReadChar();
|
||||
int ch = reader.Read();
|
||||
|
||||
if (ch == '?' && PeekChar() == '>')
|
||||
if (ch == '?' && reader.Peek() == '>')
|
||||
{
|
||||
ReadChar();
|
||||
reader.Read();
|
||||
break;
|
||||
}
|
||||
|
||||
AppendValueChar((char)ch);
|
||||
valueBuilder.Append((char)ch);
|
||||
}
|
||||
|
||||
SetProperties(
|
||||
XmlNodeType.ProcessingInstruction, // nodeType
|
||||
target, // name
|
||||
false, // isEmptyElement
|
||||
CreateValueString(), // value
|
||||
valueBuilder.ToString(), // value
|
||||
true // clearAttributes
|
||||
);
|
||||
}
|
||||
|
||||
// The reader is positioned on the first character after
|
||||
// the leading '<!'.
|
||||
private void ReadDeclaration()
|
||||
{
|
||||
int ch = PeekChar();
|
||||
|
||||
switch (ch)
|
||||
{
|
||||
case '-':
|
||||
Expect('-');
|
||||
Expect('-');
|
||||
ReadComment();
|
||||
break;
|
||||
case '[':
|
||||
ReadChar();
|
||||
Expect('C');
|
||||
Expect('D');
|
||||
Expect('A');
|
||||
Expect('T');
|
||||
Expect('A');
|
||||
Expect('[');
|
||||
ReadCDATA();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// The reader is positioned on the first character after
|
||||
// the leading '<!--'.
|
||||
private void ReadComment()
|
||||
{
|
||||
valueLength = 0;
|
||||
Expect('-');
|
||||
Expect('-');
|
||||
|
||||
while (PeekChar() != -1)
|
||||
StringBuilder valueBuilder = new StringBuilder();
|
||||
|
||||
while (reader.Peek() != -1)
|
||||
{
|
||||
int ch = ReadChar();
|
||||
int ch = reader.Read();
|
||||
|
||||
if (ch == '-' && PeekChar() == '-')
|
||||
if (ch == '-' && reader.Peek() == '-')
|
||||
{
|
||||
ReadChar();
|
||||
reader.Read();
|
||||
|
||||
if (PeekChar() != '>')
|
||||
if (reader.Peek() != '>')
|
||||
{
|
||||
throw new Exception("comments cannot contain '--'");
|
||||
}
|
||||
|
||||
ReadChar();
|
||||
reader.Read();
|
||||
break;
|
||||
}
|
||||
|
||||
AppendValueChar((char)ch);
|
||||
valueBuilder.Append((char)ch);
|
||||
}
|
||||
|
||||
SetProperties(
|
||||
XmlNodeType.Comment, // nodeType
|
||||
String.Empty, // name
|
||||
false, // isEmptyElement
|
||||
CreateValueString(), // value
|
||||
true // clearAttributes
|
||||
);
|
||||
}
|
||||
|
||||
// The reader is positioned on the first character after
|
||||
// the leading '<![CDATA['.
|
||||
private void ReadCDATA()
|
||||
{
|
||||
valueLength = 0;
|
||||
|
||||
while (PeekChar() != -1)
|
||||
{
|
||||
int ch = ReadChar();
|
||||
|
||||
if (ch == ']' && PeekChar() == ']')
|
||||
{
|
||||
ch = ReadChar(); // ']'
|
||||
|
||||
if (PeekChar() == '>')
|
||||
{
|
||||
ReadChar(); // '>'
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
AppendValueChar(']');
|
||||
AppendValueChar(']');
|
||||
ch = ReadChar();
|
||||
}
|
||||
}
|
||||
|
||||
AppendValueChar((char)ch);
|
||||
}
|
||||
|
||||
++depth;
|
||||
|
||||
SetProperties(
|
||||
XmlNodeType.CDATA, // nodeType
|
||||
String.Empty, // name
|
||||
false, // isEmptyElement
|
||||
CreateValueString(), // value
|
||||
valueBuilder.ToString(), // value
|
||||
true // clearAttributes
|
||||
);
|
||||
}
|
||||
@@ -1208,28 +751,28 @@ namespace System.Xml
|
||||
// of the name.
|
||||
private string ReadName()
|
||||
{
|
||||
if (!XmlChar.IsFirstNameChar(PeekChar()))
|
||||
if (!XmlChar.IsFirstNameChar(reader.Peek()))
|
||||
{
|
||||
throw new Exception("a name did not start with a legal character");
|
||||
}
|
||||
|
||||
nameLength = 0;
|
||||
StringBuilder nameBuilder = new StringBuilder();
|
||||
|
||||
AppendNameChar(ReadChar());
|
||||
nameBuilder.Append((char)reader.Read());
|
||||
|
||||
while (XmlChar.IsNameChar(PeekChar()))
|
||||
while (XmlChar.IsNameChar(reader.Peek()))
|
||||
{
|
||||
AppendNameChar(ReadChar());
|
||||
nameBuilder.Append((char)reader.Read());
|
||||
}
|
||||
|
||||
return CreateNameString();
|
||||
return nameBuilder.ToString();
|
||||
}
|
||||
|
||||
// Read the next character and compare it against the
|
||||
// specified character.
|
||||
private void Expect(int expected)
|
||||
{
|
||||
int ch = ReadChar();
|
||||
int ch = reader.Read();
|
||||
|
||||
if (ch != expected)
|
||||
{
|
||||
@@ -1245,9 +788,9 @@ namespace System.Xml
|
||||
// Does not consume the first non-whitespace character.
|
||||
private void SkipWhitespace()
|
||||
{
|
||||
while (XmlChar.IsWhitespace(PeekChar()))
|
||||
while (XmlChar.IsWhitespace(reader.Peek()))
|
||||
{
|
||||
ReadChar();
|
||||
reader.Read();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
IXmlLineInfo.cs
|
||||
ReadState.cs
|
||||
WhitespaceHandling.cs
|
||||
XmlChar.cs
|
||||
XmlNamespaceManager.cs
|
||||
XmlNameTable.cs
|
||||
XmlNodeType.cs
|
||||
XmlParserContext.cs
|
||||
XmlReader.cs
|
||||
XmlResolver.cs
|
||||
XmlSpace.cs
|
||||
XmlTextReader.cs
|
||||
XmlChar.cs
|
||||
XmlNameTable.cs
|
||||
XmlNamespaceManager.cs
|
||||
XmlNodeType.cs
|
||||
XmlParserContext.cs
|
||||
XmlReader.cs
|
||||
XmlSpace.cs
|
||||
XmlTextReader.cs
|
||||
Whitespace-only changes.
Whitespace-only changes.
@@ -1,5 +1,3 @@
|
||||
DIRS=System.Xml
|
||||
|
||||
all:
|
||||
@echo "You must use 'make windows' or 'make unix'."
|
||||
@echo "'make unix' is broken for now."
|
||||
@@ -11,6 +9,6 @@ unix:
|
||||
@echo "'make unix' is broken for now."
|
||||
|
||||
make-list:
|
||||
for i in $(DIRS); do \
|
||||
cat $$i/common.src $$i/windows.src | sed "s/^/$$i\\\\/"; \
|
||||
done > list
|
||||
cat $$i/common.src $$i/windows.src | sed "s/^/$$i\\\\/";
|
||||
|
||||
test: $(PLATFORM)
|
||||
@@ -1,12 +1,3 @@
|
||||
2001-07-17 John Barnette <[email protected]>
|
||||
* StringCollection.cs:
|
||||
Implemented and working according to spec.
|
||||
* StringIterator.cs:
|
||||
(ADDED) Implemented and working according to spec.
|
||||
* StringCollectionTest.cs:
|
||||
(ADDED) Initial revision contains 17 tests; all of 'em
|
||||
run correctly. More complicated tests to follow.
|
||||
|
||||
2001-07-15 Sean MacIsaac <[email protected]>
|
||||
|
||||
* StringCollection.cs: Added so that CodeDom.* would compile.
|
||||
|
||||
@@ -1,362 +0,0 @@
|
||||
/**
|
||||
* System.Collections.Specialized.NamaValueCollection class implementation
|
||||
*
|
||||
* Author: Gleb Novodran
|
||||
*/
|
||||
// created on 7/21/2001 at 5:15 PM
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
|
||||
namespace System.Collections.Specialized{
|
||||
public class NameValueCollection : NameObjectCollectionBase
|
||||
{
|
||||
string[] cachedAllKeys = null;
|
||||
string[] cachedAll = null;
|
||||
|
||||
//--------------------- Constructors -----------------------------
|
||||
|
||||
/// <summary> SDK: Initializes a new instance of the NameValueCollection class that is empty,
|
||||
/// has the default initial capacity and uses the default case-insensitive hash code provider and the default case-insensitive comparer.
|
||||
/// </summary>
|
||||
public NameValueCollection() : base()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary> SDK: Initializes a new instance of the NameValueCollection class that is empty,
|
||||
/// has the specified initial capacity and uses the default case-insensitive hash code provider and the default case-insensitive comparer.
|
||||
///</summary>
|
||||
public NameValueCollection( int capacity ) : base(capacity)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary> SDK: Copies the entries from the specified NameValueCollection to a new
|
||||
/// NameValueCollection with the same initial capacity as the number of entries copied
|
||||
/// and using the same case-insensitive hash code provider and the same case-insensitive
|
||||
/// comparer as the source collection.
|
||||
/// </summary>
|
||||
/// TODO: uncomment constructor below after it will be possible to compile NameValueCollection and
|
||||
/// NameObjectCollectionBase to the same assembly
|
||||
|
||||
/* public NameValueCollection( NameValueCollection col ) : base(col.HashCodeProvider,col.Comparer)
|
||||
{
|
||||
if (col==null)
|
||||
throw new ArgumentNullException("Null argument is not allowed");
|
||||
Add(col);
|
||||
}
|
||||
*/
|
||||
///<summary>SDK: Initializes a new instance of the NameValueCollection class that is empty,
|
||||
///has the default initial capacity and uses the specified hash code provider and
|
||||
///the specified comparer.</summary>
|
||||
public NameValueCollection( IHashCodeProvider hashProvider, IComparer comparer )
|
||||
: base(hashProvider, comparer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SDK: Copies the entries from the specified NameValueCollection to a new NameValueCollection
|
||||
/// with the specified initial capacity or the same initial capacity as the number of entries
|
||||
/// copied, whichever is greater, and using the default case-insensitive hash code provider and
|
||||
/// the default case-insensitive comparer.
|
||||
/// </summary>
|
||||
/// TODO: uncomment constructor below after it will be possible to compile NameValueCollection and
|
||||
/// NameObjectCollectionBase to the same assembly
|
||||
|
||||
/* public NameValueCollection( int capacity, NameValueCollection col )
|
||||
: base(capacity, col.get_HashCodeProvider(),col.Comparer)
|
||||
{
|
||||
if (col==null)
|
||||
throw new ArgumentNullException("Null argument is not allowed");
|
||||
Add(col);
|
||||
}
|
||||
*/
|
||||
/// <summary>
|
||||
/// SDK: Initializes a new instance of the NameValueCollection class that is serializable
|
||||
/// and uses the specified System.Runtime.Serialization.SerializationInfo and
|
||||
/// System.Runtime.Serialization.StreamingContext.
|
||||
/// </summary>
|
||||
protected NameValueCollection( SerializationInfo info, StreamingContext context )
|
||||
:base(info, context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SDK: Initializes a new instance of the NameValueCollection class that is empty,
|
||||
/// has the specified initial capacity and uses the specified hash code provider and
|
||||
/// the specified comparer.
|
||||
/// </summary>
|
||||
public NameValueCollection( int capacity, IHashCodeProvider hashProvider, IComparer comparer )
|
||||
:base(capacity, hashProvider, comparer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//----------------------- Public Instance Properties -------------------------------
|
||||
|
||||
|
||||
///<summary> SDK:
|
||||
/// Gets all the keys in the NameValueCollection.
|
||||
/// The arrays returned by AllKeys are cached for better performance and are
|
||||
/// automatically refreshed when the collection changes. A derived class can
|
||||
/// invalidate the cached version by calling InvalidateCachedArrays, thereby
|
||||
/// forcing the arrays to be recreated.
|
||||
/// </summary>
|
||||
public virtual string[] AllKeys
|
||||
{
|
||||
get {
|
||||
if (cachedAllKeys==null)
|
||||
cachedAllKeys = BaseGetAllKeys();
|
||||
return this.cachedAllKeys;
|
||||
}
|
||||
}
|
||||
|
||||
public string this[ int index ]
|
||||
{
|
||||
get{
|
||||
return this.Get(index);
|
||||
}
|
||||
}
|
||||
|
||||
public string this[ string name ] {
|
||||
get{
|
||||
return this.Get(name);
|
||||
}
|
||||
set{
|
||||
this.Set(name,value);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////// Public Instance Methods //////////////////////////////
|
||||
|
||||
/// <summary> SDK: Copies the entries in the specified NameValueCollection
|
||||
/// to the current NameValueCollection.</summary>
|
||||
/// LAMESPEC: see description that comes this Add(string, string)
|
||||
|
||||
public void Add( NameValueCollection c ){
|
||||
|
||||
if (this.IsReadOnly)
|
||||
throw new NotSupportedException("Collection is read-only");
|
||||
if (c==null)
|
||||
throw new ArgumentNullException();
|
||||
|
||||
InvalidateCachedArrays();
|
||||
ArrayList values = null;
|
||||
|
||||
int max = c.Count;
|
||||
for(int i=0; i<max; i++){
|
||||
values=(ArrayList)BaseGet(c.GetKey(i));
|
||||
if (values==null)
|
||||
values = new ArrayList();
|
||||
values.AddRange((ArrayList)c.BaseGet(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary> SDK: Adds an entry with the specified name and value to the
|
||||
/// NameValueCollection. </summary>
|
||||
///
|
||||
/// LAMESPEC:
|
||||
/// in SDK doc: If the same value already exists under the same key in the collection,
|
||||
/// the new value overwrites the old value.
|
||||
/// however the Microsoft implemenatation in this case just adds one more value
|
||||
/// in other words after
|
||||
/// <code>
|
||||
/// NameValueCollection nvc;
|
||||
/// nvc.Add("LAZY","BASTARD")
|
||||
/// nvc.Add("LAZY","BASTARD")
|
||||
/// </code>
|
||||
/// nvc.Get("LAZY") will be "BASTARD,BASTARD" instead of "BASTARD"
|
||||
|
||||
public virtual void Add( string name, string val )
|
||||
{
|
||||
|
||||
if (this.IsReadOnly)
|
||||
throw new NotSupportedException("Collection is read-only");
|
||||
|
||||
InvalidateCachedArrays();
|
||||
ArrayList values = (ArrayList)BaseGet(name);
|
||||
if (values==null){
|
||||
values = new ArrayList();
|
||||
if (val!=null)
|
||||
values.Add(val);
|
||||
BaseAdd(name,values);
|
||||
}
|
||||
else {
|
||||
if (val!=null)
|
||||
values.Add(val);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary> SDK: Invalidates the cached arrays and removes all entries from
|
||||
/// the NameValueCollection.</summary>
|
||||
|
||||
public void Clear(){
|
||||
if (this.IsReadOnly)
|
||||
throw new NotSupportedException("Collection is read-only");
|
||||
InvalidateCachedArrays();
|
||||
BaseClear();
|
||||
}
|
||||
|
||||
/// <summary> SDK: Copies the entire NameValueCollection to a compatible one-dimensional Array,
|
||||
/// starting at the specified index of the target array.</summary>
|
||||
|
||||
public void CopyTo( Array dest, int index )
|
||||
{
|
||||
if (dest==null)
|
||||
throw new ArgumentNullException("Null argument - dest");
|
||||
if (index<0)
|
||||
throw new ArgumentOutOfRangeException("index is less than 0");
|
||||
// throw new Exception("Not implemented yet");
|
||||
|
||||
//TODO: add implementation here
|
||||
if (cachedAll==null)
|
||||
RefreshCachedAll();
|
||||
cachedAll.CopyTo(dest, index);
|
||||
}
|
||||
protected void RefreshCachedAll()
|
||||
{
|
||||
this.cachedAll=null;
|
||||
int max = this.Count;
|
||||
cachedAll = new string[max];
|
||||
for(int i=0;i<max;i++){
|
||||
cachedAll[i] = this.Get(i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary> SDK: Gets the values at the specified index of the NameValueCollection combined
|
||||
/// into one comma-separated list.</summary>
|
||||
|
||||
public virtual string Get( int index )
|
||||
{
|
||||
ArrayList values = (ArrayList)BaseGet(index);
|
||||
// if index is out of range BaseGet throws an ArgumentOutOfRangeException
|
||||
|
||||
return AsSingleString(values);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* SDK: Gets the values associated with the specified key from the NameValueCollection
|
||||
* combined into one comma-separated list.
|
||||
*/
|
||||
public virtual string Get( string name )
|
||||
{
|
||||
ArrayList values = (ArrayList)BaseGet(name);
|
||||
/* if (values==null)
|
||||
Console.WriteLine("BaseGet returned null");*/
|
||||
return AsSingleString(values);
|
||||
// -------------------------------------------------------------
|
||||
|
||||
}
|
||||
/// <summary></summary>
|
||||
private static string AsSingleString(ArrayList values)
|
||||
{
|
||||
const char separator = ',';
|
||||
|
||||
if (values==null)
|
||||
return null;
|
||||
int max = values.Count;
|
||||
|
||||
if (max==0)
|
||||
return null;
|
||||
//TODO: reimplement this
|
||||
StringBuilder sb = new StringBuilder((string)values[0]);
|
||||
for (int i=1; i<max; i++){
|
||||
sb.Append(separator);
|
||||
sb.Append(values[i]);
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>SDK: Gets the key at the specified index of the NameValueCollection.</summary>
|
||||
public virtual string GetKey( int index )
|
||||
{
|
||||
return BaseGetKey(index);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>SDK: Gets the values at the specified index of the NameValueCollection.</summary>
|
||||
|
||||
public virtual string[] GetValues( int index )
|
||||
{
|
||||
ArrayList values = (ArrayList)BaseGet(index);
|
||||
|
||||
return AsStringArray(values);
|
||||
}
|
||||
|
||||
|
||||
public virtual string[] GetValues( string name )
|
||||
{
|
||||
ArrayList values = (ArrayList)BaseGet(name);
|
||||
|
||||
return AsStringArray(values);
|
||||
}
|
||||
|
||||
private static string[] AsStringArray(ArrayList values){
|
||||
|
||||
int max = values.Count;//get_Count();
|
||||
if (max==0)
|
||||
return null;
|
||||
|
||||
string[] valArray =new string[max];
|
||||
values.CopyTo(valArray);
|
||||
return valArray;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// SDK: Gets a value indicating whether the NameValueCollection contains keys that
|
||||
/// are not a null reference
|
||||
/// </summary>
|
||||
|
||||
public bool HasKeys()
|
||||
{
|
||||
return BaseHasKeys();
|
||||
}
|
||||
|
||||
public virtual void Remove( string name )
|
||||
{
|
||||
if (this.IsReadOnly)
|
||||
throw new NotSupportedException("Collection is read-only");
|
||||
InvalidateCachedArrays();
|
||||
BaseRemove(name);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the value of an entry in the NameValueCollection.
|
||||
/// </summary>
|
||||
public virtual void Set( string name, string value )
|
||||
{
|
||||
if (this.IsReadOnly)
|
||||
throw new NotSupportedException("Collection is read-only");
|
||||
InvalidateCachedArrays();
|
||||
|
||||
ArrayList values = new ArrayList();
|
||||
values.Add(value);
|
||||
BaseSet(name,values);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//---------------------- Protected Instance Methods ----------------------
|
||||
|
||||
protected void InvalidateCachedArrays()
|
||||
{
|
||||
cachedAllKeys = null;
|
||||
cachedAll = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,292 +1,14 @@
|
||||
/* System.Collections.Specialized.StringCollection.cs
|
||||
* Authors:
|
||||
* John Barnette ([email protected])
|
||||
* Sean MacIsaac ([email protected])
|
||||
*
|
||||
* Copyright (C) 2001 John Barnette
|
||||
* (C) Ximian, Inc. http://www.ximian.com
|
||||
*
|
||||
* NOTES:
|
||||
* I bet Microsoft uses ArrayList as a backing store for this; I wonder what
|
||||
* the performance difference will be.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace System.Collections.Specialized {
|
||||
public class StringCollection : IList, ICollection, IEnumerable {
|
||||
private static int InitialCapacity = 11;
|
||||
private static float CapacityMultiplier = 2.0f;
|
||||
|
||||
private int count;
|
||||
private int modCount;
|
||||
|
||||
private string[] entries;
|
||||
|
||||
// Public Constructor
|
||||
public StringCollection() {
|
||||
entries = new string[InitialCapacity];
|
||||
count = 0;
|
||||
modCount = 0;
|
||||
}
|
||||
|
||||
// Public Instance Properties
|
||||
public int Count {
|
||||
get { return count; }
|
||||
}
|
||||
|
||||
public bool IsFixedSize {
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool IsReadOnly {
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public bool IsSynchronized {
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
object IList.this[int index] {
|
||||
get { return this[index]; }
|
||||
set { this[index] = value.ToString(); }
|
||||
}
|
||||
|
||||
public string this[int index] {
|
||||
get {
|
||||
if (index < 0 || index >= count) {
|
||||
throw new ArgumentOutOfRangeException("index");
|
||||
}
|
||||
|
||||
return entries[index];
|
||||
}
|
||||
|
||||
set {
|
||||
if (index < 0 || index >= count) {
|
||||
throw new ArgumentOutOfRangeException("index");
|
||||
}
|
||||
|
||||
modCount++;
|
||||
entries[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public object SyncRoot {
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
|
||||
// Public Instance Methods
|
||||
|
||||
int IList.Add(object value) {
|
||||
return Add(value.ToString());
|
||||
}
|
||||
|
||||
public int Add(string value) {
|
||||
modCount++;
|
||||
Resize(count + 1);
|
||||
int index = count++;
|
||||
entries[index] = value;
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
public void AddRange(string[] value) {
|
||||
int numEntries = value.Length;
|
||||
|
||||
modCount++;
|
||||
Resize(count + numEntries);
|
||||
Array.Copy(value, 0, entries, count, numEntries);
|
||||
count += numEntries;
|
||||
}
|
||||
|
||||
public void Clear() {
|
||||
modCount++;
|
||||
count = 0;
|
||||
}
|
||||
|
||||
bool IList.Contains(object value) {
|
||||
return Contains(value.ToString());
|
||||
}
|
||||
|
||||
public bool Contains(string value) {
|
||||
foreach (string entry in entries) {
|
||||
if (value.Equals(entry)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ICollection.CopyTo(Array array, int index) {
|
||||
if (array == null) {
|
||||
throw new ArgumentNullException("array");
|
||||
} else if (index < 0) {
|
||||
throw new ArgumentOutOfRangeException("index");
|
||||
} else if (array.Rank > 1) {
|
||||
throw new ArgumentException("array");
|
||||
} else if (index >= array.Length) {
|
||||
throw new ArgumentException("index");
|
||||
} else if (array.Length - index < count) {
|
||||
throw new ArgumentException("array");
|
||||
}
|
||||
|
||||
Array.Copy(entries, 0, array, index, count);
|
||||
}
|
||||
|
||||
public void CopyTo(string[] array, int index) {
|
||||
if (array == null) {
|
||||
throw new ArgumentNullException("array");
|
||||
} else if (index < 0) {
|
||||
throw new ArgumentOutOfRangeException("index");
|
||||
} else if (array.Rank > 1) {
|
||||
throw new ArgumentException("array");
|
||||
} else if (index >= array.Length) {
|
||||
throw new ArgumentException("index");
|
||||
} else if (array.Length - index < count) {
|
||||
throw new ArgumentException("array");
|
||||
}
|
||||
|
||||
Array.Copy(entries, 0, array, index, count);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() {
|
||||
return new InternalEnumerator(this);
|
||||
}
|
||||
|
||||
public StringEnumerator GetEnumerator() {
|
||||
return new StringEnumerator(this);
|
||||
}
|
||||
|
||||
int IList.IndexOf(object value) {
|
||||
return IndexOf(value.ToString());
|
||||
}
|
||||
|
||||
public int IndexOf(string value) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (value.Equals(entries[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void IList.Insert(int index, object value) {
|
||||
Insert(index, value.ToString());
|
||||
}
|
||||
|
||||
public void Insert(int index, string value) {
|
||||
if (index < 0 || index > count) {
|
||||
throw new ArgumentOutOfRangeException("index");
|
||||
}
|
||||
|
||||
modCount++;
|
||||
Resize(count + 1);
|
||||
Array.Copy(entries, index, entries, index + 1, count - index);
|
||||
entries[index] = value;
|
||||
count++;
|
||||
}
|
||||
|
||||
|
||||
void IList.Remove(object value) {
|
||||
Remove(value.ToString());
|
||||
}
|
||||
|
||||
public void Remove(string value) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (value.Equals(entries[i])) {
|
||||
RemoveAt(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveAt(int index) {
|
||||
if (index < 0 || index >= count) {
|
||||
throw new ArgumentOutOfRangeException("index");
|
||||
}
|
||||
|
||||
int remaining = count - index - 1;
|
||||
|
||||
modCount++;
|
||||
|
||||
if (remaining > 0) {
|
||||
Array.Copy(entries, index + 1, entries, index, remaining);
|
||||
}
|
||||
|
||||
count--;
|
||||
entries[count] = null;
|
||||
}
|
||||
|
||||
|
||||
// Private Instance Methods
|
||||
|
||||
private void Resize(int minSize) {
|
||||
int oldSize = entries.Length;
|
||||
|
||||
if (minSize > oldSize) {
|
||||
string[] oldEntries = entries;
|
||||
int newSize = (int) (oldEntries.Length * CapacityMultiplier);
|
||||
|
||||
if (newSize < minSize) newSize = minSize;
|
||||
entries = new string[newSize];
|
||||
Array.Copy(oldEntries, 0, entries, 0, count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Private classes
|
||||
|
||||
private class InternalEnumerator : IEnumerator {
|
||||
private StringCollection data;
|
||||
private int index;
|
||||
private int myModCount;
|
||||
|
||||
public InternalEnumerator(StringCollection data) {
|
||||
this.data = data;
|
||||
myModCount = data.modCount;
|
||||
index = -1;
|
||||
}
|
||||
|
||||
|
||||
// Public Instance Properties
|
||||
|
||||
public object Current {
|
||||
get {
|
||||
if (myModCount != data.modCount) {
|
||||
throw new InvalidOperationException();
|
||||
} else if (index < 0 || index > data.count - 1) {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
return data[index];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Public Instance Methods
|
||||
|
||||
public bool MoveNext() {
|
||||
if (myModCount != data.modCount) {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
if (++index >= data.count - 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Reset() {
|
||||
if (myModCount != data.modCount) {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
index = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// System.Collections.Specialized.StringCollection.cs
|
||||
//
|
||||
// Author:
|
||||
// Sean MacIsaac ([email protected])
|
||||
//
|
||||
// (C) Ximian, Inc. http://www.ximian.com
|
||||
//
|
||||
|
||||
namespace System.Collections.Specialized {
|
||||
|
||||
public class StringCollection {
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/* System.Collections.Specialized.StringEnumerator.cs
|
||||
* Authors:
|
||||
* John Barnette ([email protected])
|
||||
*
|
||||
* Copyright (C) 2001 John Barnette
|
||||
*/
|
||||
|
||||
namespace System.Collections.Specialized {
|
||||
public class StringEnumerator {
|
||||
private StringCollection coll;
|
||||
private IEnumerator enumerable;
|
||||
|
||||
// assembly-scoped constructor
|
||||
internal StringEnumerator(StringCollection coll) {
|
||||
this.coll = coll;
|
||||
this.enumerable = ((IEnumerable)coll).GetEnumerator();
|
||||
}
|
||||
|
||||
// Public Instance Properties
|
||||
|
||||
public string Current {
|
||||
get { return (string) enumerable.Current; }
|
||||
}
|
||||
|
||||
|
||||
// Public Instance Methods
|
||||
|
||||
public bool MoveNext() {
|
||||
return enumerable.MoveNext();
|
||||
}
|
||||
|
||||
public void Reset() {
|
||||
enumerable.Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,2 @@
|
||||
BitVector32.cs
|
||||
StringCollection.cs
|
||||
StringEnumerator.cs
|
||||
@@ -1,46 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.AddressFamily.cs
|
||||
//
|
||||
// Author:
|
||||
// Andrew Sutton
|
||||
//
|
||||
// (C) Andrew Sutton
|
||||
//
|
||||
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
public enum AddressFamily
|
||||
{
|
||||
AppleTalk,
|
||||
Atm,
|
||||
Banyan,
|
||||
Ccitt,
|
||||
Chaos,
|
||||
Cluster,
|
||||
DataKit,
|
||||
DataLink,
|
||||
DecNet,
|
||||
Ecma,
|
||||
FireFox,
|
||||
HyperChannel,
|
||||
Ieee12844,
|
||||
ImpLink,
|
||||
InterNetwork,
|
||||
InterNetworkV6,
|
||||
Ipx,
|
||||
Irda,
|
||||
Iso,
|
||||
Lat,
|
||||
Max,
|
||||
NetBios,
|
||||
NetworkDesigners,
|
||||
NS,
|
||||
Osi,
|
||||
Pup,
|
||||
Sna,
|
||||
Unix,
|
||||
Unknown,
|
||||
Unspecified,
|
||||
VoiceView
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.LingerOption.cs
|
||||
//
|
||||
// Author:
|
||||
// Andrew Sutton
|
||||
//
|
||||
// (C) Andrew Sutton
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
// <remarks>
|
||||
// Encapsulates a linger option.
|
||||
// </remarks>
|
||||
public class LingerOption
|
||||
{
|
||||
protected bool enabled;
|
||||
protected int seconds;
|
||||
|
||||
public LingerOption (bool enable, int secs)
|
||||
{
|
||||
enabled = enable;
|
||||
seconds = secs;
|
||||
}
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
get { return enabled; }
|
||||
set { enabled = value; }
|
||||
}
|
||||
|
||||
public int LingerTime
|
||||
{
|
||||
get { return seconds; }
|
||||
set { seconds = value; }
|
||||
}
|
||||
|
||||
public override bool Equals (object o)
|
||||
{
|
||||
return (enabled == o.enabled) && (seconds == o.seconds);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return seconds;
|
||||
}
|
||||
|
||||
public string ToString()
|
||||
{
|
||||
string ret;
|
||||
if (enabled) {
|
||||
ret = "off";
|
||||
}
|
||||
else {
|
||||
ret = seconds.ToString();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.MulticastOption.cs
|
||||
//
|
||||
// Author:
|
||||
// Andrew Sutton
|
||||
//
|
||||
// (C) Andrew Sutton
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
// <remarks>
|
||||
// Encapsulates a multicast option
|
||||
// </remarks>
|
||||
public class MulticastOption
|
||||
{
|
||||
protected IPAddress group;
|
||||
protected IPAddress local;
|
||||
|
||||
public MulticastOption (IPAddress grp)
|
||||
{
|
||||
group = grp;
|
||||
}
|
||||
|
||||
public MulticastOption (IPAddress grp, IPAddress addr)
|
||||
{
|
||||
group = grp;
|
||||
local = addr;
|
||||
}
|
||||
|
||||
public IPAddress Group
|
||||
{
|
||||
get { return group; }
|
||||
set { group = value; }
|
||||
}
|
||||
|
||||
public IPAddress LocalAddress
|
||||
{
|
||||
get { return local; }
|
||||
set { local = value; }
|
||||
}
|
||||
|
||||
public override bool Equals (object o)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return group.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return group.ToString() + " " + local.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.NetworkStream.cs
|
||||
//
|
||||
// Author:
|
||||
// Andrew Sutton
|
||||
//
|
||||
// (C) Andrew Sutton
|
||||
//
|
||||
|
||||
using System.IO;
|
||||
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
public class NetworkStream : Stream
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.ProtocolFamily.cs
|
||||
//
|
||||
// Author:
|
||||
// Andrew Sutton
|
||||
//
|
||||
// (C) Andrew Sutton
|
||||
//
|
||||
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
public enum ProtocolFamily
|
||||
{
|
||||
AppleTalk,
|
||||
Atm,
|
||||
Banyan,
|
||||
Ccitt,
|
||||
Chaos,
|
||||
Cluster,
|
||||
DataKit,
|
||||
DataLink,
|
||||
DecNet,
|
||||
Ecma,
|
||||
FireFox,
|
||||
HyperChannel,
|
||||
Ieee12844,
|
||||
ImpLink,
|
||||
InterNetwork,
|
||||
InterNetworkV6,
|
||||
Ipx,
|
||||
Irda,
|
||||
Iso,
|
||||
Lat,
|
||||
Max,
|
||||
NetBios,
|
||||
NetworkDesigners,
|
||||
NS,
|
||||
Osi,
|
||||
Pup,
|
||||
Sna,
|
||||
Unix,
|
||||
Unknown,
|
||||
Unspecified,
|
||||
VoiceView
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.ProtocolType.cs
|
||||
//
|
||||
// Author:
|
||||
// Andrew Sutton
|
||||
//
|
||||
// (C) Andrew Sutton
|
||||
//
|
||||
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
public enum ProtocolType
|
||||
{
|
||||
Ggp,
|
||||
Icmp,
|
||||
Idp,
|
||||
Igmp,
|
||||
Ip,
|
||||
Ipx,
|
||||
ND,
|
||||
Pup,
|
||||
Raw,
|
||||
Spx,
|
||||
SpxII,
|
||||
Tcp,
|
||||
Udp,
|
||||
Unknown,
|
||||
Unspecified
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.SelectMode.cs
|
||||
//
|
||||
// Author:
|
||||
// Andrew Sutton
|
||||
//
|
||||
// (C) Andrew Sutton
|
||||
//
|
||||
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
public enum SelectMode
|
||||
{
|
||||
SelectError,
|
||||
SelectRead,
|
||||
SelectWrite
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.Socket.cs
|
||||
//
|
||||
// Author:
|
||||
// Andrew Sutton
|
||||
//
|
||||
// (C) Andrew Sutton
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
public class Socket : IDisposable
|
||||
{
|
||||
public Socket (AddressFamily af, SocketType type, ProtocolType prot)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.NetworkStream.cs
|
||||
//
|
||||
// Author:
|
||||
// Andrew Sutton
|
||||
//
|
||||
// (C) Andrew Sutton
|
||||
//
|
||||
using System;
|
||||
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
// <remarks>
|
||||
// A socket exception. Does this REALLY need to
|
||||
// be derived from Win32Exception? It seems a
|
||||
// little lame.
|
||||
//
|
||||
// This needs some work...
|
||||
// </remarks>
|
||||
public class SocketException : Exception
|
||||
{
|
||||
protected int error_code;
|
||||
protected int native_code;
|
||||
protected string help_link;
|
||||
protected string message;
|
||||
|
||||
public SocketException ()
|
||||
{
|
||||
error_code = 0;
|
||||
}
|
||||
|
||||
public SocketException (int error)
|
||||
{
|
||||
error_code = error;
|
||||
}
|
||||
|
||||
public SocketException (SerializationInfo info, StreamingContext cxt)
|
||||
{
|
||||
}
|
||||
|
||||
public override int ErrorCode
|
||||
{
|
||||
get { return error_code; }
|
||||
}
|
||||
|
||||
public override string HelpLink
|
||||
{
|
||||
get { return help_link; }
|
||||
set { help_link = value; }
|
||||
}
|
||||
|
||||
public override Exception InnerException
|
||||
{
|
||||
get { return inner_exception }
|
||||
}
|
||||
|
||||
public override string Message
|
||||
{
|
||||
get { return message; }
|
||||
}
|
||||
|
||||
public override int NativeErrorCode
|
||||
{
|
||||
get { return native_code; }
|
||||
}
|
||||
|
||||
public override string Source
|
||||
{
|
||||
get { return source; }
|
||||
}
|
||||
|
||||
public override string StackTrace
|
||||
{
|
||||
get { return stack_trace; }
|
||||
}
|
||||
|
||||
public override MethodBase TargetSite
|
||||
{
|
||||
get { return target_site; }
|
||||
}
|
||||
|
||||
protected override int HResult
|
||||
{
|
||||
get { return hresult; }
|
||||
set { hresult = value; }
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return native_code;
|
||||
}
|
||||
|
||||
public override void GetObjectData( SerializationInfo info, StreamingContext cxt )
|
||||
{
|
||||
// TODO: fill this in
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return error_code + " " + help_link;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.SocketFlags.cs
|
||||
//
|
||||
// Author:
|
||||
// Andrew Sutton
|
||||
//
|
||||
// (C) Andrew Sutton
|
||||
//
|
||||
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
public enum SocketFlags
|
||||
{
|
||||
DontRoute,
|
||||
MaxIOVectorLength,
|
||||
None,
|
||||
OutOfBand,
|
||||
Partial,
|
||||
Peek
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.SocketOptionLevel.cs
|
||||
//
|
||||
// Author:
|
||||
// Andrew Sutton
|
||||
//
|
||||
// (C) Andrew Sutton
|
||||
//
|
||||
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
public enum SocketOptionLevel
|
||||
{
|
||||
Ip,
|
||||
Socket,
|
||||
Tcp,
|
||||
Udp
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.SocketOptionName.cs
|
||||
//
|
||||
// Author:
|
||||
// Andrew Sutton
|
||||
//
|
||||
// (C) Andrew Sutton
|
||||
//
|
||||
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
public enum SocketOptionName
|
||||
{
|
||||
AcceptConnection,
|
||||
AddMembership,
|
||||
AddSourceMembership,
|
||||
BlockSource,
|
||||
Broadcast,
|
||||
BsdUrgent,
|
||||
ChecksumCoverage,
|
||||
Debug,
|
||||
DontFragment,
|
||||
DontLinger,
|
||||
DontRoute,
|
||||
DropMembership,
|
||||
DropSourceMembership,
|
||||
Error,
|
||||
ExclusiveAddress,
|
||||
Expedited,
|
||||
HeaderIncluded,
|
||||
IPOptions,
|
||||
IPTimeToLive,
|
||||
KeepAlive,
|
||||
Linger,
|
||||
MaxConnections,
|
||||
MulticastUnterface,
|
||||
MulticastLoopback,
|
||||
MulticastTimeToLive,
|
||||
NoChecksum,
|
||||
NoDelay,
|
||||
OutOfBandInline,
|
||||
PacketInformation,
|
||||
ReceiveBuffer,
|
||||
ReceiveLowWater,
|
||||
ReceiveTimeout,
|
||||
SendBuffer,
|
||||
SendLowWater,
|
||||
SendTimeout,
|
||||
Type,
|
||||
TypeOfService,
|
||||
UnblockSource,
|
||||
UseLoopback
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.SocketShutdown.cs
|
||||
//
|
||||
// Author:
|
||||
// Andrew Sutton
|
||||
//
|
||||
// (C) Andrew Sutton
|
||||
//
|
||||
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
public enum SocketShutdown
|
||||
{
|
||||
Both,
|
||||
Receive,
|
||||
Send
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.SocketType.cs
|
||||
//
|
||||
// Author:
|
||||
// Andrew Sutton
|
||||
//
|
||||
// (C) Andrew Sutton
|
||||
//
|
||||
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
public enum SocketType
|
||||
{
|
||||
Dgram,
|
||||
Raw,
|
||||
Rdm,
|
||||
Seqpacket,
|
||||
Stream,
|
||||
Unknown
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
AddressFamily.cs
|
||||
MulticastOption.cs
|
||||
ProtocolFamily.cs
|
||||
ProtocolType.cs
|
||||
SelectMode.cs
|
||||
SocketFlags.cs
|
||||
SocketOptionLevel.cs
|
||||
SocketOptionName.cs
|
||||
SocketShutdown.cs
|
||||
SocketType.cs
|
||||
Whitespace-only changes.
Whitespace-only changes.
@@ -10,6 +10,8 @@ namespace System.Net {
|
||||
// <remarks>
|
||||
// Base authentication interface for Web clients.
|
||||
// </remarks>
|
||||
public interface ICredentials {
|
||||
public interface ICredential {
|
||||
|
||||
NetworkCredential GetCredential (string uri, string AuthType);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
AuthenticationManager.cs
|
||||
Authorization.cs
|
||||
EndPoint.cs
|
||||
IAuthenticationModule.cs
|
||||
ICredentialLookup.cs
|
||||
IPAdress.cs
|
||||
IPEndPoint.cs
|
||||
SocketAddress.cs
|
||||
@@ -1,178 +0,0 @@
|
||||
// created on 7/21/2001 at 2:36 PM
|
||||
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using System.Text;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
|
||||
|
||||
namespace Testsuite.System.Collections.Specialized {
|
||||
|
||||
|
||||
/// <summary>Microsoft NameValueCollection test.</summary>
|
||||
public class NameValueCollectionTest {
|
||||
public static ITest Suite {
|
||||
get {
|
||||
TestSuite suite= new TestSuite("All NameValueCollection Tests");
|
||||
suite.AddTest(BasicOperationsTest.Suite);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public class BasicOperationsTest : TestCase {
|
||||
|
||||
protected NameValueCollection nvc;
|
||||
private static Random rnd;
|
||||
|
||||
public BasicOperationsTest(String name) : base(name) {}
|
||||
|
||||
protected override void SetUp() {
|
||||
nvc = new NameValueCollection();
|
||||
rnd=new Random();
|
||||
}
|
||||
|
||||
public static ITest Suite {
|
||||
get {
|
||||
return new TestSuite(typeof(BasicOperationsTest));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void SetDefaultData() {
|
||||
nvc.Clear();
|
||||
nvc.Add("k1","this");
|
||||
nvc.Add("k2","test");
|
||||
nvc.Add("k3","is");
|
||||
nvc.Add("k4","silly");
|
||||
}
|
||||
private static string FormatForPrinting(NameValueCollection nv)
|
||||
{
|
||||
if (nv==null)
|
||||
return null;
|
||||
int max = nv.Count;
|
||||
StringBuilder sb = new StringBuilder("-\t-Key-\t-Value-\n");
|
||||
for (int i=0; i<max; i++){
|
||||
|
||||
sb.Append("\t"+nv.GetKey(i)+"\t"+nv[i]+"\n");
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
|
||||
public void TestAddRemoveClearSetGet()
|
||||
{
|
||||
nvc.Clear();
|
||||
Assert(nvc.Count==0&& !nvc.HasKeys());
|
||||
|
||||
SetDefaultData();
|
||||
Assert(nvc.Count==4);
|
||||
Assert("Get operation returns wrong result.\n"+FormatForPrinting(nvc),(nvc.Get(0).Equals("this"))&&(nvc.Get("k1").Equals("this")));
|
||||
|
||||
|
||||
nvc.Add("k2","programmer");
|
||||
Assert(nvc["k2"].Equals("test,programmer"));
|
||||
|
||||
nvc["k2"]="project";
|
||||
nvc.Add("k2","project");
|
||||
Assert(nvc.Count==4);
|
||||
Assert("Wrong effect of add(samekey,samevalue)\n"+FormatForPrinting(nvc),nvc["k2"].Equals("project"));
|
||||
// TODO: add Remove test
|
||||
nvc.Remove("k4");
|
||||
Assert("wrong nvc.Count="+nvc.Count,nvc.Count==3);
|
||||
Assert(nvc["k4"]==null);
|
||||
|
||||
NameValueCollection nvc1 = new NameValueCollection();
|
||||
nvc1["k1"]="these";
|
||||
nvc1["k5"]="!";
|
||||
nvc.Add(nvc1);
|
||||
Assert(FormatForPrinting(nvc)+"Count is wrong after Add(nvc1) Count="+nvc.Count,nvc.Count==4);
|
||||
Assert("Values are wrong after Add(nvc1)",(nvc["k1"].Equals("this,these"))&&(nvc["k5"].Equals("!")));
|
||||
|
||||
nvc.Set("k3","accomplished");
|
||||
Assert("Wrong result of Set operation",nvc["k3"].Equals("accomplished"));
|
||||
|
||||
}
|
||||
|
||||
public void TestGetKeyGetValues()
|
||||
{
|
||||
SetDefaultData();
|
||||
Assert(nvc.GetKey(0).Equals("k1"));
|
||||
string[] values = nvc.GetValues(0);
|
||||
Assert(values[0].Equals("this"));
|
||||
|
||||
}
|
||||
|
||||
public void TestCopyTo() {
|
||||
SetDefaultData();
|
||||
string[] entries=new string[nvc.Count];
|
||||
nvc.CopyTo(entries,0);
|
||||
//Message(FormatForPrinting(nvc));
|
||||
//Assert("Not an entry.",entries[0] is DictionaryEntry);
|
||||
}
|
||||
|
||||
public void TestUnderHeavyLoad() {
|
||||
|
||||
//TODO: add memory and time measurement
|
||||
|
||||
nvc.Clear();
|
||||
int max=10000;
|
||||
String[] cache=new String[max*2];
|
||||
int n=0;
|
||||
|
||||
for (int i=0;i<max;i++) {
|
||||
int id=rnd.Next()&0xFFFF;
|
||||
String key=""+id+"-key-"+id;
|
||||
String val="value-"+id;
|
||||
if (nvc[key]==null) {
|
||||
nvc[key]=val;
|
||||
cache[n]=key;
|
||||
cache[n+max]=val;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
Assert(nvc.Count==n);
|
||||
|
||||
for (int i=0;i<n;i++) {
|
||||
String key=cache[i];
|
||||
String val=nvc[key] as String;
|
||||
String err="nvc[\""+key+"\"]=\""+val+
|
||||
"\", expected \""+cache[i+max]+"\"";
|
||||
Assert(err,val!=null && val.Equals(cache[i+max]));
|
||||
}
|
||||
|
||||
int r1=(n/3);
|
||||
int r2=r1+(n/5);
|
||||
|
||||
for (int i=r1;i<r2;i++) {
|
||||
nvc.Remove(cache[i]);
|
||||
}
|
||||
|
||||
|
||||
for (int i=0;i<n;i++) {
|
||||
if (i>=r1 && i<r2) {
|
||||
Assert(nvc[cache[i]]==null);
|
||||
} else {
|
||||
String key=cache[i];
|
||||
String val=nvc[key] as String;
|
||||
String err="ht[\""+key+"\"]=\""+val+
|
||||
"\", expected \""+cache[i+max]+"\"";
|
||||
Assert(err,val!=null && val.Equals(cache[i+max]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,152 +0,0 @@
|
||||
/* System.Collections.Specialized.StringCollection.cs
|
||||
* Authors:
|
||||
* John Barnette ([email protected])
|
||||
*
|
||||
* Copyright (C) 2001 John Barnette
|
||||
*/
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace System.Collections.Specialized {
|
||||
public class StringCollectionTest : TestCase {
|
||||
private StringCollection sc;
|
||||
string[] strings = {
|
||||
"foo",
|
||||
"bar",
|
||||
"baz",
|
||||
"john",
|
||||
"paul",
|
||||
"george",
|
||||
"ringo"
|
||||
};
|
||||
|
||||
public StringCollectionTest(string name) : base(name) {}
|
||||
|
||||
protected override void SetUp() {
|
||||
sc = new StringCollection();
|
||||
sc.AddRange(strings);
|
||||
}
|
||||
|
||||
// Simple Tests
|
||||
|
||||
public void TestSimpleCount() {
|
||||
Assert(sc.Count == 7);
|
||||
}
|
||||
|
||||
public void TestSimpleIsFixedSize() {
|
||||
Assert(!sc.IsFixedSize);
|
||||
}
|
||||
|
||||
public void TestSimpleIsReadOnly() {
|
||||
Assert(!sc.IsReadOnly);
|
||||
}
|
||||
|
||||
public void TestSimpleIsSynchronized() {
|
||||
Assert(!sc.IsSynchronized);
|
||||
}
|
||||
|
||||
public void TestSimpleItemGet() {
|
||||
for(int i = 0; i < strings.Length; i++) {
|
||||
Assert(strings[i].Equals(sc[i]));
|
||||
}
|
||||
}
|
||||
|
||||
public void TestSimpleItemSet() {
|
||||
sc[0] = "bob";
|
||||
Assert(sc[0].Equals("bob"));
|
||||
}
|
||||
|
||||
public void TestSimpleSyncRoot() {
|
||||
Assert(sc.Equals(sc.SyncRoot));
|
||||
}
|
||||
|
||||
public void TestSimpleAdd() {
|
||||
int index = sc.Add("chuck");
|
||||
Assert(index == strings.Length);
|
||||
Assert(sc[strings.Length].Equals("chuck"));
|
||||
|
||||
}
|
||||
|
||||
public void TestSimpleAddRange() {
|
||||
string[] newStrings = {
|
||||
"peter",
|
||||
"paul",
|
||||
"mary"
|
||||
};
|
||||
|
||||
int index = sc.Count;
|
||||
sc.AddRange(newStrings);
|
||||
|
||||
Assert(sc.Count == index + newStrings.Length);
|
||||
|
||||
for (int i = 0; i+index <= sc.Count-1; i++) {
|
||||
Assert(newStrings[i].Equals(sc[i+index]));
|
||||
}
|
||||
}
|
||||
|
||||
public void TestSimpleClear() {
|
||||
sc.Clear();
|
||||
Assert(sc.Count == 0);
|
||||
}
|
||||
|
||||
public void TestSimpleContains() {
|
||||
Assert(sc.Contains(strings[0]));
|
||||
Assert(!sc.Contains("NOT CONTAINED"));
|
||||
}
|
||||
|
||||
public void TestSimpleCopyTo() {
|
||||
string[] copyArray = new string[sc.Count];
|
||||
sc.CopyTo(copyArray, 0);
|
||||
for (int i = 0; i < copyArray.Length; i++) {
|
||||
Assert(copyArray[i] == sc[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void TestSimpleGetEnumerator() {
|
||||
int index = 0;
|
||||
foreach(string s in sc) {
|
||||
Assert(s.Equals(strings[index]));
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
public void TestSimpleIndexOf() {
|
||||
Assert(sc.IndexOf(strings[0]) == 0);
|
||||
}
|
||||
|
||||
public void TestSimpleInsert() {
|
||||
int index = 3;
|
||||
int oldCount = sc.Count;
|
||||
string before = sc[index - 1];
|
||||
string current = sc[index];
|
||||
string after = sc[index + 1];
|
||||
string newStr = "paco";
|
||||
|
||||
sc.Insert(index, newStr);
|
||||
|
||||
Assert(sc.Count == oldCount + 1);
|
||||
Assert(sc[index].Equals(newStr));
|
||||
Assert(sc[index-1].Equals(before));
|
||||
Assert(sc[index+1].Equals(current));
|
||||
Assert(sc[index+2].Equals(after));
|
||||
}
|
||||
|
||||
public void TestSimpleRemove() {
|
||||
int oldCount = sc.Count;
|
||||
sc.Remove(strings[0]);
|
||||
Assert(oldCount == sc.Count + 1);
|
||||
Assert(!sc.Contains(strings[0]));
|
||||
}
|
||||
|
||||
public void TestSimpleRemoveAt() {
|
||||
int index = 3;
|
||||
int oldCount = sc.Count;
|
||||
string after = sc[index+1];
|
||||
|
||||
sc.RemoveAt(index);
|
||||
Assert(oldCount == sc.Count + 1);
|
||||
Assert(sc[index].Equals(after));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
DIRS=System.CodeDom System.CodeDom.Compiler System.Net System.Net.Sockets System.Collections.Specialized
|
||||
DIRS=System.CodeDom System.CodeDom.Compiler System.Collections.Specialized
|
||||
|
||||
all:
|
||||
@echo "You must use 'make windows' or 'make unix'."
|
||||
|
||||
@@ -1,501 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace System.Collections
|
||||
{
|
||||
// do we really need to specify IEnumerable since ICollection extends it?
|
||||
public class BitArray : ICollection, IEnumerable, ICloneable
|
||||
{
|
||||
private Int32[] m_array;
|
||||
private int m_length;
|
||||
private int m_modCount = 0;
|
||||
|
||||
private static void clearJunk(Int32[] arr, int numbits)
|
||||
{
|
||||
int numjunkbits = 32 - (numbits%32);
|
||||
UInt32 mask = (~0U >> numjunkbits);
|
||||
arr[arr.Length - 1] &= (int)mask;
|
||||
}
|
||||
|
||||
private static int bitsToInts(int bits)
|
||||
{
|
||||
int retval = bits/32;
|
||||
if (bits % 32 != 0)
|
||||
retval++;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
private static int bitsToBytes(int bits)
|
||||
{
|
||||
int retval = bits/8;
|
||||
if (bits % 8 != 0)
|
||||
retval++;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
private void setBit(int bitIndex, bool value)
|
||||
{
|
||||
int index = bitIndex/32;
|
||||
int shift = bitIndex%32;
|
||||
|
||||
Int32 theBit = 1 << shift;
|
||||
|
||||
if(value)
|
||||
m_array[index] |= theBit;
|
||||
else
|
||||
m_array[index] &= ~theBit;
|
||||
|
||||
m_modCount++;
|
||||
}
|
||||
|
||||
private bool getBit(int bitIndex)
|
||||
{
|
||||
int index = bitIndex/32;
|
||||
int shift = bitIndex%32;
|
||||
|
||||
Int32 theBit = m_array[index] & (1 << shift);
|
||||
|
||||
return (theBit == 0) ? false : true;
|
||||
}
|
||||
|
||||
private byte getByte(int byteIndex)
|
||||
{
|
||||
int index = byteIndex/4;
|
||||
int shift = (byteIndex%4)*8;
|
||||
|
||||
Int32 theByte = m_array[index] & (0xff << shift);
|
||||
|
||||
return (byte)((theByte >> shift)&0xff);
|
||||
}
|
||||
|
||||
private void setByte(int byteIndex, byte value)
|
||||
{
|
||||
int index = byteIndex/4;
|
||||
int shift = (byteIndex%4)*8;
|
||||
|
||||
Int32 orig = m_array[index];
|
||||
|
||||
// clear the byte
|
||||
orig &= ~(0xff << shift);
|
||||
// or in the new byte
|
||||
orig |= value << shift;
|
||||
|
||||
m_array[index] = orig;
|
||||
|
||||
m_modCount++;
|
||||
}
|
||||
|
||||
/* --- Constructors --- */
|
||||
public BitArray(BitArray orig)
|
||||
{
|
||||
m_length = orig.m_length;
|
||||
|
||||
int numInts = bitsToInts(m_length);
|
||||
m_array = new Int32[numInts];
|
||||
Array.Copy(orig.m_array, m_array, numInts);
|
||||
}
|
||||
|
||||
public BitArray(bool[] bits)
|
||||
{
|
||||
m_length = bits.Length;
|
||||
|
||||
int numInts = bitsToInts(m_length);
|
||||
m_array = new Int32[numInts];
|
||||
for (int i=0; i < bits.Length; i++)
|
||||
setBit(i, bits[i]);
|
||||
}
|
||||
|
||||
public BitArray(byte[] bytes)
|
||||
{
|
||||
m_length = bytes.Length * 8;
|
||||
|
||||
m_array = new Int32[bitsToInts(m_length)];
|
||||
for (int i=0; i < bytes.Length; i++)
|
||||
setByte(i, bytes[i]);
|
||||
}
|
||||
|
||||
public BitArray(int capacity)
|
||||
{
|
||||
m_length = capacity;
|
||||
m_array = new Int32[bitsToInts(m_length)];
|
||||
}
|
||||
|
||||
public BitArray(int[] words)
|
||||
{
|
||||
int arrlen = words.Length;
|
||||
m_length = arrlen*32;
|
||||
m_array = new Int32[arrlen];
|
||||
Array.Copy(words, m_array, arrlen);
|
||||
}
|
||||
|
||||
public BitArray(int capacity, bool value) : this(capacity)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
// FIXME: Maybe you can create an array pre filled?
|
||||
for (int i = 0; i < m_array.Length; i++)
|
||||
m_array[i] = ~0;
|
||||
}
|
||||
}
|
||||
|
||||
private BitArray(Int32 [] array, int length)
|
||||
{
|
||||
m_array = array;
|
||||
m_length = length;
|
||||
}
|
||||
|
||||
|
||||
/* --- Public properties --- */
|
||||
public virtual int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_length;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool IsReadOnly
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool IsSynchronized
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return Get(index);
|
||||
}
|
||||
set
|
||||
{
|
||||
Set(index, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public virtual int Length
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_length;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
|
||||
int newLen = value;
|
||||
if (m_length != newLen)
|
||||
{
|
||||
int numints = bitsToInts(newLen);
|
||||
Int32 [] newArr = new Int32[numints];
|
||||
int copylen = (numints > m_array.Length ? m_array.Length : numints);
|
||||
Array.Copy(m_array, newArr, copylen);
|
||||
|
||||
// clear out the junk bits at the end:
|
||||
clearJunk(newArr, newLen);
|
||||
|
||||
// set the internal state
|
||||
m_array = newArr;
|
||||
m_length = newLen;
|
||||
m_modCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual object SyncRoot
|
||||
{
|
||||
get
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/* --- Public methods --- */
|
||||
public BitArray And(BitArray operand)
|
||||
{
|
||||
if (operand == null)
|
||||
throw new ArgumentNullException();
|
||||
if (operand.m_length != m_length)
|
||||
throw new ArgumentException();
|
||||
|
||||
Int32 [] newarr = new Int32[m_array.Length];
|
||||
for (int i=0; i < m_array.Length; i++)
|
||||
newarr[i] = m_array[i] & operand.m_array[i];
|
||||
|
||||
return new BitArray(newarr, m_length);
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
// FIXME: according to the doc, this should be a shallow copy.
|
||||
// But the MS implementation seems to do a deep copy.
|
||||
return new BitArray((Int32 [])m_array.Clone(), m_length);
|
||||
}
|
||||
|
||||
public void CopyTo(Array array, int index)
|
||||
{
|
||||
if (array == null)
|
||||
throw new ArgumentNullException();
|
||||
if (index < 0)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
|
||||
// FIXME: Throw ArgumentException if array is multidimensional
|
||||
if (index >= array.Length)
|
||||
throw new ArgumentException();
|
||||
|
||||
// in each case, check to make sure enough space in array
|
||||
|
||||
if (array is bool[])
|
||||
{
|
||||
if (index + m_length >= array.Length)
|
||||
throw new ArgumentException();
|
||||
|
||||
bool [] barray = (bool []) array;
|
||||
|
||||
// Copy the bits into the array
|
||||
for (int i = 0; i < m_length; i++)
|
||||
barray[index + i] = getBit(i);
|
||||
}
|
||||
else if (array is byte[])
|
||||
{
|
||||
int numbytes = bitsToBytes(m_length);
|
||||
if (index + numbytes >= array.Length)
|
||||
throw new ArgumentException();
|
||||
|
||||
byte [] barray = (byte []) array;
|
||||
// Copy the bytes into the array
|
||||
for (int i = 0; i < numbytes; i++)
|
||||
barray[index + i] = getByte(i);
|
||||
}
|
||||
else if (array is int[])
|
||||
{
|
||||
int numints = bitsToInts(m_length);
|
||||
if (index + numints >= array.Length)
|
||||
throw new ArgumentException();
|
||||
Array.Copy(m_array, 0, array, index, numints);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* All this code for nothing... Apparently, The MS BitArray doesn't
|
||||
* override Equals!
|
||||
*public override bool Equals(object obj)
|
||||
{
|
||||
// If it's not a BitArray, then it can't be equal to us.
|
||||
if (!(obj is BitArray))
|
||||
return false;
|
||||
|
||||
// If the references are equal, then clearly the instances are equal
|
||||
if (this == obj)
|
||||
return true;
|
||||
|
||||
// If its length is different, than it can't be equal.
|
||||
BitArray b = (BitArray) obj;
|
||||
if (m_length != b.m_length)
|
||||
return false;
|
||||
|
||||
|
||||
// Now compare the bits.
|
||||
// This is a little tricky, because if length doesn't divide 32,
|
||||
// then we shouldn't compare the unused bits in the last element
|
||||
// of m_array.
|
||||
|
||||
// Compare all full ints. If any differ, then we are not equal.
|
||||
int numints = m_length/32;
|
||||
for (int i = 0; i < numints; i++)
|
||||
{
|
||||
if (b.m_array[i] != m_array[i])
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compare the left over bits (if any)
|
||||
int extrabits = m_length%32;
|
||||
if (extrabits != 0)
|
||||
{
|
||||
// our mask is the "extrabits" least significant bits set to 1.
|
||||
UInt32 comparemask = ~0U >> (32 - extrabits);
|
||||
|
||||
// numints is rounded down, so it's safe to use as an index here,
|
||||
// as long as extrabits > 0.
|
||||
if ((b.m_array[numints] & comparemask)
|
||||
!= (m_array[numints] & comparemask))
|
||||
return false;
|
||||
}
|
||||
|
||||
// We passed through all the above, so we are equal.
|
||||
return true;
|
||||
|
||||
}
|
||||
* End comment out of Equals()
|
||||
*/
|
||||
|
||||
public bool Get(int index)
|
||||
{
|
||||
if (index < 0 || index >= m_length)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
return getBit(index);
|
||||
}
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
return new BitArrayEnumerator(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Since MS doesn't appear to override Equals/GetHashCode, we don't.
|
||||
*public override int GetHashCode()
|
||||
{
|
||||
// We could make this a constant time function
|
||||
// by just picking a constant number of bits, spread out
|
||||
// evenly across the entire array. For now, this will suffice.
|
||||
|
||||
int retval = m_length;
|
||||
|
||||
// Add in each array element, except for the leftover bits.
|
||||
int numints = m_length/32;
|
||||
for (int i = 0; i < numints; i++)
|
||||
retval += (int)m_array[i];
|
||||
|
||||
// That's enough. Adding in the leftover bits is tiring.
|
||||
|
||||
return retval;
|
||||
}
|
||||
* End comment out of GetHashCode()
|
||||
*/
|
||||
|
||||
public BitArray Not()
|
||||
{
|
||||
Int32 [] newarr = new Int32[m_array.Length];
|
||||
for (int i=0; i < m_array.Length; i++)
|
||||
newarr[i] = ~m_array[i];
|
||||
|
||||
return new BitArray(newarr, m_length);
|
||||
}
|
||||
|
||||
public BitArray Or(BitArray operand)
|
||||
{
|
||||
if (operand == null)
|
||||
throw new ArgumentNullException();
|
||||
if (operand.m_length != m_length)
|
||||
throw new ArgumentException();
|
||||
|
||||
Int32 [] newarr = new Int32[m_array.Length];
|
||||
for (int i=0; i < m_array.Length; i++)
|
||||
newarr[i] = m_array[i] | operand.m_array[i];
|
||||
|
||||
return new BitArray(newarr, m_length);
|
||||
}
|
||||
|
||||
public void Set(int index, bool value)
|
||||
{
|
||||
if (index < 0 || index >= m_length)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
setBit(index, value);
|
||||
}
|
||||
|
||||
public void SetAll(bool value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
for (int i = 0; i < m_array.Length; i++)
|
||||
m_array[i] = ~0;
|
||||
|
||||
// clear out the junk bits that we might have set
|
||||
clearJunk(m_array, m_length);
|
||||
}
|
||||
else
|
||||
Array.Clear(m_array, 0, m_array.Length);
|
||||
|
||||
|
||||
m_modCount++;
|
||||
}
|
||||
|
||||
public BitArray Xor(BitArray operand)
|
||||
{
|
||||
if (operand == null)
|
||||
throw new ArgumentNullException();
|
||||
if (operand.m_length != m_length)
|
||||
throw new ArgumentException();
|
||||
|
||||
Int32 [] newarr = new Int32[m_array.Length];
|
||||
for (int i=0; i < m_array.Length; i++)
|
||||
newarr[i] = m_array[i] ^ operand.m_array[i];
|
||||
|
||||
return new BitArray(newarr, m_length);
|
||||
}
|
||||
|
||||
~BitArray()
|
||||
{
|
||||
}
|
||||
|
||||
class BitArrayEnumerator : IEnumerator
|
||||
{
|
||||
BitArray m_bitArray;
|
||||
private bool m_current;
|
||||
private int m_index;
|
||||
private int m_max;
|
||||
private int m_modCount;
|
||||
|
||||
public BitArrayEnumerator(BitArray ba)
|
||||
{
|
||||
m_index = -1;
|
||||
m_bitArray = ba;
|
||||
m_max = ba.m_length;
|
||||
m_modCount = ba.m_modCount;
|
||||
}
|
||||
|
||||
public object Current
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_index < 0 || m_index >= m_max)
|
||||
throw new InvalidOperationException();
|
||||
return m_current;
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (m_modCount != m_bitArray.m_modCount)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
if (m_index + 1 >= m_max)
|
||||
return false;
|
||||
|
||||
m_index++;
|
||||
m_current = m_bitArray[m_index];
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
if (m_modCount != m_bitArray.m_modCount)
|
||||
throw new InvalidOperationException();
|
||||
m_index = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
//
|
||||
// System.Collections.CaseInsensitiveComparer
|
||||
//
|
||||
// Author:
|
||||
// Sergey Chaban ([email protected])
|
||||
//
|
||||
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
|
||||
|
||||
namespace System.Collections {
|
||||
|
||||
public class CaseInsensitiveComparer : IComparer {
|
||||
|
||||
private static CaseInsensitiveComparer singleton;
|
||||
|
||||
|
||||
// Class constructor
|
||||
|
||||
static CaseInsensitiveComparer ()
|
||||
{
|
||||
singleton=new CaseInsensitiveComparer ();
|
||||
}
|
||||
|
||||
|
||||
// Public instance constructor
|
||||
|
||||
public CaseInsensitiveComparer ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Public static properties
|
||||
//
|
||||
|
||||
public static CaseInsensitiveComparer Default {
|
||||
get {
|
||||
return singleton;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Instance methods
|
||||
//
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return "mono::System.Collections.CaseInsensitiveComparer";
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// IComparer
|
||||
//
|
||||
|
||||
public int Compare (object a, object b)
|
||||
{
|
||||
string str1 = a as string;
|
||||
string str2 = b as string;
|
||||
|
||||
|
||||
int res = 0;
|
||||
|
||||
if (str1 != null && str2 != null) {
|
||||
res = String.Compare (str1, str2, true);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // CaseInsensitiveComparer
|
||||
}
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
//
|
||||
// System.Collections.CaseInsensitiveHashCodeProvider
|
||||
//
|
||||
// Author:
|
||||
// Sergey Chaban ([email protected])
|
||||
//
|
||||
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
|
||||
|
||||
namespace System.Collections {
|
||||
|
||||
public class CaseInsensitiveHashCodeProvider : IHashCodeProvider {
|
||||
|
||||
private static CaseInsensitiveHashCodeProvider singleton;
|
||||
|
||||
|
||||
// Class constructor
|
||||
|
||||
static CaseInsensitiveHashCodeProvider ()
|
||||
{
|
||||
singleton=new CaseInsensitiveHashCodeProvider ();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Public instance constructor
|
||||
|
||||
public CaseInsensitiveHashCodeProvider ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Public static properties
|
||||
//
|
||||
|
||||
public static CaseInsensitiveHashCodeProvider Default {
|
||||
get {
|
||||
return singleton;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Instance methods
|
||||
//
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return "mono::System.Collections.CaseInsensitiveHashCodeProvider";
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// IHashCodeProvider
|
||||
//
|
||||
|
||||
public virtual int GetHashCode (object obj)
|
||||
{
|
||||
if (obj == null) {
|
||||
throw new ArgumentNullException ("obj is null");
|
||||
}
|
||||
|
||||
string str = obj as string;
|
||||
|
||||
if (str == null) {
|
||||
// FIXME:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int h = 0;
|
||||
char c;
|
||||
|
||||
if (str.Length > 0) {
|
||||
for (int i = 0;i<str.Length;i++) {
|
||||
c = str [i];
|
||||
|
||||
if (Char.IsLetter (c))
|
||||
c = Char.ToLower (c);
|
||||
|
||||
h = h * 31 + c;
|
||||
}
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
} // CaseInsensitiveHashCodeProvider
|
||||
}
|
||||
|
||||
@@ -1,41 +1,3 @@
|
||||
2001-07-23 Sergey Chaban <[email protected]>
|
||||
|
||||
* Hashtable.cs: Fixed bug in Clear(), the Count wasn't zeroed.
|
||||
From now, Clear() increases modification count.
|
||||
Fixed HCP bug in GetHash(object) - hcp.GetHashCode() was used
|
||||
instead of hcp.GetHashCode(key). This was resulted in the
|
||||
insanely long lookup times when HashCodeProvider was used to
|
||||
construct Hashtable. Added thread-safe wrapper.
|
||||
|
||||
2001-07-16 David Menestrina <[email protected]>
|
||||
|
||||
* BitArray.cs: Add
|
||||
* BitArrayTest.cs: Add
|
||||
|
||||
2001-07-18 Miguel de Icaza <[email protected]>
|
||||
|
||||
* IDictionary.cs (Collections): IDictionary implements ICollection
|
||||
as well. Thanks Sergey!
|
||||
|
||||
2001-07-18 Garrett Rooney <[email protected]>
|
||||
|
||||
* Stack.cs Removed unnecessary locking from many methods of
|
||||
SyncStack, removed SyncEnumerator because it was unnecessary,
|
||||
added a modCount member to Stack and Stack.Enumerator, to
|
||||
ensure that the Stack has not been modified out form under the
|
||||
Enumerator, and changed the Enumerator to use a reference to the
|
||||
stack rather than copying over the contents array.
|
||||
|
||||
2001-07-17 David Menestrina <[email protected]>
|
||||
|
||||
* Added implementation of BitArray.
|
||||
|
||||
2001-07-17 Miguel de Icaza <[email protected]>
|
||||
|
||||
* Hashtable.cs: Removed call to d.Count in the Hashtable
|
||||
constructor that takes an IDictionary as IDictionary does not
|
||||
provide a Count field.
|
||||
|
||||
2001-07-15 Sean MacIsaac <[email protected]>
|
||||
|
||||
* IDictionary.cs: Clear was clear.
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
//
|
||||
// System.Collections.Comparer
|
||||
//
|
||||
// Author:
|
||||
// Sergey Chaban ([email protected])
|
||||
//
|
||||
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
|
||||
|
||||
namespace System.Collections {
|
||||
|
||||
public sealed class Comparer : IComparer {
|
||||
|
||||
public static readonly Comparer Default;
|
||||
|
||||
|
||||
// Class constructor
|
||||
|
||||
static Comparer ()
|
||||
{
|
||||
Default=new Comparer ();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Public instance constructor
|
||||
|
||||
private Comparer ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
// IComparer
|
||||
|
||||
public int Compare (object a, object b)
|
||||
{
|
||||
int res=0;
|
||||
|
||||
if (a is IComparable) {
|
||||
res = (a as IComparable).CompareTo (b);
|
||||
} else if (b is IComparable) {
|
||||
res = (b as IComparable).CompareTo (a);
|
||||
} else {
|
||||
throw new ArgumentException ("Neither a nor b IComparable");
|
||||
}
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return "mono::System.Collections.Comparer";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,985 +0,0 @@
|
||||
//
|
||||
// System.Collections.Hashtable
|
||||
//
|
||||
// Author:
|
||||
// Sergey Chaban ([email protected])
|
||||
//
|
||||
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
|
||||
// TODO: 1. Interfaces to implement: ISerializable and IDeserializationCallback;
|
||||
// 2. Meaningfull error messages for all exceptions.
|
||||
// Probably we should use ResourceSet to translate
|
||||
// error codes to messages.
|
||||
|
||||
|
||||
namespace System.Collections {
|
||||
|
||||
public class Hashtable : IDictionary, ICollection,
|
||||
IEnumerable, ICloneable
|
||||
{
|
||||
|
||||
internal struct Slot {
|
||||
internal Object key;
|
||||
|
||||
internal Object value;
|
||||
|
||||
// Hashcode. Chains are also marked through this.
|
||||
internal int hashMix;
|
||||
}
|
||||
|
||||
//
|
||||
// Private data
|
||||
//
|
||||
|
||||
private readonly static int CHAIN_MARKER = ~Int32.MaxValue;
|
||||
private readonly static int ALLOC_GRAIN = 0x2F;
|
||||
|
||||
// Used as indicator for the removed parts of a chain.
|
||||
private readonly static Object REMOVED_MARKER = new Object ();
|
||||
|
||||
|
||||
private int inUse;
|
||||
private int modificationCount;
|
||||
private float loadFactor;
|
||||
private Slot [] table;
|
||||
private int threshold;
|
||||
|
||||
private IHashCodeProvider hcpRef;
|
||||
private IComparer comparerRef;
|
||||
|
||||
public static int [] primeTbl = {};
|
||||
|
||||
|
||||
// Class constructor
|
||||
|
||||
static Hashtable () {
|
||||
// NOTE: Precalculate primes table.
|
||||
// This precalculated table of primes is intended
|
||||
// to speed-up allocations/resize for relatively
|
||||
// small tables.
|
||||
// I'm not sure whether it's a good idea or not.
|
||||
// Also I am in doubt as for the quality of this
|
||||
// particular implementation, probably the increment
|
||||
// shouldn't be linear? Consider this as a hack
|
||||
// or as a placeholder for future improvements.
|
||||
int size = 0x2000/ALLOC_GRAIN;
|
||||
primeTbl = new int [size];
|
||||
for (int x = 53, i = 0;i<size;x+= ALLOC_GRAIN, i++) {
|
||||
primeTbl [i] = CalcPrime (x);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Constructors
|
||||
//
|
||||
|
||||
public Hashtable () : this (0, 1.0f) {}
|
||||
|
||||
|
||||
public Hashtable (int capacity, float loadFactor, IHashCodeProvider hcp, IComparer comparer) {
|
||||
if (capacity<0)
|
||||
throw new ArgumentOutOfRangeException ("negative capacity");
|
||||
|
||||
if (loadFactor<0.1 || loadFactor>1)
|
||||
throw new ArgumentOutOfRangeException ("load factor");
|
||||
|
||||
if (capacity == 0) ++capacity;
|
||||
this.loadFactor = 0.75f*loadFactor;
|
||||
int size = (int) (capacity/this.loadFactor);
|
||||
size = ToPrime (size);
|
||||
this.SetTable (new Slot [size]);
|
||||
|
||||
this.hcp = hcp;
|
||||
this.comparer = comparer;
|
||||
|
||||
this.inUse = 0;
|
||||
this.modificationCount = 0;
|
||||
|
||||
}
|
||||
|
||||
public Hashtable (int capacity, float loadFactor) :
|
||||
this (capacity, loadFactor, null, null)
|
||||
{
|
||||
}
|
||||
|
||||
public Hashtable (int capacity) : this (capacity, 1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
public Hashtable (int capacity,
|
||||
IHashCodeProvider hcp,
|
||||
IComparer comparer)
|
||||
: this (capacity, 1.0f, hcp, comparer)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public Hashtable (IDictionary d, float loadFactor,
|
||||
IHashCodeProvider hcp, IComparer comparer)
|
||||
: this (d!=null ? d.Count : 0,
|
||||
loadFactor, hcp, comparer)
|
||||
{
|
||||
|
||||
if (d == null)
|
||||
throw new ArgumentNullException ("dictionary");
|
||||
|
||||
IDictionaryEnumerator it = d.GetEnumerator ();
|
||||
while (it.MoveNext ()) {
|
||||
Add (it.Key, it.Value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Hashtable (IDictionary d, float loadFactor)
|
||||
: this (d, loadFactor, null, null)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public Hashtable (IDictionary d) : this (d, 1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
public Hashtable (IDictionary d, IHashCodeProvider hcp, IComparer comparer)
|
||||
: this (d, 1.0f, hcp, comparer)
|
||||
{
|
||||
}
|
||||
|
||||
public Hashtable (IHashCodeProvider hcp, IComparer comparer)
|
||||
: this (1, 1.0f, hcp, comparer)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Properties
|
||||
//
|
||||
|
||||
protected IComparer comparer {
|
||||
set {
|
||||
comparerRef = value;
|
||||
}
|
||||
get {
|
||||
return comparerRef;
|
||||
}
|
||||
}
|
||||
|
||||
protected IHashCodeProvider hcp {
|
||||
set {
|
||||
hcpRef = value;
|
||||
}
|
||||
get {
|
||||
return hcpRef;
|
||||
}
|
||||
}
|
||||
|
||||
// ICollection
|
||||
|
||||
public virtual int Count {
|
||||
get {
|
||||
return inUse;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool IsSynchronized {
|
||||
get {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Object SyncRoot {
|
||||
get {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// IDictionary
|
||||
|
||||
public virtual bool IsFixedSize {
|
||||
get {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public virtual bool IsReadOnly {
|
||||
get {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual ICollection Keys {
|
||||
get {
|
||||
return new HashKeys (this);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual ICollection Values {
|
||||
get {
|
||||
return new HashValues (this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public virtual Object this [Object key] {
|
||||
get {
|
||||
return GetImpl (key);
|
||||
}
|
||||
set {
|
||||
PutImpl (key, value, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Interface methods
|
||||
//
|
||||
|
||||
|
||||
// IEnumerable
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator ()
|
||||
{
|
||||
return new Enumerator (this, EnumeratorMode.KEY_MODE);
|
||||
}
|
||||
|
||||
|
||||
// ICollection
|
||||
public virtual void CopyTo (Array array, int arrayIndex)
|
||||
{
|
||||
IDictionaryEnumerator it = GetEnumerator ();
|
||||
int i = arrayIndex;
|
||||
|
||||
while (it.MoveNext ()) {
|
||||
array.SetValue (it.Entry, i++);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// IDictionary
|
||||
|
||||
public virtual void Add (Object key, Object value)
|
||||
{
|
||||
PutImpl (key, value, false);
|
||||
}
|
||||
|
||||
public virtual void Clear ()
|
||||
{
|
||||
for (int i = 0;i<table.Length;i++) {
|
||||
table [i].key = null;
|
||||
table [i].value = null;
|
||||
table [i].hashMix = 0;
|
||||
}
|
||||
|
||||
inUse = 0;
|
||||
modificationCount++;
|
||||
}
|
||||
|
||||
public virtual bool Contains (Object key)
|
||||
{
|
||||
return (Find (key) >= 0);
|
||||
}
|
||||
|
||||
public virtual IDictionaryEnumerator GetEnumerator ()
|
||||
{
|
||||
return new Enumerator (this, EnumeratorMode.KEY_MODE);
|
||||
}
|
||||
|
||||
public virtual void Remove (Object key)
|
||||
{
|
||||
int i = Find (key);
|
||||
Slot [] table = this.table;
|
||||
if (i >= 0) {
|
||||
int h = table [i].hashMix;
|
||||
h &= CHAIN_MARKER;
|
||||
table [i].hashMix = h;
|
||||
table [i].key = (h != 0)
|
||||
? REMOVED_MARKER
|
||||
: null;
|
||||
table [i].value = null;
|
||||
--inUse;
|
||||
++modificationCount;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public virtual bool ContainsKey (object key)
|
||||
{
|
||||
return Contains (key);
|
||||
}
|
||||
|
||||
public virtual bool ContainsValue (object value)
|
||||
{
|
||||
int size = this.table.Length;
|
||||
Slot [] table = this.table;
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
Slot entry = table [i];
|
||||
if (entry.key != null && entry.key!= REMOVED_MARKER
|
||||
&& value.Equals (entry.value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// ICloneable
|
||||
|
||||
public virtual object Clone ()
|
||||
{
|
||||
Hashtable ht = new Hashtable (Count, hcp, comparer);
|
||||
ht.modificationCount = this.modificationCount;
|
||||
ht.inUse = this.inUse;
|
||||
ht.AdjustThreshold ();
|
||||
|
||||
// FIXME: maybe it's faster to simply
|
||||
// copy the back-end array?
|
||||
|
||||
IDictionaryEnumerator it = GetEnumerator ();
|
||||
while (it.MoveNext ()) {
|
||||
ht [it.Key] = it.Value;
|
||||
}
|
||||
|
||||
return ht;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TODO: public virtual void GetObjectData (SerializationInfo info, StreamingContext context) {}
|
||||
// TODO: public virtual void OnDeserialization (object sender);
|
||||
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
// FIXME: What's it supposed to do?
|
||||
// Maybe print out some internals here? Anyway.
|
||||
return "mono::System.Collections.Hashtable";
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns a synchronized (thread-safe)
|
||||
/// wrapper for the Hashtable.
|
||||
/// </summary>
|
||||
public static Hashtable Synchronized (Hashtable table)
|
||||
{
|
||||
return new SynchedHashtable (table);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Protected instance methods
|
||||
//
|
||||
|
||||
/// <summary>Returns the hash code for the specified key.</summary>
|
||||
protected virtual int GetHash (Object key)
|
||||
{
|
||||
IHashCodeProvider hcp = this.hcp;
|
||||
return (hcp!= null)
|
||||
? hcp.GetHashCode (key)
|
||||
: key.GetHashCode ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares a specific Object with a specific key
|
||||
/// in the Hashtable.
|
||||
/// </summary>
|
||||
protected virtual bool KeyEquals (Object item, Object key)
|
||||
{
|
||||
IComparer c = this.comparer;
|
||||
if (c!= null)
|
||||
return (c.Compare (item, key) == 0);
|
||||
else
|
||||
return item.Equals (key);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Private instance methods
|
||||
//
|
||||
|
||||
private void AdjustThreshold ()
|
||||
{
|
||||
int size = table.Length;
|
||||
|
||||
threshold = (int) (size*loadFactor);
|
||||
if (this.threshold >= size)
|
||||
threshold = size-1;
|
||||
}
|
||||
|
||||
private void SetTable (Slot [] table)
|
||||
{
|
||||
if (table == null)
|
||||
throw new ArgumentNullException ("table");
|
||||
|
||||
this.table = table;
|
||||
AdjustThreshold ();
|
||||
}
|
||||
|
||||
private Object GetImpl (Object key)
|
||||
{
|
||||
int i = Find (key);
|
||||
|
||||
if (i >= 0)
|
||||
return table [i].value;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private int Find (Object key)
|
||||
{
|
||||
if (key == null)
|
||||
throw new ArgumentNullException ("null key");
|
||||
|
||||
uint size = (uint) this.table.Length;
|
||||
int h = this.GetHash (key) & Int32.MaxValue;
|
||||
uint spot = (uint)h;
|
||||
uint step = (uint) ((h >> 5)+1) % (size-1)+1;
|
||||
Slot[] table = this.table;
|
||||
|
||||
for (int i = 0; i < size;i++) {
|
||||
int indx = (int) (spot % size);
|
||||
Slot entry = table [indx];
|
||||
Object k = entry.key;
|
||||
if (k == null)
|
||||
return -1;
|
||||
if ((entry.hashMix & Int32.MaxValue) == h
|
||||
&& this.KeyEquals (key, k)) {
|
||||
return indx;
|
||||
}
|
||||
|
||||
if ((entry.hashMix & CHAIN_MARKER) == 0)
|
||||
return -1;
|
||||
|
||||
spot+= step;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
private void Rehash ()
|
||||
{
|
||||
int oldSize = this.table.Length;
|
||||
|
||||
// From the SDK docs:
|
||||
// Hashtable is automatically increased
|
||||
// to the smallest prime number that is larger
|
||||
// than twice the current number of Hashtable buckets
|
||||
uint newSize = (uint)ToPrime ((oldSize<<1)|1);
|
||||
|
||||
|
||||
Slot [] newTable = new Slot [newSize];
|
||||
Slot [] table = this.table;
|
||||
|
||||
for (int i = 0;i<oldSize;i++) {
|
||||
Slot s = table [i];
|
||||
if (s.key!= null) {
|
||||
int h = s.hashMix & Int32.MaxValue;
|
||||
uint spot = (uint)h;
|
||||
uint step = ((uint) (h>>5)+1)% (newSize-1)+1;
|
||||
for (uint j = spot%newSize;;spot+= step, j = spot%newSize) {
|
||||
// No check for REMOVED_MARKER here,
|
||||
// because the table is just allocated.
|
||||
if (newTable [j].key == null) {
|
||||
newTable [j].key = s.key;
|
||||
newTable [j].value = s.value;
|
||||
newTable [j].hashMix |= h;
|
||||
break;
|
||||
} else {
|
||||
newTable [j].hashMix |= CHAIN_MARKER;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
++this.modificationCount;
|
||||
|
||||
this.SetTable (newTable);
|
||||
}
|
||||
|
||||
|
||||
private void PutImpl (Object key, Object value, bool overwrite)
|
||||
{
|
||||
if (key == null)
|
||||
throw new ArgumentNullException ("null key");
|
||||
|
||||
uint size = (uint)this.table.Length;
|
||||
if (this.inUse >= this.threshold) {
|
||||
this.Rehash ();
|
||||
size = (uint)this.table.Length;
|
||||
}
|
||||
|
||||
int h = this.GetHash (key) & Int32.MaxValue;
|
||||
uint spot = (uint)h;
|
||||
uint step = (uint) ((spot>>5)+1)% (size-1)+1;
|
||||
Slot [] table = this.table;
|
||||
Slot entry;
|
||||
|
||||
int freeIndx = -1;
|
||||
for (int i = 0; i < size; i++) {
|
||||
int indx = (int) (spot % size);
|
||||
entry = table [indx];
|
||||
|
||||
if (freeIndx == -1
|
||||
&& entry.key == REMOVED_MARKER
|
||||
&& (entry.hashMix & CHAIN_MARKER)!= 0)
|
||||
freeIndx = indx;
|
||||
|
||||
if (entry.key == null ||
|
||||
(entry.key == REMOVED_MARKER
|
||||
&& (entry.hashMix & CHAIN_MARKER)!= 0)) {
|
||||
|
||||
if (freeIndx == -1)
|
||||
freeIndx = indx;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((entry.hashMix & Int32.MaxValue) == h && KeyEquals (key, entry.key)) {
|
||||
if (overwrite) {
|
||||
table [indx].value = value;
|
||||
++this.modificationCount;
|
||||
} else {
|
||||
// Handle Add ():
|
||||
// An entry with the same key already exists in the Hashtable.
|
||||
throw new ArgumentException ("Key duplication");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (freeIndx == -1) {
|
||||
table [indx].hashMix |= CHAIN_MARKER;
|
||||
}
|
||||
|
||||
spot+= step;
|
||||
|
||||
}
|
||||
|
||||
if (freeIndx!= -1) {
|
||||
table [freeIndx].key = key;
|
||||
table [freeIndx].value = value;
|
||||
table [freeIndx].hashMix |= h;
|
||||
|
||||
++this.inUse;
|
||||
++this.modificationCount;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void CopyToArray (Array arr, int i,
|
||||
EnumeratorMode mode)
|
||||
{
|
||||
IEnumerator it = new Enumerator (this, mode);
|
||||
|
||||
while (it.MoveNext ()) {
|
||||
arr.SetValue (it.Current, i++);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Private static methods
|
||||
//
|
||||
private static bool TestPrime (int x)
|
||||
{
|
||||
if ((x & 1) != 0) {
|
||||
for (int n = 3; n< (int)Math.Sqrt (x); n += 2) {
|
||||
if ((x % n) == 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// There is only one even prime - 2.
|
||||
return (x == 2);
|
||||
}
|
||||
|
||||
private static int CalcPrime (int x)
|
||||
{
|
||||
for (int i = (x & (~1))-1; i< Int32.MaxValue; i += 2) {
|
||||
if (TestPrime (i)) return i;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
private static int ToPrime (int x)
|
||||
{
|
||||
for (int i = x/ALLOC_GRAIN; i < primeTbl.Length; i++) {
|
||||
if (x <= primeTbl [i])
|
||||
return primeTbl [i];
|
||||
}
|
||||
return CalcPrime (x);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Inner classes
|
||||
//
|
||||
|
||||
public enum EnumeratorMode : int {KEY_MODE = 0, VALUE_MODE};
|
||||
|
||||
protected sealed class Enumerator : IDictionaryEnumerator, IEnumerator {
|
||||
|
||||
private Hashtable host;
|
||||
private int stamp;
|
||||
private int pos;
|
||||
private int size;
|
||||
private EnumeratorMode mode;
|
||||
|
||||
private Object currentKey;
|
||||
private Object currentValue;
|
||||
|
||||
private readonly static string xstr = "Hashtable.Enumerator: snapshot out of sync.";
|
||||
|
||||
public Enumerator (Hashtable host, EnumeratorMode mode) {
|
||||
this.host = host;
|
||||
stamp = host.modificationCount;
|
||||
size = host.table.Length;
|
||||
this.mode = mode;
|
||||
Reset ();
|
||||
}
|
||||
|
||||
public Enumerator (Hashtable host)
|
||||
: this (host, EnumeratorMode.KEY_MODE) {}
|
||||
|
||||
|
||||
private void FailFast ()
|
||||
{
|
||||
if (host.modificationCount!= stamp) {
|
||||
throw new InvalidOperationException (xstr);
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset ()
|
||||
{
|
||||
FailFast ();
|
||||
|
||||
pos = -1;
|
||||
currentKey = null;
|
||||
currentValue = null;
|
||||
}
|
||||
|
||||
public bool MoveNext ()
|
||||
{
|
||||
FailFast ();
|
||||
|
||||
if (pos < size) {
|
||||
while (++pos < size) {
|
||||
Slot entry = host.table [pos];
|
||||
|
||||
if (entry.key != null && entry.key != REMOVED_MARKER) {
|
||||
currentKey = entry.key;
|
||||
currentValue = entry.value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentKey = null;
|
||||
currentValue = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public DictionaryEntry Entry
|
||||
{
|
||||
get {
|
||||
FailFast ();
|
||||
return new DictionaryEntry (currentKey, currentValue);
|
||||
}
|
||||
}
|
||||
|
||||
public Object Key {
|
||||
get {
|
||||
FailFast ();
|
||||
return currentKey;
|
||||
}
|
||||
}
|
||||
|
||||
public Object Value {
|
||||
get {
|
||||
FailFast ();
|
||||
return currentValue;
|
||||
}
|
||||
}
|
||||
|
||||
public Object Current {
|
||||
get {
|
||||
FailFast ();
|
||||
return (mode == EnumeratorMode.KEY_MODE)
|
||||
? currentKey
|
||||
: currentValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected class HashKeys : ICollection, IEnumerable {
|
||||
|
||||
private Hashtable host;
|
||||
private int count;
|
||||
|
||||
public HashKeys (Hashtable host) {
|
||||
if (host == null)
|
||||
throw new ArgumentNullException ();
|
||||
|
||||
this.host = host;
|
||||
this.count = host.Count;
|
||||
}
|
||||
|
||||
// ICollection
|
||||
|
||||
public virtual int Count {
|
||||
get {
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool IsSynchronized {
|
||||
get {
|
||||
return host.IsSynchronized;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Object SyncRoot {
|
||||
get {return host.SyncRoot;}
|
||||
}
|
||||
|
||||
public virtual void CopyTo (Array array, int arrayIndex)
|
||||
{
|
||||
host.CopyToArray (array, arrayIndex, EnumeratorMode.KEY_MODE);
|
||||
}
|
||||
|
||||
// IEnumerable
|
||||
|
||||
public virtual IEnumerator GetEnumerator ()
|
||||
{
|
||||
return new Hashtable.Enumerator (host, EnumeratorMode.KEY_MODE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected class HashValues : ICollection, IEnumerable {
|
||||
|
||||
private Hashtable host;
|
||||
private int count;
|
||||
|
||||
public HashValues (Hashtable host) {
|
||||
if (host == null)
|
||||
throw new ArgumentNullException ();
|
||||
|
||||
this.host = host;
|
||||
this.count = host.Count;
|
||||
}
|
||||
|
||||
// ICollection
|
||||
|
||||
public virtual int Count {
|
||||
get {
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool IsSynchronized {
|
||||
get {
|
||||
return host.IsSynchronized;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Object SyncRoot {
|
||||
get {
|
||||
return host.SyncRoot;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void CopyTo (Array array, int arrayIndex)
|
||||
{
|
||||
host.CopyToArray (array, arrayIndex, EnumeratorMode.VALUE_MODE);
|
||||
}
|
||||
|
||||
// IEnumerable
|
||||
|
||||
public virtual IEnumerator GetEnumerator ()
|
||||
{
|
||||
return new Hashtable.Enumerator (host, EnumeratorMode.VALUE_MODE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected class SynchedHashtable : Hashtable, IEnumerable {
|
||||
|
||||
private Hashtable host;
|
||||
|
||||
public SynchedHashtable (Hashtable host) {
|
||||
if (host == null)
|
||||
throw new ArgumentNullException ();
|
||||
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
// ICollection
|
||||
|
||||
public override int Count {
|
||||
get {
|
||||
return host.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsSynchronized {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override Object SyncRoot {
|
||||
get {
|
||||
return host.SyncRoot;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// IDictionary
|
||||
|
||||
public override bool IsFixedSize {
|
||||
get {
|
||||
return host.IsFixedSize;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override bool IsReadOnly {
|
||||
get {
|
||||
return host.IsReadOnly;
|
||||
}
|
||||
}
|
||||
|
||||
public override ICollection Keys {
|
||||
get {
|
||||
ICollection keys = null;
|
||||
lock (host.SyncRoot) {
|
||||
keys = host.Keys;
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
|
||||
public override ICollection Values {
|
||||
get {
|
||||
ICollection vals = null;
|
||||
lock (host.SyncRoot) {
|
||||
vals = host.Values;
|
||||
}
|
||||
return vals;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override Object this [Object key] {
|
||||
get {
|
||||
return host.GetImpl (key);
|
||||
}
|
||||
set {
|
||||
lock (host.SyncRoot) {
|
||||
host.PutImpl (key, value, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IEnumerable
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator ()
|
||||
{
|
||||
return new Enumerator (host, EnumeratorMode.KEY_MODE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ICollection
|
||||
|
||||
public override void CopyTo (Array array, int arrayIndex)
|
||||
{
|
||||
host.CopyTo (array, arrayIndex);
|
||||
}
|
||||
|
||||
|
||||
// IDictionary
|
||||
|
||||
public override void Add (Object key, Object value)
|
||||
{
|
||||
lock (host.SyncRoot) {
|
||||
host.PutImpl (key, value, false);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Clear ()
|
||||
{
|
||||
lock (host.SyncRoot) {
|
||||
host.Clear ();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Contains (Object key)
|
||||
{
|
||||
return (host.Find (key) >= 0);
|
||||
}
|
||||
|
||||
public override IDictionaryEnumerator GetEnumerator ()
|
||||
{
|
||||
return new Enumerator (host, EnumeratorMode.KEY_MODE);
|
||||
}
|
||||
|
||||
public override void Remove (Object key)
|
||||
{
|
||||
lock (host.SyncRoot) {
|
||||
host.Remove (key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override bool ContainsKey (object key)
|
||||
{
|
||||
return host.Contains (key);
|
||||
}
|
||||
|
||||
public override bool ContainsValue (object value)
|
||||
{
|
||||
return host.ContainsValue (value);
|
||||
}
|
||||
|
||||
|
||||
// ICloneable
|
||||
|
||||
public override object Clone ()
|
||||
{
|
||||
return (host.Clone () as Hashtable);
|
||||
}
|
||||
|
||||
} // SynchedHashtable
|
||||
|
||||
|
||||
} // Hashtable
|
||||
|
||||
}
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
// TODO: add tests for Comparer and HashCodeProvider
|
||||
|
||||
|
||||
// NOTE: add MCS prefix to Hashtable.cs to use this test.
|
||||
|
||||
|
||||
using System;
|
||||
using MCS.System.Collections;
|
||||
using System.Collections;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
|
||||
|
||||
namespace Testsuite.System.Collections {
|
||||
|
||||
|
||||
/// <summary>Hashtable test.</summary>
|
||||
public class HashtableTest {
|
||||
public static ITest Suite {
|
||||
get {
|
||||
TestSuite suite= new TestSuite("All Hashtable Tests");
|
||||
suite.AddTest(BasicOperationsTest.Suite);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public class BasicOperationsTest : TestCase {
|
||||
|
||||
protected MCS.System.Collections.Hashtable ht;
|
||||
private static Random rnd;
|
||||
|
||||
public BasicOperationsTest(String name) : base(name) {}
|
||||
|
||||
protected override void SetUp() {
|
||||
ht=new MCS.System.Collections.Hashtable();
|
||||
rnd=new Random();
|
||||
}
|
||||
|
||||
public static ITest Suite {
|
||||
get {
|
||||
return new TestSuite(typeof(BasicOperationsTest));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void SetDefaultData() {
|
||||
ht.Clear();
|
||||
ht.Add("k1","another");
|
||||
ht.Add("k2","yet");
|
||||
ht.Add("k3","hashtable");
|
||||
}
|
||||
|
||||
|
||||
public void TestAddRemoveClear() {
|
||||
ht.Clear();
|
||||
Assert(ht.Count==0);
|
||||
|
||||
SetDefaultData();
|
||||
Assert(ht.Count==3);
|
||||
|
||||
bool thrown=false;
|
||||
try {
|
||||
ht.Add("k2","cool");
|
||||
} catch (ArgumentException) {thrown=true;}
|
||||
Assert("Must throw ArgumentException!",thrown);
|
||||
|
||||
ht["k2"]="cool";
|
||||
Assert(ht.Count==3);
|
||||
Assert(ht["k2"].Equals("cool"));
|
||||
|
||||
}
|
||||
|
||||
public void TestCopyTo() {
|
||||
SetDefaultData();
|
||||
Object[] entries=new Object[ht.Count];
|
||||
ht.CopyTo(entries,0);
|
||||
Assert("Not an entry.",entries[0] is DictionaryEntry);
|
||||
}
|
||||
|
||||
|
||||
public void TestUnderHeavyLoad() {
|
||||
Console.WriteLine("Testing "+ht);
|
||||
ht.Clear();
|
||||
int max=100000;
|
||||
String[] cache=new String[max*2];
|
||||
int n=0;
|
||||
|
||||
for (int i=0;i<max;i++) {
|
||||
int id=rnd.Next()&0xFFFF;
|
||||
String key=""+id+"-key-"+id;
|
||||
String val="value-"+id;
|
||||
if (ht[key]==null) {
|
||||
ht[key]=val;
|
||||
cache[n]=key;
|
||||
cache[n+max]=val;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
Assert(ht.Count==n);
|
||||
|
||||
for (int i=0;i<n;i++) {
|
||||
String key=cache[i];
|
||||
String val=ht[key] as String;
|
||||
String err="ht[\""+key+"\"]=\""+val+
|
||||
"\", expected \""+cache[i+max]+"\"";
|
||||
Assert(err,val!=null && val.Equals(cache[i+max]));
|
||||
}
|
||||
|
||||
int r1=(n/3);
|
||||
int r2=r1+(n/5);
|
||||
|
||||
for (int i=r1;i<r2;i++) {
|
||||
ht.Remove(cache[i]);
|
||||
}
|
||||
|
||||
|
||||
for (int i=0;i<n;i++) {
|
||||
if (i>=r1 && i<r2) {
|
||||
Assert(ht[cache[i]]==null);
|
||||
} else {
|
||||
String key=cache[i];
|
||||
String val=ht[key] as String;
|
||||
String err="ht[\""+key+"\"]=\""+val+
|
||||
"\", expected \""+cache[i+max]+"\"";
|
||||
Assert(err,val!=null && val.Equals(cache[i+max]));
|
||||
}
|
||||
}
|
||||
|
||||
ICollection keys=ht.Keys;
|
||||
int nKeys=0;
|
||||
foreach (Object key in keys) {
|
||||
Assert((key as String) != null);
|
||||
nKeys++;
|
||||
}
|
||||
Assert(nKeys==ht.Count);
|
||||
|
||||
|
||||
ICollection vals=ht.Values;
|
||||
int nVals=0;
|
||||
foreach (Object val in vals) {
|
||||
Assert((val as String) != null);
|
||||
nVals++;
|
||||
}
|
||||
Assert(nVals==ht.Count);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ using System;
|
||||
|
||||
namespace System.Collections {
|
||||
|
||||
public interface IDictionary : ICollection {
|
||||
public interface IDictionary {
|
||||
// properties
|
||||
|
||||
bool IsFixedSize { get; }
|
||||
@@ -33,7 +33,7 @@ namespace System.Collections {
|
||||
|
||||
bool Contains (object key);
|
||||
|
||||
new IDictionaryEnumerator GetEnumerator ();
|
||||
IDictionaryEnumerator GetEnumerator ();
|
||||
|
||||
void Remove (object key);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
||||
//
|
||||
// System.Collections.IHashCodeProvider
|
||||
// System.Collections.IDictionary
|
||||
//
|
||||
// Author:
|
||||
// Vladimir Vukicevic ([email protected])
|
||||
|
||||
@@ -1,864 +0,0 @@
|
||||
//
|
||||
// System.Collections.SortedList
|
||||
//
|
||||
// Author:
|
||||
// Sergey Chaban ([email protected])
|
||||
//
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
|
||||
namespace System.Collections {
|
||||
|
||||
/// <summary>
|
||||
/// Represents a collection of associated keys and values
|
||||
/// that are sorted by the keys and are accessible by key
|
||||
/// and by index.
|
||||
/// </summary>
|
||||
public class SortedList : IDictionary, ICollection,
|
||||
IEnumerable, ICloneable {
|
||||
|
||||
|
||||
internal struct Slot {
|
||||
internal Object key;
|
||||
internal Object value;
|
||||
}
|
||||
|
||||
private readonly static int INITIAL_SIZE = 16;
|
||||
|
||||
public enum EnumeratorMode : int {KEY_MODE = 0, VALUE_MODE}
|
||||
|
||||
private int inUse;
|
||||
private int modificationCount;
|
||||
private Slot[] table;
|
||||
private IComparer comparer;
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Constructors
|
||||
//
|
||||
public SortedList () : this (INITIAL_SIZE)
|
||||
{
|
||||
}
|
||||
|
||||
public SortedList (int initialCapacity)
|
||||
: this (null, initialCapacity)
|
||||
{
|
||||
}
|
||||
|
||||
public SortedList (IComparer comparer, int initialCapacity)
|
||||
{
|
||||
this.comparer = comparer;
|
||||
InitTable (initialCapacity);
|
||||
}
|
||||
|
||||
public SortedList (IComparer comparer)
|
||||
: this (comparer, 0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public SortedList (IDictionary d) : this (d, null)
|
||||
{
|
||||
}
|
||||
|
||||
public SortedList (IDictionary d, IComparer comparer)
|
||||
{
|
||||
if (d == null)
|
||||
throw new ArgumentNullException ("dictionary");
|
||||
|
||||
InitTable (d.Count);
|
||||
this.comparer = comparer;
|
||||
|
||||
IDictionaryEnumerator it = d.GetEnumerator ();
|
||||
while (it.MoveNext ()) {
|
||||
if (it.Key is IComparable) {
|
||||
Add (it.Key, it.Value);
|
||||
} else {
|
||||
throw new InvalidCastException("!IComparable");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Properties
|
||||
//
|
||||
|
||||
|
||||
// ICollection
|
||||
|
||||
public virtual int Count {
|
||||
get {
|
||||
return inUse;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool IsSynchronized {
|
||||
get {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Object SyncRoot {
|
||||
get {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// IDictionary
|
||||
|
||||
public virtual bool IsFixedSize {
|
||||
get {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public virtual bool IsReadOnly {
|
||||
get {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual ICollection Keys {
|
||||
get {
|
||||
return new ListKeys (this);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual ICollection Values {
|
||||
get {
|
||||
return new ListValues (this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public virtual Object this [Object key] {
|
||||
get {
|
||||
return GetImpl (key);
|
||||
}
|
||||
set {
|
||||
PutImpl (key, value, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public virtual int Capacity {
|
||||
get {
|
||||
return table.Length;
|
||||
}
|
||||
set {
|
||||
Slot [] table = this.table;
|
||||
int current = table.Length;
|
||||
|
||||
if (inUse > value)
|
||||
throw new ArgumentOutOfRangeException("capacity too small");
|
||||
|
||||
if (value > current) {
|
||||
Slot [] newTable = new Slot [value];
|
||||
Array.Copy (table, newTable, current);
|
||||
this.table = newTable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Public instance methods.
|
||||
//
|
||||
|
||||
|
||||
// IEnumerable
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator ()
|
||||
{
|
||||
return new Enumerator (this, EnumeratorMode.KEY_MODE);
|
||||
}
|
||||
|
||||
|
||||
// IDictionary
|
||||
|
||||
public virtual void Add (object key, object value)
|
||||
{
|
||||
PutImpl (key, value, false);
|
||||
}
|
||||
|
||||
|
||||
public virtual void Clear ()
|
||||
{
|
||||
this.table = new Slot [Capacity];
|
||||
inUse = 0;
|
||||
modificationCount++;
|
||||
}
|
||||
|
||||
public virtual bool Contains (object key)
|
||||
{
|
||||
return (Find (key) >= 0);
|
||||
}
|
||||
|
||||
|
||||
public virtual IDictionaryEnumerator GetEnumerator ()
|
||||
{
|
||||
return new Enumerator (this, EnumeratorMode.KEY_MODE);
|
||||
}
|
||||
|
||||
public virtual void Remove (object key)
|
||||
{
|
||||
int i = IndexOfKey (key);
|
||||
if (i >= 0) RemoveAt (i);
|
||||
}
|
||||
|
||||
|
||||
// ICollection
|
||||
|
||||
public virtual void CopyTo (Array array, int arrayIndex)
|
||||
{
|
||||
IDictionaryEnumerator it = GetEnumerator ();
|
||||
int i = arrayIndex;
|
||||
|
||||
while (it.MoveNext ()) {
|
||||
array.SetValue (it.Entry, i++);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ICloneable
|
||||
|
||||
public virtual object Clone ()
|
||||
{
|
||||
SortedList sl = new SortedList (this, comparer);
|
||||
sl.modificationCount = this.modificationCount;
|
||||
return sl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// SortedList
|
||||
//
|
||||
|
||||
public virtual IList GetKeyList ()
|
||||
{
|
||||
return new ListKeys (this);
|
||||
}
|
||||
|
||||
|
||||
public virtual IList GetValueList ()
|
||||
{
|
||||
return new ListValues (this);
|
||||
}
|
||||
|
||||
|
||||
public virtual void RemoveAt (int index)
|
||||
{
|
||||
Slot [] table = this.table;
|
||||
int cnt = Count;
|
||||
if (index >= 0 && index < cnt) {
|
||||
if (index != cnt - 1) {
|
||||
Array.Copy (table, index+1, table, index, cnt-1);
|
||||
} else {
|
||||
table [index].key = null;
|
||||
table [index].value = null;
|
||||
}
|
||||
--inUse;
|
||||
++modificationCount;
|
||||
} else {
|
||||
throw new ArgumentOutOfRangeException("index out of range");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public virtual int IndexOfKey (object key)
|
||||
{
|
||||
int indx = Find (key);
|
||||
return (indx | (indx >> 31));
|
||||
}
|
||||
|
||||
|
||||
public virtual int IndexOfValue (object value)
|
||||
{
|
||||
Slot [] table = this.table;
|
||||
int len = table.Length;
|
||||
|
||||
for (int i=0; i < len; i++) {
|
||||
if (table[i].value.Equals (value)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
public virtual bool ContainsKey (object key)
|
||||
{
|
||||
return Contains (key);
|
||||
}
|
||||
|
||||
|
||||
public virtual bool ContainsValue (object value)
|
||||
{
|
||||
return IndexOfValue (value) >= 0;
|
||||
}
|
||||
|
||||
|
||||
public virtual object GetByIndex (int index)
|
||||
{
|
||||
if (index >= 0 && index < Count) {
|
||||
return table [index].value;
|
||||
} else {
|
||||
throw new ArgumentOutOfRangeException("index out of range");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public virtual void SetByIndex (int index, object value)
|
||||
{
|
||||
if (index >= 0 && index < Count) {
|
||||
table [index].value = value;
|
||||
} else {
|
||||
throw new ArgumentOutOfRangeException("index out of range");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public virtual object GetKey (int index)
|
||||
{
|
||||
if (index >= 0 && index < Count) {
|
||||
return table [index].key;
|
||||
} else {
|
||||
throw new ArgumentOutOfRangeException("index out of range");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public virtual void TrimToSize ()
|
||||
{
|
||||
// From Beta2:
|
||||
// Trimming an empty SortedList sets the capacity
|
||||
// of the SortedList to the default capacity,
|
||||
// not zero.
|
||||
if (Count == 0) Resize (INITIAL_SIZE, false);
|
||||
else Resize (Count, true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return "mono::System.Collections.SortedList";
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Private methods
|
||||
//
|
||||
|
||||
|
||||
private void Resize (int n, bool copy)
|
||||
{
|
||||
Slot [] table = this.table;
|
||||
Slot [] newTable = new Slot [n];
|
||||
if (copy) Array.Copy (table, 0, newTable, 0, n);
|
||||
this.table = newTable;
|
||||
}
|
||||
|
||||
|
||||
private void EnsureCapacity (int n, int free)
|
||||
{
|
||||
Slot [] table = this.table;
|
||||
Slot [] newTable = null;
|
||||
int cap = Capacity;
|
||||
bool gap = (free >=0 && free < Count);
|
||||
|
||||
if (n > cap) {
|
||||
newTable = new Slot [n << 1];
|
||||
}
|
||||
|
||||
if (newTable != null) {
|
||||
if (gap) {
|
||||
int copyLen = free;
|
||||
if (copyLen > 0) {
|
||||
Array.Copy (table, 0, newTable, 0, copyLen);
|
||||
}
|
||||
copyLen = Count - free;
|
||||
if (copyLen > 0) {
|
||||
Array.Copy (table, free, newTable, free+1, copyLen);
|
||||
}
|
||||
} else {
|
||||
// Just a resizing, copy the entire table.
|
||||
Array.Copy (table, newTable, Count);
|
||||
}
|
||||
this.table = newTable;
|
||||
} else if (gap) {
|
||||
Array.Copy (table, free, table, free+1, Count - free);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void PutImpl (object key, object value, bool overwrite)
|
||||
{
|
||||
if (key == null)
|
||||
throw new ArgumentNullException ("null key");
|
||||
|
||||
Slot [] table = this.table;
|
||||
int freeIndx = Find (key);
|
||||
|
||||
|
||||
if (freeIndx >= 0) {
|
||||
if (!overwrite)
|
||||
throw new ArgumentException("element already exists");
|
||||
|
||||
table [freeIndx].value = value;
|
||||
return;
|
||||
}
|
||||
|
||||
freeIndx = ~freeIndx;
|
||||
|
||||
if (freeIndx > Capacity + 1)
|
||||
throw new Exception ("SortedList::internal error ("+key+", "+value+") at ["+freeIndx+"]");
|
||||
|
||||
|
||||
EnsureCapacity (Count+1, freeIndx);
|
||||
|
||||
table = this.table;
|
||||
table [freeIndx].key = key;
|
||||
table [freeIndx].value = value;
|
||||
|
||||
++inUse;
|
||||
++modificationCount;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private object GetImpl (object key)
|
||||
{
|
||||
int i = Find (key);
|
||||
|
||||
if (i >= 0)
|
||||
return table [i].value;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private void InitTable (int capacity)
|
||||
{
|
||||
int size = (capacity + 1) & (~1);
|
||||
if (size < INITIAL_SIZE) size = INITIAL_SIZE;
|
||||
this.table = new Slot [size];
|
||||
this.inUse = 0;
|
||||
this.modificationCount = 0;
|
||||
}
|
||||
|
||||
|
||||
private void CopyToArray (Array arr, int i,
|
||||
EnumeratorMode mode)
|
||||
{
|
||||
IEnumerator it = new Enumerator (this, mode);
|
||||
|
||||
while (it.MoveNext ()) {
|
||||
arr.SetValue (it.Current, i++);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int Find (object key)
|
||||
{
|
||||
Slot [] table = this.table;
|
||||
int len = Count;
|
||||
|
||||
if (len == 0) return ~0;
|
||||
|
||||
IComparer comparer = (this.comparer == null)
|
||||
? Comparer.Default
|
||||
: this.comparer;
|
||||
|
||||
int left = 0;
|
||||
int right = len-1;
|
||||
|
||||
while (left <= right) {
|
||||
int guess = (left + right) >> 1;
|
||||
|
||||
int cmp = comparer.Compare (key, table[guess].key);
|
||||
|
||||
if (cmp == 0) return guess;
|
||||
|
||||
cmp &= ~Int32.MaxValue;
|
||||
|
||||
if (cmp == 0) left = guess+1;
|
||||
else right = guess-1;
|
||||
}
|
||||
|
||||
return ~left;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Inner classes
|
||||
//
|
||||
|
||||
|
||||
protected sealed class Enumerator : IDictionaryEnumerator,
|
||||
IEnumerator {
|
||||
|
||||
private SortedList host;
|
||||
private int stamp;
|
||||
private int pos;
|
||||
private int size;
|
||||
private EnumeratorMode mode;
|
||||
|
||||
private object currentKey;
|
||||
private object currentValue;
|
||||
|
||||
private readonly static string xstr = "SortedList.Enumerator: snapshot out of sync.";
|
||||
|
||||
public Enumerator (SortedList host, EnumeratorMode mode)
|
||||
{
|
||||
this.host = host;
|
||||
stamp = host.modificationCount;
|
||||
size = host.Count;
|
||||
this.mode = mode;
|
||||
Reset ();
|
||||
}
|
||||
|
||||
public Enumerator (SortedList host)
|
||||
: this (host, EnumeratorMode.KEY_MODE)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
private void FailFast ()
|
||||
{
|
||||
if (host.modificationCount != stamp) {
|
||||
throw new InvalidOperationException (xstr);
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset ()
|
||||
{
|
||||
FailFast ();
|
||||
|
||||
pos = -1;
|
||||
currentKey = null;
|
||||
currentValue = null;
|
||||
}
|
||||
|
||||
public bool MoveNext ()
|
||||
{
|
||||
FailFast ();
|
||||
|
||||
Slot [] table = host.table;
|
||||
|
||||
if (++pos < size) {
|
||||
Slot entry = table [pos];
|
||||
|
||||
currentKey = entry.key;
|
||||
currentValue = entry.value;
|
||||
return true;
|
||||
}
|
||||
|
||||
currentKey = null;
|
||||
currentValue = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public DictionaryEntry Entry
|
||||
{
|
||||
get {
|
||||
FailFast ();
|
||||
return new DictionaryEntry (currentKey,
|
||||
currentValue);
|
||||
}
|
||||
}
|
||||
|
||||
public Object Key {
|
||||
get {
|
||||
FailFast ();
|
||||
return currentKey;
|
||||
}
|
||||
}
|
||||
|
||||
public Object Value {
|
||||
get {
|
||||
FailFast ();
|
||||
return currentValue;
|
||||
}
|
||||
}
|
||||
|
||||
public Object Current {
|
||||
get {
|
||||
FailFast ();
|
||||
return (mode == EnumeratorMode.KEY_MODE)
|
||||
? currentKey
|
||||
: currentValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected class ListKeys : IList, IEnumerable {
|
||||
|
||||
private SortedList host;
|
||||
|
||||
|
||||
public ListKeys (SortedList host)
|
||||
{
|
||||
if (host == null)
|
||||
throw new ArgumentNullException ();
|
||||
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
//
|
||||
// ICollection
|
||||
//
|
||||
|
||||
public virtual int Count {
|
||||
get {
|
||||
return host.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool IsSynchronized {
|
||||
get {
|
||||
return host.IsSynchronized;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Object SyncRoot {
|
||||
get {
|
||||
return host.SyncRoot;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void CopyTo (Array array, int arrayIndex)
|
||||
{
|
||||
host.CopyToArray (array, arrayIndex, EnumeratorMode.KEY_MODE);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// IList
|
||||
//
|
||||
|
||||
public virtual bool IsFixedSize {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool IsReadOnly {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public virtual object this [int index] {
|
||||
get {
|
||||
return host.GetKey (index);
|
||||
}
|
||||
set {
|
||||
throw new NotSupportedException("attempt to modify a key");
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int Add (object value)
|
||||
{
|
||||
throw new NotSupportedException("IList::Add not supported");
|
||||
}
|
||||
|
||||
public virtual void Clear ()
|
||||
{
|
||||
throw new NotSupportedException("IList::Clear not supported");
|
||||
}
|
||||
|
||||
public virtual bool Contains (object key)
|
||||
{
|
||||
return host.Contains (key);
|
||||
}
|
||||
|
||||
|
||||
public virtual int IndexOf (object key)
|
||||
{
|
||||
return host.IndexOfKey (key);
|
||||
}
|
||||
|
||||
|
||||
public virtual void Insert (int index, object value)
|
||||
{
|
||||
throw new NotSupportedException("IList::Insert not supported");
|
||||
}
|
||||
|
||||
|
||||
public virtual void Remove (object value)
|
||||
{
|
||||
throw new NotSupportedException("IList::Remove not supported");
|
||||
}
|
||||
|
||||
|
||||
public virtual void RemoveAt (int index)
|
||||
{
|
||||
throw new NotSupportedException("IList::RemoveAt not supported");
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// IEnumerable
|
||||
//
|
||||
|
||||
public virtual IEnumerator GetEnumerator ()
|
||||
{
|
||||
return new SortedList.Enumerator (host, EnumeratorMode.KEY_MODE);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected class ListValues : IList, IEnumerable {
|
||||
|
||||
private SortedList host;
|
||||
|
||||
|
||||
public ListValues (SortedList host)
|
||||
{
|
||||
if (host == null)
|
||||
throw new ArgumentNullException ();
|
||||
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
//
|
||||
// ICollection
|
||||
//
|
||||
|
||||
public virtual int Count {
|
||||
get {
|
||||
return host.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool IsSynchronized {
|
||||
get {
|
||||
return host.IsSynchronized;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Object SyncRoot {
|
||||
get {
|
||||
return host.SyncRoot;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void CopyTo (Array array, int arrayIndex)
|
||||
{
|
||||
host.CopyToArray (array, arrayIndex, EnumeratorMode.VALUE_MODE);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// IList
|
||||
//
|
||||
|
||||
public virtual bool IsFixedSize {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool IsReadOnly {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public virtual object this [int index] {
|
||||
get {
|
||||
return host.GetByIndex (index);
|
||||
}
|
||||
set {
|
||||
// FIXME: It seems (according to tests)
|
||||
// that modifications are allowed
|
||||
// in Beta2.
|
||||
// ? host.SetByIndex (index, value);
|
||||
throw new NotSupportedException("attempt to modify a value");
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int Add (object value)
|
||||
{
|
||||
throw new NotSupportedException("IList::Add not supported");
|
||||
}
|
||||
|
||||
public virtual void Clear ()
|
||||
{
|
||||
throw new NotSupportedException("IList::Clear not supported");
|
||||
}
|
||||
|
||||
public virtual bool Contains (object value)
|
||||
{
|
||||
return host.ContainsValue (value);
|
||||
}
|
||||
|
||||
|
||||
public virtual int IndexOf (object value)
|
||||
{
|
||||
return host.IndexOfValue (value);
|
||||
}
|
||||
|
||||
|
||||
public virtual void Insert (int index, object value)
|
||||
{
|
||||
throw new NotSupportedException("IList::Insert not supported");
|
||||
}
|
||||
|
||||
|
||||
public virtual void Remove (object value)
|
||||
{
|
||||
throw new NotSupportedException("IList::Remove not supported");
|
||||
}
|
||||
|
||||
|
||||
public virtual void RemoveAt (int index)
|
||||
{
|
||||
throw new NotSupportedException("IList::RemoveAt not supported");
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// IEnumerable
|
||||
//
|
||||
|
||||
public virtual IEnumerator GetEnumerator ()
|
||||
{
|
||||
return new SortedList.Enumerator (host, EnumeratorMode.VALUE_MODE);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
} // SortedList
|
||||
|
||||
} // System.Collections
|
||||
@@ -1,310 +0,0 @@
|
||||
// -*- Mode: C; tab-width: 8; c-basic-offset: 8 -*-
|
||||
//
|
||||
// System.Collections.Stack
|
||||
//
|
||||
// Author:
|
||||
// Garrett Rooney ([email protected])
|
||||
//
|
||||
// (C) 2001 Garrett Rooney
|
||||
//
|
||||
|
||||
namespace System.Collections {
|
||||
|
||||
public class Stack : ICollection, IEnumerable, ICloneable {
|
||||
|
||||
// properties
|
||||
private object[] contents;
|
||||
private int current = -1;
|
||||
private int count = 0;
|
||||
private int capacity = 16;
|
||||
private int modCount = 0;
|
||||
|
||||
private void Resize(int ncapacity) {
|
||||
object[] ncontents = new object[ncapacity];
|
||||
|
||||
Array.Copy(contents, ncontents, count);
|
||||
|
||||
capacity = ncapacity;
|
||||
contents = ncontents;
|
||||
}
|
||||
|
||||
public Stack() {
|
||||
contents = new object[capacity];
|
||||
}
|
||||
|
||||
public Stack(ICollection collection) {
|
||||
capacity = collection.Count;
|
||||
contents = new object[capacity];
|
||||
current = capacity - 1;
|
||||
count = capacity;
|
||||
|
||||
collection.CopyTo(contents, 0);
|
||||
}
|
||||
|
||||
public Stack(int c) {
|
||||
capacity = c;
|
||||
contents = new object[capacity];
|
||||
}
|
||||
|
||||
private class SyncStack : Stack {
|
||||
|
||||
Stack stack;
|
||||
|
||||
public SyncStack(Stack s) {
|
||||
stack = s;
|
||||
}
|
||||
|
||||
public override int Count {
|
||||
get {
|
||||
lock (stack) {
|
||||
return stack.Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsReadOnly {
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override bool IsSynchronized {
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override object SyncRoot {
|
||||
get { return stack.SyncRoot; }
|
||||
}
|
||||
|
||||
public override void Clear() {
|
||||
lock(stack) { stack.Clear(); }
|
||||
}
|
||||
|
||||
public override object Clone() {
|
||||
lock (stack) {
|
||||
return Stack.Synchronized((Stack)stack.Clone());
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Contains(object obj) {
|
||||
lock (stack) { return stack.Contains(obj); }
|
||||
}
|
||||
|
||||
public override void CopyTo(Array array, int index) {
|
||||
lock (stack) { stack.CopyTo(array, index); }
|
||||
}
|
||||
|
||||
public override IEnumerator GetEnumerator() {
|
||||
lock (stack) {
|
||||
return new Enumerator(stack);
|
||||
}
|
||||
}
|
||||
|
||||
public override object Peek() {
|
||||
lock (stack) { return stack.Peek(); }
|
||||
}
|
||||
|
||||
public override object Pop() {
|
||||
lock (stack) { return stack.Pop(); }
|
||||
}
|
||||
|
||||
public override void Push(object obj) {
|
||||
lock (stack) { stack.Push(obj); }
|
||||
}
|
||||
|
||||
public override object[] ToArray() {
|
||||
lock (stack) { return stack.ToArray(); }
|
||||
}
|
||||
}
|
||||
|
||||
public static Stack Synchronized(Stack s) {
|
||||
if (s == null) {
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
|
||||
return new SyncStack(s);
|
||||
}
|
||||
|
||||
public virtual int Count {
|
||||
get { return count; }
|
||||
}
|
||||
|
||||
public virtual bool IsReadOnly {
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public virtual bool IsSynchronized {
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public virtual object SyncRoot {
|
||||
get { return this; }
|
||||
}
|
||||
|
||||
public virtual void Clear() {
|
||||
modCount++;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
contents[i] = null;
|
||||
}
|
||||
|
||||
count = 0;
|
||||
current = -1;
|
||||
}
|
||||
|
||||
public virtual object Clone() {
|
||||
Stack stack;
|
||||
|
||||
if (IsSynchronized) {
|
||||
stack = new Stack();
|
||||
|
||||
stack.current = current;
|
||||
stack.contents = contents;
|
||||
stack.count = count;
|
||||
stack.capacity = capacity;
|
||||
} else {
|
||||
stack = new SyncStack(this);
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public virtual bool Contains(object obj) {
|
||||
if (count == 0)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (contents[i].Equals(obj))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual void CopyTo (Array array, int index) {
|
||||
if (array == null) {
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
|
||||
if (index < 0) {
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
if (array.Rank > 1 ||
|
||||
index >= array.Length ||
|
||||
count > array.Length - index) {
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
for (int i = current; i != -1; i--) {
|
||||
array.SetValue(contents[i],
|
||||
count - (i + 1) + index);
|
||||
}
|
||||
}
|
||||
|
||||
private class Enumerator : IEnumerator {
|
||||
|
||||
Stack stack;
|
||||
private int modCount;
|
||||
private int current;
|
||||
|
||||
internal Enumerator(Stack s) {
|
||||
// this is odd. it seems that you need to
|
||||
// start one further ahead than current, since
|
||||
// MoveNext() gets called first when using an
|
||||
// Enumeration...
|
||||
stack = s;
|
||||
modCount = s.modCount;
|
||||
current = s.current + 1;
|
||||
}
|
||||
|
||||
public virtual object Current {
|
||||
get {
|
||||
if (modCount != stack.modCount
|
||||
|| current == -1
|
||||
|| current > stack.count)
|
||||
throw new InvalidOperationException();
|
||||
return stack.contents[current];
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool MoveNext() {
|
||||
if (modCount != stack.modCount
|
||||
|| current == -1) {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
current--;
|
||||
|
||||
if (current == -1) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Reset() {
|
||||
if (modCount != stack.modCount) {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
// start one ahead of stack.current, so the
|
||||
// first MoveNext() will put us at the top
|
||||
current = stack.current + 1;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual IEnumerator GetEnumerator() {
|
||||
return new Enumerator(this);
|
||||
}
|
||||
|
||||
public virtual object Peek() {
|
||||
if (current == -1) {
|
||||
throw new InvalidOperationException();
|
||||
} else {
|
||||
return contents[current];
|
||||
}
|
||||
}
|
||||
|
||||
public virtual object Pop() {
|
||||
if (current == -1) {
|
||||
throw new InvalidOperationException();
|
||||
} else {
|
||||
modCount++;
|
||||
|
||||
object ret = contents[current];
|
||||
|
||||
count--;
|
||||
current--;
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: We should probably be a bit smarter about our
|
||||
// resizing. After a certain point, doubling isn't that smart.
|
||||
// We just need to find out what that point is...
|
||||
public virtual void Push(Object o) {
|
||||
modCount++;
|
||||
|
||||
if (capacity == count) {
|
||||
Resize(capacity * 2);
|
||||
}
|
||||
|
||||
count++;
|
||||
current++;
|
||||
|
||||
contents[current] = o;
|
||||
}
|
||||
|
||||
public virtual object[] ToArray() {
|
||||
object[] ret = new object[count];
|
||||
|
||||
Array.Copy(contents, ret, count);
|
||||
|
||||
// ret needs to be in LIFO order
|
||||
Array.Reverse(ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
ArrayList.cs
|
||||
BitArray.cs
|
||||
Hashtable.cs
|
||||
ICollection.cs
|
||||
IComparer.cs
|
||||
IDictionary.cs
|
||||
@@ -9,5 +7,3 @@ IEnumerable.cs
|
||||
IEnumerator.cs
|
||||
IHashCodeProvider.cs
|
||||
IList.cs
|
||||
Stack.cs
|
||||
SortedList.cs
|
||||
@@ -1,70 +0,0 @@
|
||||
|
||||
//
|
||||
// AssemblyHash.cs
|
||||
//
|
||||
// Implementation of the
|
||||
// System.Configuration.Assemblies.AssemblyHash
|
||||
// class for the Mono Class Library
|
||||
//
|
||||
// Author:
|
||||
// Tomas Restrepo ([email protected])
|
||||
//
|
||||
|
||||
namespace System.Configuration.Assemblies {
|
||||
|
||||
public struct AssemblyHash : System.ICloneable
|
||||
{
|
||||
private AssemblyHashAlgorithm _algorithm;
|
||||
private byte[] _value;
|
||||
|
||||
public static readonly AssemblyHash Empty =
|
||||
new AssemblyHash(AssemblyHashAlgorithm.None,null);
|
||||
|
||||
|
||||
//
|
||||
// properties
|
||||
//
|
||||
public AssemblyHashAlgorithm Algorithm {
|
||||
get { return _algorithm; }
|
||||
set { _algorithm = value; }
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// construction
|
||||
//
|
||||
public AssemblyHash ( AssemblyHashAlgorithm algorithm, byte[] value )
|
||||
{
|
||||
_algorithm = algorithm;
|
||||
_value = null;
|
||||
if ( value != null )
|
||||
{
|
||||
int size = value.Length;
|
||||
_value = new byte[size];
|
||||
System.Array.Copy ( value, _value, size );
|
||||
}
|
||||
}
|
||||
|
||||
public AssemblyHash ( byte[] value )
|
||||
: this(AssemblyHashAlgorithm.SHA1, value)
|
||||
{
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
return new AssemblyHash(_algorithm,_value);
|
||||
}
|
||||
|
||||
public byte[] GetValue()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
public void SetValue ( byte[] value )
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
|
||||
} // class AssemblyHash
|
||||
|
||||
} // namespace System.Configuration.Assemblies
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
|
||||
//
|
||||
// AssemblyHashAlgorithm.cs
|
||||
//
|
||||
// Implementation of the
|
||||
// System.Configuration.Assemblies.AssemblyHashAlgorithm
|
||||
// enumeration for the Mono Class Library
|
||||
//
|
||||
// Written by Tomas Restrepo ([email protected])
|
||||
//
|
||||
|
||||
namespace System.Configuration.Assemblies {
|
||||
|
||||
public enum AssemblyHashAlgorithm
|
||||
{
|
||||
None = 0x00000000,
|
||||
MD5 = 0x00008003,
|
||||
SHA1 = 0x00008004,
|
||||
} // enum AssemblyHashAlgorithm
|
||||
|
||||
} // namespace System.Configuration.Assemblies
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
|
||||
//
|
||||
// AssemblyVersionCompatibility.cs
|
||||
//
|
||||
// Implementation of the
|
||||
// System.Configuration.Assemblies.AssemblyVersionCompatibility
|
||||
// enumeration for the Mono Class Library
|
||||
//
|
||||
// Written by Tomas Restrepo ([email protected])
|
||||
//
|
||||
|
||||
namespace System.Configuration.Assemblies {
|
||||
|
||||
public enum AssemblyVersionCompatibility
|
||||
{
|
||||
SameMachine = 0x00000001,
|
||||
SameProcess = 0x00000002,
|
||||
SameDomain = 0x00000003,
|
||||
|
||||
} // enum AssemblyHashAlgorithm
|
||||
|
||||
} // namespace System.Configuration.Assemblies
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
2001-07-13 Tomas Restrepo ([email protected])
|
||||
|
||||
* AssemblyHash finished
|
||||
* AssemblyHashAlgorithm finished
|
||||
* AssemblyVersion finished
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
AssemblyHash.cs
|
||||
AssemblyHashAlgorithm.cs
|
||||
AssemblyVersionCompatibility.cs
|
||||
Whitespace-only changes.
Whitespace-only changes.
@@ -1,48 +0,0 @@
|
||||
//
|
||||
// System.Diagnostics.BooleanSwitch.cs
|
||||
//
|
||||
// Author:
|
||||
// John R. Hicks ([email protected])
|
||||
//
|
||||
// (C) 2001
|
||||
//
|
||||
|
||||
namespace System.Diagnostics
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides a simple on/off switch that controls debuggina
|
||||
/// and tracing output
|
||||
/// </summary>
|
||||
public class BooleanSwitch : Switch
|
||||
{
|
||||
private bool enabled = false;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance
|
||||
/// </summary>
|
||||
public BooleanSwitch(string displayName, string description)
|
||||
: base(displayName, description)
|
||||
{
|
||||
}
|
||||
|
||||
// =================== Properties ===================
|
||||
|
||||
/// <summary>
|
||||
/// Specifies whether the switch is enabled or disabled
|
||||
/// </summary>
|
||||
public bool Enabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
set
|
||||
{
|
||||
enabled = value;
|
||||
}
|
||||
}
|
||||
|
||||
// ================= Event Handlers =================
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
//
|
||||
// System.Diagnostics.Switch.cs
|
||||
//
|
||||
// Author:
|
||||
// John R. Hicks ([email protected])
|
||||
//
|
||||
// (C) 2001
|
||||
//
|
||||
|
||||
namespace System.Diagnostics
|
||||
{
|
||||
/// <summary>
|
||||
/// Abstract base class to create new debugging and tracing switches
|
||||
/// </summary>
|
||||
public abstract class Switch
|
||||
{
|
||||
private string desc = "";
|
||||
private string display_name = "";
|
||||
private int iSwitch;
|
||||
|
||||
// ================= Constructors ===================
|
||||
/// <summary>
|
||||
/// Initialize a new instance
|
||||
/// </summary>
|
||||
protected Switch(string displayName, string description)
|
||||
{
|
||||
display_name = displayName;
|
||||
desc = description;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows an Object to attempt to free resources and
|
||||
/// perform cleanup before the Object is reclaimed
|
||||
/// by the Garbage Collector
|
||||
/// </summary>
|
||||
~Switch()
|
||||
{
|
||||
}
|
||||
|
||||
// ================ Instance Methods ================
|
||||
|
||||
// ==================== Properties ==================
|
||||
|
||||
/// <summary>
|
||||
/// Returns a description of the switch
|
||||
/// </summary>
|
||||
public string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a name used to identify the switch
|
||||
/// </summary>
|
||||
public string DisplayName
|
||||
{
|
||||
get
|
||||
{
|
||||
return display_name;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the current setting for this switch
|
||||
/// </summary>
|
||||
protected int SwitchSetting
|
||||
{
|
||||
get
|
||||
{
|
||||
return iSwitch;
|
||||
}
|
||||
set
|
||||
{
|
||||
if(iSwitch != value)
|
||||
{
|
||||
|
||||
}
|
||||
iSwitch = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the SwitchSettingChanged event
|
||||
/// </summary>
|
||||
protected virtual void OnSwitchSettingChanged()
|
||||
{
|
||||
// TODO: implement me
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
//
|
||||
// System.Diagnostics.TraceLevel.cs Enumeration
|
||||
//
|
||||
// Author:
|
||||
// John R. Hicks ([email protected])
|
||||
//
|
||||
// (C) 2001
|
||||
|
||||
namespace System.Diagnostics
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies what messages to output for the Debug, Trace and TraceSwitch classes.
|
||||
/// </summary>
|
||||
public enum TraceLevel {Error, Info, Off, Verbose, Warning}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
//
|
||||
// System.Diagnostics.TraceSwtich.cs
|
||||
//
|
||||
// Author:
|
||||
// John R. Hicks ([email protected])
|
||||
//
|
||||
// (C) 2001
|
||||
//
|
||||
|
||||
namespace System.Diagnostics
|
||||
{
|
||||
/// <summary>
|
||||
/// Multi-level switch to provide tracing and debug output without
|
||||
/// recompiling.
|
||||
/// </summary>
|
||||
public class TraceSwitch : Switch
|
||||
{
|
||||
private TraceLevel level;
|
||||
private bool traceError = false;
|
||||
private bool traceInfo = false;
|
||||
private bool traceVerbose = false;
|
||||
private bool traceWarning = false;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance
|
||||
/// </summary>
|
||||
/// <param name="displayName">Name for the switch</param>
|
||||
/// <param name="description">Description of the switch</param>
|
||||
public TraceSwitch(string displayName, string description)
|
||||
: base(displayName, description)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the trace level that specifies the messages to
|
||||
/// output for tracing and debugging.
|
||||
/// </summary>
|
||||
public TraceLevel Level
|
||||
{
|
||||
get
|
||||
{
|
||||
return level;
|
||||
}
|
||||
set
|
||||
{
|
||||
level = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the Level is set to Error,
|
||||
/// Warning, Info, or Verbose.
|
||||
/// </summary>
|
||||
public bool TraceError
|
||||
{
|
||||
get
|
||||
{
|
||||
return traceError;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the Level is set to Info or Verbose.
|
||||
/// </summary>
|
||||
public bool TraceInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
return traceInfo;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the Level is set to Verbose.
|
||||
/// </summary>
|
||||
public bool TraceVerbose
|
||||
{
|
||||
get
|
||||
{
|
||||
return traceVerbose;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the Level is set to
|
||||
/// Warning, Info, or Verbose.
|
||||
/// </summary>
|
||||
public bool TraceWarning
|
||||
{
|
||||
get
|
||||
{
|
||||
return traceWarning;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
BooleanSwitch.cs
|
||||
Switch.cs
|
||||
TraceLevel.cs
|
||||
TraceSwitch.cs
|
||||
Whitespace-only changes.
Loaded 100 of 309 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user