| 1 |
Dia2Code v. 1.0.0 |
| 2 |
|
| 3 |
SUMMARY |
| 4 |
|
| 5 |
This program generates code for many languages from an UML Dia Diagram. |
| 6 |
|
| 7 |
|
| 8 |
DESCRIPTION |
| 9 |
|
| 10 |
This program is a small utility that makes code from a Dia diagram. Supported |
| 11 |
target languages are: C++(99,11), C#, Java, PHP5. |
| 12 |
Starting version 1.0.0, the program was completely rewritten in C++. |
| 13 |
Target languages still to be ported from the dia2code-0.8.x C implementation are: |
| 14 |
ActionScript3, Ada, C, Python, Ruby, shapefiles, and SQL create statement files. |
| 15 |
|
| 16 |
Its intended purpose is to ease the programmer's work by generating |
| 17 |
the structure of the classes in an Object Oriented language |
| 18 |
(like C++, Java and C#) from a graphical representation of them |
| 19 |
(a Dia Diagram). |
| 20 |
|
| 21 |
|
| 22 |
STATUS |
| 23 |
|
| 24 |
Dia2Code generates C++(99,11), C#, Java, PHP. |
| 25 |
Templates and packages are supported. |
| 26 |
In the future, it will be able to generate ActionScript, Ada, C, IDL, Python, Ruby, |
| 27 |
shape files, and SQL's CREATE TABLE statements. |
| 28 |
For the time being, if you require any of these languages, please continue to use |
| 29 |
the dia2code-0.8.x C based implementation. |
| 30 |
|
| 31 |
The generation of #include and import directives is automatically done |
| 32 |
considering the types used in each class but they may be added by dependencies. |
| 33 |
Classes are automatically searched in the types of: |
| 34 |
attributes, method's return types, method's parameters, parents, dependencies |
| 35 |
and associations. |
| 36 |
|
| 37 |
Dia2Code handles Associations, Dependencies, Realizations, Implements and |
| 38 |
Generalizations. |
| 39 |
|
| 40 |
Feel free to have a try and send me your comments. |
| 41 |
|
| 42 |
|
| 43 |
LICENSE |
| 44 |
|
| 45 |
This program is distributed under the GNU GPLv3. |
| 46 |
Read the COPYING file for details. |
| 47 |
|
| 48 |
|
| 49 |
REQUIREMENTS |
| 50 |
|
| 51 |
Works under Linux (i386 and x64) and Win32/Win64. |
| 52 |
Feedback about other platforms is welcome. |
| 53 |
|
| 54 |
- Dia (I work with 0.97.2 but older versions *may* be OK). |
| 55 |
- libxml2 headers and development libraries (I use 2.9 but it *may* be |
| 56 |
OK if you use any version greater than 2.0). |
| 57 |
- A C++ compiler which supports C++11 standard (>=gcc 4.6). |
| 58 |
- automake and autoconf (actually, optional) |
| 59 |
|
| 60 |
|
| 61 |
INSTALLATION |
| 62 |
|
| 63 |
Usually: |
| 64 |
|
| 65 |
$ ./configure --with-corba |
| 66 |
|
| 67 |
$ make |
| 68 |
|
| 69 |
$ make check |
| 70 |
|
| 71 |
# make install |
| 72 |
|
| 73 |
Read the INSTALL file for details. |
| 74 |
|
| 75 |
If that doesn't work for you, try (from the src's dia2code directory): |
| 76 |
|
| 77 |
$ g++ -std=c++11 -I/usr/include/libxml2 *.cpp -O2 -o dia2codetest -lxml2 -I.. |
| 78 |
|
| 79 |
$ strip dia2code |
| 80 |
|
| 81 |
To cross-compiling from Linux (build=x86_64-pc-linux-gnu): |
| 82 |
- To Win32, with package cross-i686-pc-mingw32/gcc: |
| 83 |
# ./configure --disable-static --enable-shared --build=x86_64-pc-linux-gnu --host=i686-pc-mingw32 |
| 84 |
|
| 85 |
- To Win64, with package cross-x86_64-w64-mingw32/gcc: |
| 86 |
# ./configure --disable-static --enable-shared --build=x86_64-pc-linux-gnu --host=x86_64-w64-mingw32 |
| 87 |
|
| 88 |
- To Linux32: |
| 89 |
# ./configure --disable-static --enable-shared -m32 |
| 90 |
|
| 91 |
- To Linux64: |
| 92 |
# ./configure --disable-static --enable-shared -m64 |
| 93 |
|
| 94 |
|
| 95 |
OPERATION |
| 96 |
|
| 97 |
$ dia2code <parameters> |
| 98 |
|
| 99 |
Where <parameters> can be any combination of: |
| 100 |
|
| 101 |
-h --help Print this help and exit. |
| 102 |
-d <dir> Output generated files to <dir>, default is "." |
| 103 |
--buildtree Convert package names to a directory tree. |
| 104 |
Imply -1. Off by default. |
| 105 |
-l <license> License file to prepend to generated files. |
| 106 |
-nc Do not overwrite files that already exist. |
| 107 |
-cl <classlist> Generate code only for the classes specified in |
| 108 |
the comma-separated <classlist>. |
| 109 |
E.g: Base,Derived. |
| 110 |
-v Invert the class list selection. When used |
| 111 |
without -cl prevents any file from being created. |
| 112 |
--version Show version x.y.z. |
| 113 |
--tab <number> Set number of spaces for one indentation. |
| 114 |
Default: 4. Maximum: 8. |
| 115 |
-ext <extension> Use <extension> as the file extension. |
| 116 |
Here are the defaults: |
| 117 |
ada:"ads", c:"h", cpp:"hpp", idl:"idl", |
| 118 |
java:"java", php:"php", python:"py", |
| 119 |
csharp:"cs". |
| 120 |
Not applicable to shp, sql. |
| 121 |
-bext <extension> Use <extension> as the body (implementation) file |
| 122 |
extension. Only applies to ada and c. |
| 123 |
Here are the defaults: |
| 124 |
ada:"adb", c:"c". |
| 125 |
-nl Create new line on new brace. Off by default. |
| 126 |
-1 One header contains only one header. If two classes |
| 127 |
have the same name, they will be overwritten without |
| 128 |
--buildtree. |
| 129 |
Off by default but java. |
| 130 |
-t <target> Selects the output language. <target> can be one of: |
| 131 |
ada,as3,c,cpp,cpp11,csharp,idl,java,php,php5,python, |
| 132 |
ruby,shp,sql. |
| 133 |
<diagramfile> The Dia file that holds the diagram to be read. |
| 134 |
|
| 135 |
The only mandatory parameters are the diagram file name and the target. |
| 136 |
|
| 137 |
Note: Parameters can be specified in any order. |
| 138 |
|
| 139 |
|
| 140 |
EXAMPLES |
| 141 |
|
| 142 |
$ dia2code -t java test.dia |
| 143 |
|
| 144 |
Will generate the *.java files for the classes in the test.dia diagram |
| 145 |
and put them in the current directory. |
| 146 |
|
| 147 |
$ dia2code -t cpp -nc -d ~/C++ hw.dia |
| 148 |
|
| 149 |
Will generate the *.cpp and *.h files for the classes in the test.dia |
| 150 |
diagram and put them in the directory ~/C++. It won't overwrite any |
| 151 |
existant file. |
| 152 |
|
| 153 |
$ dia2code -t java -cl Base,Derived test.dia |
| 154 |
|
| 155 |
Will create the Java files only for classes "Base" and "Derived". |
| 156 |
|
| 157 |
$ dia2code -t cpp -cl B*,*Foo test.dia |
| 158 |
|
| 159 |
Will create the *.hpp files for classes that begin with "B" or |
| 160 |
end with "Foo". |
| 161 |
NOTE: You can only specify one asterisk and either at the beginning or end |
| 162 |
of the pattern. |
| 163 |
NOTE2: You may have to quote the asterisks when typing on the shell |
| 164 |
(e.g. "\*" instead of "*") |
| 165 |
|
| 166 |
$ dia2code -t cpp -cl Foo -v foobar.dia |
| 167 |
|
| 168 |
Will create C++ code for all classes but "Foo". |
| 169 |
|
| 170 |
$ dia2code -t cpp -v test.dia |
| 171 |
|
| 172 |
Will not create any files. Don't know if it may be useful, but it surely |
| 173 |
is syntactically correct. |
| 174 |
|
| 175 |
|
| 176 |
NOTES ON UML |
| 177 |
|
| 178 |
What you should put into your diagram |
| 179 |
|
| 180 |
These are mandatory: |
| 181 |
|
| 182 |
- A non-empty class or package name. |
| 183 |
- For each attribute, the name and type. |
| 184 |
- For each method, the name. |
| 185 |
- For each method's parameter, the name and type. |
| 186 |
|
| 187 |
These are optional: |
| 188 |
|
| 189 |
- The stereotype of the class. |
| 190 |
- The default value of attributes. |
| 191 |
- The default value of parameters. |
| 192 |
- The return type of a method. If no type is declared, dia2code |
| 193 |
will output no type at all for it. |
| 194 |
|
| 195 |
|
| 196 |
OUTPUT |
| 197 |
|
| 198 |
This section shows some examples of UML diagram converted to code without use |
| 199 |
of stereotype. |
| 200 |
Lines starting with double stars are comments to explain the process of the |
| 201 |
generation of the code. |
| 202 |
|
| 203 |
Common: |
| 204 |
If -1 and --buildtree are not specified, the name of each file will be the |
| 205 |
class name (if not in a package) and the name of the top package either. |
| 206 |
If -1 or --buildtree is specified, the filename will be the class name. |
| 207 |
|
| 208 |
|
| 209 |
C++ generator: |
| 210 |
** The license if specified in command line (-l option). |
| 211 |
/* |
| 212 |
File bit-by-bit. |
| 213 |
*/ |
| 214 |
|
| 215 |
** Header guard |
| 216 |
#ifndef README__HPP |
| 217 |
#define README__HPP |
| 218 |
|
| 219 |
** Dependencies |
| 220 |
#include "dependencies.hpp" |
| 221 |
|
| 222 |
** Templates |
| 223 |
template <type template> |
| 224 |
|
| 225 |
** Namespace if classes are in package. |
| 226 |
namespace package { |
| 227 |
** Class with inheritance if necessary. |
| 228 |
class Class : public ParentClass { |
| 229 |
** Visibility of the attribute / operation. Public, private, protected |
| 230 |
** are supported. Implementation is not, default will be public. |
| 231 |
** Attributes will be printed first, then operations. |
| 232 |
// Attributes |
| 233 |
** Default values are ignored for attributes. |
| 234 |
public : |
| 235 |
** Comments are in doxygen format. |
| 236 |
/// Comment for the first |
| 237 |
/// attribute. |
| 238 |
type1 nom1; |
| 239 |
private : |
| 240 |
/// Example of static attribute. |
| 241 |
static type2 nom2; |
| 242 |
protected : |
| 243 |
type3 nom3; |
| 244 |
// Operations |
| 245 |
public : |
| 246 |
/** |
| 247 |
* \class AbstractOperation |
| 248 |
* \brief Multiple line |
| 249 |
* comment |
| 250 |
*/ |
| 251 |
** An abstract operation must not be defined thus " = 0". |
| 252 |
virtual AbstractOperation () = 0; |
| 253 |
** A virtual operation must be defined in the source code. |
| 254 |
virtual VirtualOperation (); |
| 255 |
NonAbstractOperation (); |
| 256 |
/** |
| 257 |
* \brief comment |
| 258 |
* \param in (in) |
| 259 |
* \param inOut (in/out) comment2 |
| 260 |
* \param undef (???) |
| 261 |
* \param out (out) |
| 262 |
*/ |
| 263 |
virtual type test (type1 in, type2 inOut, type3 undef = 0, type4 out) = 0; |
| 264 |
static test2 (); |
| 265 |
test3 () const; |
| 266 |
}; |
| 267 |
} |
| 268 |
|
| 269 |
** End of header guard |
| 270 |
#endif |
| 271 |
|
| 272 |
|
| 273 |
C++11 generator: |
| 274 |
** The license if specified in command line (-l option). |
| 275 |
/* |
| 276 |
File bit-by-bit. |
| 277 |
*/ |
| 278 |
|
| 279 |
** Header guard |
| 280 |
#ifndef README__HPP |
| 281 |
#define README__HPP |
| 282 |
|
| 283 |
** Dependencies |
| 284 |
#include "dependencies.hpp" |
| 285 |
|
| 286 |
** Templates |
| 287 |
template <type template> |
| 288 |
|
| 289 |
** Namespace if class are in package. |
| 290 |
namespace package { |
| 291 |
** Class with inheritance if necessary. |
| 292 |
public class Class : public ParentClass { |
| 293 |
** Visibility of the attribute / operation. Public, private, protected |
| 294 |
** are supported. Implementation is not, default will be public. |
| 295 |
** Attributes will be print first, then operations. |
| 296 |
// Attributes |
| 297 |
** Default values are ignored for attributes. |
| 298 |
public : |
| 299 |
** Comments are in doxygen format. |
| 300 |
/// Comment for the first |
| 301 |
/// attribute. |
| 302 |
type1 nom1; |
| 303 |
private : |
| 304 |
/// Exemple of static attribut. |
| 305 |
static type2 nom2; |
| 306 |
protected : |
| 307 |
type3 nom3; |
| 308 |
// Operations |
| 309 |
public : |
| 310 |
/** |
| 311 |
* \class AbstractOperation |
| 312 |
* \brief Multiple line |
| 313 |
* comment |
| 314 |
*/ |
| 315 |
** An abstract operation must not be defined thus " = 0". |
| 316 |
virtual AbstractOperation () = 0; |
| 317 |
** A virtual operation must be defined in the source code. |
| 318 |
virtual VirtualOperation (); |
| 319 |
NonAbstractOperation (); |
| 320 |
/** |
| 321 |
* \brief comment |
| 322 |
* \param in (in) |
| 323 |
* \param inOut (in/out) comment2 |
| 324 |
* \param undef (???) |
| 325 |
* \param out (out) |
| 326 |
*/ |
| 327 |
virtual type test (type1 in, type2 inOut, type3 undef = 0, type4 out) = 0; |
| 328 |
static test2 (); |
| 329 |
constexpr test3 (); |
| 330 |
}; |
| 331 |
} |
| 332 |
|
| 333 |
** End of header guard |
| 334 |
#endif |
| 335 |
|
| 336 |
|
| 337 |
C# generator: |
| 338 |
https://msdn.microsoft.com/en-us/library/ms228500%28v=vs.90%29.aspx |
| 339 |
|
| 340 |
XML Documentation Comments |
| 341 |
https://msdn.microsoft.com/en-us/library/b2s063f7.aspx |
| 342 |
|
| 343 |
** The license if specified in command line (-l option). |
| 344 |
/* |
| 345 |
File bit-by-bit. |
| 346 |
*/ |
| 347 |
|
| 348 |
** No header guard |
| 349 |
|
| 350 |
** Dependencies |
| 351 |
using dependencies; |
| 352 |
|
| 353 |
** Templates |
| 354 |
template <type template> |
| 355 |
|
| 356 |
** Namespace if classes are in package. |
| 357 |
namespace package { |
| 358 |
** Class with inheritance and templates if necessary. |
| 359 |
public class Class <template> : ParentClass where template : type { |
| 360 |
** Attributes will be printed first, then operations. |
| 361 |
// Attributes |
| 362 |
** Comments are in XML format. |
| 363 |
/// <summary>com1</summary> |
| 364 |
public type1 nom1 = val1; |
| 365 |
private static type2 nom2; |
| 366 |
protected type3 nom3 = val3; |
| 367 |
// Operations |
| 368 |
public abstract AbstractOperation (); |
| 369 |
public virtual VirtualOperation (); |
| 370 |
public NonAbstractOperation (); |
| 371 |
/// <summary>comment</summary> |
| 372 |
/// <param name="in">(in)</param> |
| 373 |
/// <param name="inOut">(in/out) comment2</param> |
| 374 |
/// <param name="undef">(???)</param> |
| 375 |
/// <param name="out">(out)</param> |
| 376 |
/// <returns>type</returns> |
| 377 |
public abstract type test (type1 in, type2 inOut, type3 undef = 0, type4 out); |
| 378 |
public static test2 (); |
| 379 |
** There is no const function in C#. |
| 380 |
public test3 (); |
| 381 |
}; |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
Java generator: |
| 386 |
Convention naming: |
| 387 |
http://www.oracle.com/technetwork/java/codeconventions-135099.html |
| 388 |
|
| 389 |
Packages: all-lowercase ASCII letters and should be one of the top-level domain |
| 390 |
names, currently com, edu, gov, mil, net, org, or one of the English two-letter |
| 391 |
codes identifying countries as specified in ISO Standard 3166, 1981. |
| 392 |
com.sun.eng |
| 393 |
com.apple.quicktime.v2 |
| 394 |
edu.cmu.cs.bovik.cheese |
| 395 |
|
| 396 |
Classes or Interfaces: |
| 397 |
Class names should be nouns, in mixed case with the first letter of each |
| 398 |
internal word capitalized. |
| 399 |
class Raster; |
| 400 |
class ImageSprite |
| 401 |
|
| 402 |
Methods: |
| 403 |
Methods should be verbs, in mixed case with the first letter lowercase, with |
| 404 |
the first letter of each internal word capitalized. |
| 405 |
run (); |
| 406 |
runFast (); |
| 407 |
|
| 408 |
Variables: |
| 409 |
Except for variables, all instance, class, and class constants are in mixed |
| 410 |
case with a lowercase first letter. Internal words start with capital letters. |
| 411 |
Variable names should not start with underscore _ or dollar sign $ characters, |
| 412 |
even though both are allowed. |
| 413 |
int i; |
| 414 |
char c; |
| 415 |
float myWidth; |
| 416 |
|
| 417 |
Constants: |
| 418 |
The names of variables declared class constants and of ANSI constants should be |
| 419 |
all uppercase with words separated by underscores ("_"). |
| 420 |
static final int MAX_WIDTH = 999; |
| 421 |
|
| 422 |
|
| 423 |
** The license if specified in command line (-l option). |
| 424 |
/* |
| 425 |
File bit-by-bit. |
| 426 |
*/ |
| 427 |
|
| 428 |
** No header guard |
| 429 |
|
| 430 |
** Dependencies |
| 431 |
import Dependencies; |
| 432 |
|
| 433 |
** If class are in package. |
| 434 |
package Pack; |
| 435 |
|
| 436 |
** Class with inheritance and templates if necessary. |
| 437 |
public class Class <template extends type> extends ParentClass { |
| 438 |
** Attributes will be printed first, then operations. |
| 439 |
// Attributes |
| 440 |
** Comments are in doxygen format. |
| 441 |
/** |
| 442 |
* comment. |
| 443 |
*/ |
| 444 |
public type1 nom1 = val1; |
| 445 |
private static type2 nom2; |
| 446 |
protected type3 nom3 = val3; |
| 447 |
// Operations |
| 448 |
public abstract AbstractOperation (); |
| 449 |
public VirtualOperation (); |
| 450 |
public final NonAbstractOperation (); |
| 451 |
/** |
| 452 |
* comment |
| 453 |
* @param in (in) |
| 454 |
* @param inOut (in/out) comment2 |
| 455 |
* @param undef (???) |
| 456 |
* @param out (out) |
| 457 |
* @return type |
| 458 |
*/ |
| 459 |
** There is no default param in Java. |
| 460 |
public abstract type test (type1 in, type2 inOut, type3 undef = 0, type4 out); |
| 461 |
public static test2 (); |
| 462 |
** There is no const function in Java. |
| 463 |
public test3 (); |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
STEREOTYPES |
| 468 |
|
| 469 |
Multiple stereotypes can be applied on each class, attribute, operation, |
| 470 |
inheritance and dependence by separating them with a "," without space. |
| 471 |
For example (without quotes): "interface,getset". |
| 472 |
|
| 473 |
|
| 474 |
- Inheritance or Realization of an interface: |
| 475 |
|
| 476 |
By default, all inheritances are public. Some languages, like C++, allow a |
| 477 |
different visibility like protected or private. |
| 478 |
Possible value: public, private, protected, implementation. |
| 479 |
|
| 480 |
C++ and C++11 generator: |
| 481 |
** The stereotype of Generalization (or Realizes) of three classes are public, |
| 482 |
** protected and private. |
| 483 |
** Implementation visibility is not applicable to C++ generator. |
| 484 |
class InheritanceClasseChildren : public InheritanceClasseImplement, protected InheritanceClasseProtected, private InheritancePack1::InheritanceClassePrivate { |
| 485 |
}; |
| 486 |
|
| 487 |
C# generator: |
| 488 |
** Generalization are public only. |
| 489 |
class InheritanceClasseChildren : InheritanceClasseImplement : InheritanceClasseProtected : InheritanceClassePrivate { |
| 490 |
}; |
| 491 |
|
| 492 |
Java generator: |
| 493 |
** In Java, Generalization are public only. |
| 494 |
class InheritanceClasseChildren extends InheritanceClasseImplement extends InheritanceClasseProtected extends InheritancePack1.InheritanceClassePrivate { |
| 495 |
}; |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
- Classes: |
| 500 |
|
| 501 |
CORBAValue: |
| 502 |
---------- |
| 503 |
To enable Corba to a class, the stereotype must be CORBAValue. |
| 504 |
|
| 505 |
GetSet |
| 506 |
------ |
| 507 |
Generate all get/set functions of all attributes. Their visibility will be |
| 508 |
public. If you want to be able to customize the visibility of the functions |
| 509 |
or generate get/set only for specifics attributes, use instead GetSet |
| 510 |
stereotype on operation. |
| 511 |
|
| 512 |
A "T getA ();" method, with return type conformant to the type of the |
| 513 |
attribute. If the type of the attribute is boolean (boolean, Boolean or bool) |
| 514 |
then the name will be: "T isA ()". |
| 515 |
|
| 516 |
A "void setA (T value);" method, with a parameter, "value", with type |
| 517 |
conformant to the type of the attribute. |
| 518 |
|
| 519 |
C++ generator: |
| 520 |
** The stereotype of the class is GetSet. |
| 521 |
// Stereotype : GetSet |
| 522 |
public class GetSet { |
| 523 |
// Attributes |
| 524 |
private : |
| 525 |
char * nom; |
| 526 |
bool boole; |
| 527 |
// Operations |
| 528 |
public : |
| 529 |
char * getNom () const; |
| 530 |
void setNom (char * value); |
| 531 |
bool isBoole () const; |
| 532 |
void setBoole (bool value); |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
C++11 generator: |
| 537 |
** The stereotype of the class is GetSet. |
| 538 |
// Stereotype : GetSet |
| 539 |
public class GetSet { |
| 540 |
// Attributes |
| 541 |
private : |
| 542 |
char * nom; |
| 543 |
bool boole; |
| 544 |
// Operations |
| 545 |
public : |
| 546 |
constexpr char * getNom (); |
| 547 |
void setNom (char * value); |
| 548 |
constexpr bool isBoole (); |
| 549 |
void setBoole (bool value); |
| 550 |
} |
| 551 |
|
| 552 |
|
| 553 |
C# generator: |
| 554 |
// Stereotype : GetSet |
| 555 |
public class GetSet { |
| 556 |
// Attributes |
| 557 |
public type nom; |
| 558 |
/// <summary>com2</summary> |
| 559 |
private bool boole; |
| 560 |
// Operations |
| 561 |
public type Nom { |
| 562 |
get { |
| 563 |
} |
| 564 |
set { |
| 565 |
} |
| 566 |
} |
| 567 |
public bool Boole { |
| 568 |
get { |
| 569 |
} |
| 570 |
set { |
| 571 |
} |
| 572 |
} |
| 573 |
} |
| 574 |
|
| 575 |
|
| 576 |
Java generator: |
| 577 |
** The stereotype of the class is GetSet. |
| 578 |
// Stereotype : GetSet |
| 579 |
public class GetSet { |
| 580 |
// Attributes |
| 581 |
private char * nom; |
| 582 |
private bool boole; |
| 583 |
// Operations |
| 584 |
public char * getNom () { |
| 585 |
} |
| 586 |
public void setNom (char * value) { |
| 587 |
} |
| 588 |
public bool isBoole () { |
| 589 |
} |
| 590 |
public void setBoole (bool value) { |
| 591 |
} |
| 592 |
} |
| 593 |
|
| 594 |
|
| 595 |
const, constant, Const, Constant or CORBAConstant: |
| 596 |
----- -------- ----- -------- ------------- |
| 597 |
|
| 598 |
TODO |
| 599 |
|
| 600 |
|
| 601 |
enum, enumeration, Enum, Enumeration or CORBAEnum: |
| 602 |
---- ----------- ---- ----------- --------- |
| 603 |
|
| 604 |
Generate an enum class. Only attributes will be used. Template or function are |
| 605 |
ignored. |
| 606 |
|
| 607 |
|
| 608 |
C++ generator: |
| 609 |
/// Comment of the enum |
| 610 |
enum enumeration { |
| 611 |
/// Comment ENUM_1 |
| 612 |
ENUM_1 = 0, |
| 613 |
/// Comment ENUM_2 |
| 614 |
ENUM_2, |
| 615 |
/// Comment ENUM_3 |
| 616 |
ENUM_3 |
| 617 |
}; |
| 618 |
|
| 619 |
|
| 620 |
C++11 generator: |
| 621 |
/// Comment of the enum |
| 622 |
enum class enumeration { |
| 623 |
/// Comment ENUM_1 |
| 624 |
ENUM_1 = 0, |
| 625 |
/// Comment ENUM_2 |
| 626 |
ENUM_2, |
| 627 |
/// Comment ENUM_3 |
| 628 |
ENUM_3 |
| 629 |
}; |
| 630 |
|
| 631 |
|
| 632 |
C# generator: |
| 633 |
/// <summary>Comment of the enum</summary> |
| 634 |
public enum enumeration { |
| 635 |
/// <summary>enum1</summary> |
| 636 |
ENUM_1 = 0, |
| 637 |
/// <summary>enum2</summary> |
| 638 |
ENUM_2, |
| 639 |
ENUM_3 |
| 640 |
}; |
| 641 |
|
| 642 |
|
| 643 |
Java generator: |
| 644 |
/** |
| 645 |
* Comment of the enum |
| 646 |
*/ |
| 647 |
public enum enumeration { |
| 648 |
/// Comment ENUM_1 |
| 649 |
ENUM_1 = 0, |
| 650 |
/// Comment ENUM_2 |
| 651 |
ENUM_2, |
| 652 |
ENUM_3 |
| 653 |
}; |
| 654 |
|
| 655 |
|
| 656 |
struct, structure, Struct, Structure, or CORBAStruct: |
| 657 |
------ --------- ------ --------- ----------- |
| 658 |
|
| 659 |
A structure is almost the same as a class. |
| 660 |
|
| 661 |
|
| 662 |
C++ and C++11 generator: |
| 663 |
** In C++, all attributes and operations are public. |
| 664 |
/// Comment about the structure. |
| 665 |
struct structure { |
| 666 |
// Attributes |
| 667 |
/// com1 |
| 668 |
type1 nom1; |
| 669 |
/// com2-1 |
| 670 |
/// com2-2 |
| 671 |
type2 nom2; |
| 672 |
type3 nom3; |
| 673 |
// Operations |
| 674 |
void operation (type1 attr1); |
| 675 |
}; |
| 676 |
|
| 677 |
|
| 678 |
C# generator: |
| 679 |
public struct structure { |
| 680 |
/// <summary>com1</summary> |
| 681 |
public type1 nom1; |
| 682 |
/// <summary>com2-1 |
| 683 |
/// com2-2</summary> |
| 684 |
public type2 nom2; |
| 685 |
public type3 nom3; |
| 686 |
public void operation (type1 attr1) { |
| 687 |
} |
| 688 |
}; |
| 689 |
|
| 690 |
|
| 691 |
Java generator: |
| 692 |
** In Java, structure is not defined. The equivalent is a class. |
| 693 |
/** |
| 694 |
* Comment about the structure. |
| 695 |
*/ |
| 696 |
public class structure { |
| 697 |
// Attributes |
| 698 |
/** |
| 699 |
* com1 |
| 700 |
*/ |
| 701 |
public type1 nom1; |
| 702 |
/** |
| 703 |
* com2-1 |
| 704 |
* com2-2 |
| 705 |
*/ |
| 706 |
private type2 nom2; |
| 707 |
protected type3 nom3; |
| 708 |
// Operations |
| 709 |
public void operation (type1 attr1) { |
| 710 |
} |
| 711 |
}; |
| 712 |
|
| 713 |
|
| 714 |
typedef, Typedef or CORBATypedef: |
| 715 |
------- ------- ------------ |
| 716 |
|
| 717 |
A typedef defines a type as a derivated of another one. |
| 718 |
The name of the new type is the name of the classe. |
| 719 |
The name of the derivated type is the name of the first attribute. |
| 720 |
All other information is ignored. |
| 721 |
Not applicable in Java. |
| 722 |
|
| 723 |
|
| 724 |
C++ and C++11 generator: |
| 725 |
#include "Pack.hpp" |
| 726 |
|
| 727 |
typedef PrimitiveType NewType1; |
| 728 |
typedef Pack::ClassType NewType2; |
| 729 |
|
| 730 |
C# generator: |
| 731 |
using Pack; |
| 732 |
|
| 733 |
public class AliasOfMyClass : MyClass {} |
| 734 |
public class ArrayOfBool : bool[3][10] {} |
| 735 |
|
| 736 |
|
| 737 |
Java generator: |
| 738 |
import Pack.ClassType; |
| 739 |
|
| 740 |
class NewType1 extends PrimitiveType {} |
| 741 |
class NewType2 extends Pack.ClassType {} |
| 742 |
|
| 743 |
|
| 744 |
extern: |
| 745 |
------ |
| 746 |
Define a external class. Usefull for external dependencies when you don't want |
| 747 |
to generate the class' source. |
| 748 |
IMPORTANT for C++ generator: because extern can define a system header <list> |
| 749 |
or a header for another <Class.hpp>, no extension will be automatically added. |
| 750 |
If a class implements such external class, the extension (if so) will be |
| 751 |
removed. |
| 752 |
|
| 753 |
|
| 754 |
C++ and C++11 generator: |
| 755 |
#include <Pack/Class.hpp> |
| 756 |
|
| 757 |
|
| 758 |
C# generator: |
| 759 |
using Pack; |
| 760 |
|
| 761 |
|
| 762 |
Java generator: |
| 763 |
import Pack.Class; |
| 764 |
|
| 765 |
|
| 766 |
interface, Interface: |
| 767 |
--------- --------- |
| 768 |
Define a interface. The class will be automatically considers as a interface if |
| 769 |
a Realization or a Implementation link are pointing to it. |
| 770 |
|
| 771 |
|
| 772 |
C++ and C++11 generator: |
| 773 |
class Interface2 { |
| 774 |
}; |
| 775 |
|
| 776 |
|
| 777 |
C# generator: |
| 778 |
public interface Interface2 { |
| 779 |
} |
| 780 |
|
| 781 |
|
| 782 |
Java generator: |
| 783 |
public interface Interface2 { |
| 784 |
} |
| 785 |
|
| 786 |
|
| 787 |
dllexport, DllExport: |
| 788 |
--------- --------- |
| 789 |
Force some signature to be store in a Microsoft Library Manager (lib). |
| 790 |
|
| 791 |
|
| 792 |
C++ and C++11 generator: |
| 793 |
class DllExport operations { |
| 794 |
} |
| 795 |
// Don't forget to add a #define: |
| 796 |
// #define DllExport __declspec (dllexport) |
| 797 |
|
| 798 |
|
| 799 |
C# generator: |
| 800 |
Java generator: |
| 801 |
PHP gerenator: |
| 802 |
not supported |
| 803 |
|
| 804 |
|
| 805 |
- Operation: |
| 806 |
|
| 807 |
delete, Delete: |
| 808 |
------ ------ |
| 809 |
In C++11, a deleted function must be defined in the header. |
| 810 |
Not applicable in C# and Java. |
| 811 |
|
| 812 |
C++ generator: |
| 813 |
** In C++, there is no keyword for function hiding (as `delete` in C++11). |
| 814 |
** So the common way to delete a function (like copy constructor) is to make |
| 815 |
** the function private and not define it in source. |
| 816 |
class operations { |
| 817 |
private : |
| 818 |
test5 (); |
| 819 |
} |
| 820 |
|
| 821 |
|
| 822 |
C++11 generator: |
| 823 |
class operations { |
| 824 |
public : |
| 825 |
test5 () = delete; |
| 826 |
} |
| 827 |
|
| 828 |
|
| 829 |
C# generator: |
| 830 |
** Not applicable in C#. |
| 831 |
class operations { |
| 832 |
public test5 () { |
| 833 |
} |
| 834 |
} |
| 835 |
|
| 836 |
|
| 837 |
Java generator: |
| 838 |
** Not applicable in Java. |
| 839 |
class operations { |
| 840 |
public test5 () { |
| 841 |
} |
| 842 |
} |
| 843 |
|
| 844 |
|
| 845 |
GetSet: |
| 846 |
------ |
| 847 |
This feature will generate the same output as GetSet for class except it will |
| 848 |
respect the visibility of the operation. You also need to define the attribute. |
| 849 |
|
| 850 |
|
| 851 |
dllexport, DllExport: |
| 852 |
--------- --------- |
| 853 |
Force some signature to be stored in a Microsoft Library Manager (lib). |
| 854 |
|
| 855 |
|
| 856 |
C++ and C++11 generator: |
| 857 |
class operations { |
| 858 |
DllExport test (); |
| 859 |
} |
| 860 |
// Don't forget to add a #define: |
| 861 |
// #define DllExport __declspec (dllexport) |
| 862 |
|
| 863 |
|
| 864 |
C# generator: |
| 865 |
Java generator: |
| 866 |
PHP gerenator: |
| 867 |
not supported |
| 868 |
|
| 869 |
|
| 870 |
- Attributes: |
| 871 |
|
| 872 |
Some stereotypes are supported that all begin with "CORBA". These are: |
| 873 |
CORBAConstant, CORBAEnum, CORBAException, CORBANative, CORBATypedef, |
| 874 |
CORBAStruct, CORBAUnion, CORBAValue. |
| 875 |
When generating IDL, the corresponding IDL syntax is generated for the UML |
| 876 |
class. When generating other languages, a rough mapping from the IDL to the |
| 877 |
other language is generated. |
| 878 |
|
| 879 |
The following conventions are followed by the code generation for CORBA |
| 880 |
stereotypes: |
| 881 |
|
| 882 |
Constant First attribute's type contains the const type; first attribute's |
| 883 |
value contains the const's value. Everything else unused. |
| 884 |
Enum Attribute names contain the enum literals, everything else unused. |
| 885 |
Exception TODO. |
| 886 |
Native TODO. |
| 887 |
Typedef First attribute's type contains the original type; |
| 888 |
first attribute's value optionally contains the dimensions |
| 889 |
in case of an array. Everything else unused. |
| 890 |
Struct Attribute names and types contain the struct members. |
| 891 |
Everything else unused. |
| 892 |
Union First attribute's type contains the switch type. Only |
| 893 |
enum types are supported as the switch type. |
| 894 |
Following attributes contain the union cases as follows: |
| 895 |
Attribute value contains the switch value for the case |
| 896 |
(only exactly one value possible per case); attribute |
| 897 |
name and type contains the union member name and type |
| 898 |
for that case. |
| 899 |
Everything else unused. |
| 900 |
Value Use much like a normal class. Staticness not supported. |
| 901 |
|
| 902 |
|
| 903 |
- Dependency: |
| 904 |
|
| 905 |
NoLoop, noloop |
| 906 |
------ ------ |
| 907 |
In C/C++, circular dependencies are really messy with include and only the user |
| 908 |
can handle it. Adding a "NoLoop" stereotype will disable the "#include" for the |
| 909 |
connection. |
| 910 |
|
| 911 |
|
| 912 |
MISCELLANEOUS |
| 913 |
|
| 914 |
Visibility |
| 915 |
|
| 916 |
Dia2Code does not handle the "implementation" visibility for methods. |
| 917 |
So when you have a class that implements a method that was declared |
| 918 |
abstract in a base class, you have to give it the same visibility of the |
| 919 |
parent class' method. The visibility of the method is not printed if it is |
| 920 |
"implementation"; this may be a source of bugs. |
| 921 |
|
| 922 |
|
| 923 |
Method's return type |
| 924 |
|
| 925 |
If you leave the "type" entry in the method declaration empty, then no |
| 926 |
type will be declared for it. This is useful with constructors, when the |
| 927 |
return type is implicit (both in C++ and Java). If the return type is |
| 928 |
void, you should explicitly declare it in the UML diagram. |
| 929 |
|
| 930 |
|
| 931 |
Packages |
| 932 |
|
| 933 |
The UML standard states that there are two ways of representing packages: |
| 934 |
a large box with all the elements inside (Large Package in Dia) or a small box |
| 935 |
(Small Package in Dia) to which the package's elements connect with a symbol |
| 936 |
that Dia does not include: a line with a crossed out circle in the end of the |
| 937 |
container. You can put a normal line with a "Coordiate origin" arrow at one |
| 938 |
end, of course, and will be aesthetically correct, but of no use to Dia2Code. |
| 939 |
|
| 940 |
Dia2code, currently, checks only for intersections of packages (Large or |
| 941 |
Small) with other objects like classes and other packages, so it will |
| 942 |
be mostly useful with diagrams that use Large Packages instead of Small |
| 943 |
ones. |
| 944 |
|
| 945 |
|
| 946 |
INFORMATION FOR DEVELOPERS |
| 947 |
|
| 948 |
How it works: |
| 949 |
|
| 950 |
1. Parse the diagram file with xmlParseFile(). |
| 951 |
2. Parse the tree generated in 1 for UML classes to build an |
| 952 |
umlclasslist (type defined here). |
| 953 |
3. Parse the tree again for UML Generalizations, Realizations, |
| 954 |
Implements, Dependencies, Associations and packages to add information |
| 955 |
to the class list. |
| 956 |
4. Generate the structure of the classes (write it into files) |
| 957 |
from the class list. |
| 958 |
|
| 959 |
Steps 1-3 are done in parse_diagram (). |
| 960 |
Step 4 is done in GenerateCode* (). |
| 961 |
Both functions are called from main (). |
| 962 |
|
| 963 |
|
| 964 |
Code Generators: |
| 965 |
|
| 966 |
**IMPORTANT**: When a modification is done in a generator, BE SURE to do the |
| 967 |
same with all generators if necessary. |
| 968 |
|
| 969 |
A code generator (class derived from GenerateCode) is a class that takes |
| 970 |
reference to a DiaGram class. |
| 971 |
|
| 972 |
The DiaGram class contains: |
| 973 |
- std::list <umlClassNode> uml; // a list of all class nodes. |
| 974 |
|
| 975 |
The GenerateCode class contains: |
| 976 |
- DiaGram & dia; // a reference to a DiaGram class. |
| 977 |
- std::string license; // file that contains the license. |
| 978 |
- std::string outdir; // folder where to write the headers. |
| 979 |
// empty for current folder. |
| 980 |
- std::string file_ext; // extension of header. |
| 981 |
- std::string body_file_ext; // extension of body file (if usefull). |
| 982 |
|
| 983 |
- uint8_t indent : 4; // number of space of each indent. |
| 984 |
uint32_t getIndent () const; |
| 985 |
void setIndent (uint8_t spaces); |
| 986 |
|
| 987 |
- bool overwrite : 1; // allow overwriting existing file. |
| 988 |
bool getOverwrite () const; |
| 989 |
void setOverwrite (bool over); |
| 990 |
|
| 991 |
- bool buildtree : 1; // create one folder for each package. |
| 992 |
bool getBuildTree () const; |
| 993 |
void setBuildTree (bool build); |
| 994 |
|
| 995 |
- bool bOpenBraceOnNewline : 1; // open brace on new line. |
| 996 |
bool getOpenBraceOnNewline () const; |
| 997 |
void setOpenBraceOnNewline (bool newline); |
| 998 |
|
| 999 |
- bool oneClassOneHeader : 1; // Only one class par header. |
| 1000 |
bool getOneClass () const; |
| 1001 |
void setOneClass (bool val); |
| 1002 |
|
| 1003 |
|
| 1004 |
New generator: |
| 1005 |
|
| 1006 |
The new generator is a class that inherits from GenerateCode. All virtual |
| 1007 |
functions must be overridden. Developers can get an idea on how to write a |
| 1008 |
new generator by having a good look inside GenerateCodeCpp.cpp. |
| 1009 |
|
| 1010 |
- writeLicense (); |
| 1011 |
Write the license at the top of each header. The characters that start and end |
| 1012 |
multiple line comments must be added before and after the file. |
| 1013 |
The license is specified by the attribute license. |
| 1014 |
|
| 1015 |
- writeStartHeader (std::string & name); |
| 1016 |
Write the mechanism that avoids multiple inclusion (applies to C/C++). |
| 1017 |
- writeEndHeader (); |
| 1018 |
Finish the mechanism that avoids multiple inclusion. |
| 1019 |
|
| 1020 |
- writeInclude (std::basic_string <char> name); |
| 1021 |
- writeInclude (const char * name); |
| 1022 |
Write the instruction that includes a file (header). |
| 1023 |
|
| 1024 |
- writeFunctionComment (const umlOperation & ope); |
| 1025 |
Write the comment for a function and its parameters. Use well-known format. |
| 1026 |
C++ uses doxygen format. |
| 1027 |
|
| 1028 |
- writeFunction (const umlOperation & ope, int * curr_visibility); |
| 1029 |
Write the header of a function. The current visibility is used to avoid writing |
| 1030 |
it every time. |
| 1031 |
|
| 1032 |
- writeComment (const std::string & text); |
| 1033 |
- writeComment (const char * text); |
| 1034 |
Write a single comment, not in the well-known format. |
| 1035 |
|
| 1036 |
- writeClassComment (const umlClassNode & node); |
| 1037 |
Write the comment for a class by using the well-known format. |
| 1038 |
|
| 1039 |
- writeClass (const umlClassNode & node); |
| 1040 |
Write the beginning of a class (name, inheritance and visibility). |
| 1041 |
- writeClassEnd (); |
| 1042 |
End the class. |
| 1043 |
|
| 1044 |
- writeAttribute (const umlAttribute & attr, int * curr_visibility); |
| 1045 |
Write an attribute inside of a class. |
| 1046 |
|
| 1047 |
- writeNameSpaceStart (const umlClassNode * name); |
| 1048 |
Start a package. |
| 1049 |
- writeNameSpaceEnd (const umlClassNode * node); |
| 1050 |
End a package. |
| 1051 |
|
| 1052 |
- writeConst (const umlClassNode & node); |
| 1053 |
Write a class which is a const type (stereotype "const", "constant" or |
| 1054 |
"CORBAConstant"). |
| 1055 |
|
| 1056 |
- writeEnum (const umlClassNode & node); |
| 1057 |
Write a class which is an enum type (stereotype "enum", "enumeration" or |
| 1058 |
"CORBAEnum"). |
| 1059 |
|
| 1060 |
- writeStruct (const umlClassNode & node); |
| 1061 |
Write a class which is an structure type (stereotype "struct", "structure" or |
| 1062 |
"CORBAStruct"). |
| 1063 |
|
| 1064 |
- writeTypedef (const umlClassNode & node); |
| 1065 |
Write a class which is a typedef type (stereotype "typedef" or "CORBATypedef"). |
| 1066 |
|
| 1067 |
- writeAssociation (const umlassoc & asso); |
| 1068 |
Write an association. |
| 1069 |
|
| 1070 |
- writeTemplates ( |
| 1071 |
const std::list <std::pair <std::string, std::string> > & tmps); |
| 1072 |
Write a template. |
| 1073 |
|
| 1074 |
Add a new generator to the main program: |
| 1075 |
The following files need to be updated: |
| 1076 |
- src/main.cpp: |
| 1077 |
- add a new include at the top of the file with the header of the new |
| 1078 |
generator, |
| 1079 |
- inside the variable const char *help, add the abreviation of the |
| 1080 |
language, |
| 1081 |
- inside the variable const char *bighelp, change -ext, -bext and -t |
| 1082 |
options, |
| 1083 |
- and finally add it inside the main loop, in "case 1". |
| 1084 |
- src/Makefile.am: |
| 1085 |
- add the source in dia2code_SOURCES, |
| 1086 |
- add the header in EXTRA_DIST. |
| 1087 |
- builds/vs-community-2013/dia2code.vcxproj |
| 1088 |
- add the new source and header files. |
| 1089 |
- README: |
| 1090 |
- add examples for classic usecases and for the different stereotypes. |
| 1091 |
- tests/tests.sh: |
| 1092 |
- add your new generator to generators. |
| 1093 |
And of course, don't forget to run "git add GenerateCodeXXX.?pp". |
| 1094 |
|
| 1095 |
|
| 1096 |
KNOWN BUGS |
| 1097 |
|
| 1098 |
- Packages of classes are searched using the position and size instead of |
| 1099 |
<dia:childnode parent="O0"/> |
| 1100 |
|
| 1101 |
|
| 1102 |
AUTHOR, MAINTAINER and THANKS |
| 1103 |
|
| 1104 |
Javier O'Hara <[email protected]> |